fix: Windows hook detection and line ending handling#209
Closed
micah-loftin-mediware wants to merge 5 commits intortk-ai:masterfrom
Closed
fix: Windows hook detection and line ending handling#209micah-loftin-mediware wants to merge 5 commits intortk-ai:masterfrom
micah-loftin-mediware wants to merge 5 commits intortk-ai:masterfrom
Conversation
Previously, RTK used compile-time OS checks (#[cfg(unix)]) to determine whether to allow hook installation. This blocked hook installation on Windows even when Claude Code runs in a bash environment (Git Bash/WSL). Changes: - Add is_bash_environment() runtime check (executes bash --version) - Remove #[cfg(unix)] guards from run_default_mode() and run_hook_only_mode() - Update ensure_hook_installed() to handle permissions cross-platform - Update show_config() to display hook status on Windows - Update test_default_mode_creates_hook_and_rtk_md() for cross-platform Benefits: - Claude Code on Windows can now use hook-based mode - Automatic fallback to --claude-md mode if bash not found - Better error messages guiding Windows users to install Git Bash/WSL Testing: - All 393 tests pass - Cross-platform test now works on both Unix and Windows - Zero clippy warnings introduced Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Windows Git auto-converts LF to CRLF by default, breaking bash shebangs. Previously, installed hooks had CRLF line endings, causing hook errors. Changes: - Add .gitattributes to enforce LF for .sh, .rs, .md, .toml, .json files - Add normalize_line_endings() to strip \r\n -> \n before writing hooks - Convert hooks/rtk-rewrite.sh to LF line endings (10465 -> 10256 bytes) - Add tests: test_hook_has_lf_line_endings, test_normalize_line_endings Before: $ head -1 ~/.claude/hooks/rtk-rewrite.sh | od -c # ! / b i n / b a s h \r \n (CRLF - broken) After: $ head -1 ~/.claude/hooks/rtk-rewrite.sh | od -c # ! / b i n / b a s h \n (LF - works) Testing: - All 28 init tests pass (including 3 new tests) - Verified hook installs with LF on Windows - File size correct: 10256 bytes (not 10465 with CRLF) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add comprehensive debug logging to rtk-rewrite.sh hook controlled by RTK_HOOK_DEBUG environment variable. When set to "1", logs hook invocation details, environment variables, tool locations, and command transformations to ~/.claude/hooks/rtk-rewrite.log. Features: - Conditional logging only when RTK_HOOK_DEBUG=1 (silent by default) - PATH augmentation to include ~/.local/bin and ~/.cargo/bin - Silent guards for missing dependencies (rtk, jq) - Error trapping and logging for troubleshooting - Logs hook context: PWD, BASH_VERSION, SHELL, HOME, USER - Logs tool detection: rtk and jq locations - Logs input JSON and extracted command Also updated CLAUDE.md with RTK usage instructions covering all supported commands and token savings metrics. Verified: RTK metrics tracking works correctly (63.4% savings on git status) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add debug output to show when commands don't match any rewrite patterns and log the rewritten command when a match is found. Debug output (when RTK_HOOK_DEBUG=1): - "No rewrite pattern matched, exiting" when command passes through - "REWRITTEN: <cmd>" showing the transformed command This helps troubleshoot hook behavior and verify command rewrites are working correctly (e.g., gh pr view -> rtk gh pr view). Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Changes
Testing
Related Issues
Fixes hook errors on Windows when using Git Bash/MSYS environments
🤖 Generated with Claude Code