fix(init): enable hook-based mode on Windows#1027
Open
daywhirls wants to merge 1 commit intortk-ai:developfrom
Open
fix(init): enable hook-based mode on Windows#1027daywhirls wants to merge 1 commit intortk-ai:developfrom
daywhirls wants to merge 1 commit intortk-ai:developfrom
Conversation
Remove #[cfg(unix)] gates that blocked hook installation on Windows. The only Unix-specific operation is chmod +x, which is unnecessary on Windows where bash scripts execute without the execute bit. Changes: - Make ensure_hook_installed cross-platform (wrap only chmod in cfg(unix)) - Prefix hook command with `bash` on Windows in patch_settings_json - Delete #[cfg(not(unix))] fallback stubs for run_default_mode and run_hook_only_mode - Add cross-platform tests for hook installation and bash-wrapped command detection Fixes rtk-ai#913
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
rtk init -gon Windows falls back to--claude-mdmode with a warning ("Hook-based mode requires Unix"), andrtk rewriteemits a persistent "Hook outdated" warning — even when a working bash hook exists. This is because the entireensure_hook_installed,run_default_mode, andrun_hook_only_modefunctions are gated behind#[cfg(unix)], but the only Unix-specific operation ischmod +x.This PR removes the platform gates and makes hook installation cross-platform:
ensure_hook_installed: Remove#[cfg(unix)]from the function; wrap only thechmodcall in#[cfg(unix)]run_default_mode/run_hook_only_mode: Delete the#[cfg(not(unix))]fallback stubs; remove#[cfg(unix)]from the real implementationspatch_settings_json: On Windows, prefix the hook command withbashso the.shscript executes via Git Bash/MSYS2 (e.g.bash "C:\Users\...\.claude\hooks\rtk-rewrite.sh")Testing
cargo fmt --all --check && cargo clippy --all-targets && cargo test— all 1355 tests pass, 0 failurestest_ensure_hook_installed_cross_platform— verifies hook creation, content, and idempotency on all platformstest_hook_already_present_bash_wrapped— verifiesbash "..."wrapped commands are detected byhook_already_presentrtk init -g, confirmed hook installed andrtk rewriteno longer warnsContext
There are several open PRs for Windows hook support (#150, #452, #551, #726, #727, #809, #905, #954). This PR takes the minimal approach — 1 file, +56/-36 lines — rather than introducing alternative hook implementations (Python, Node.js, native). The bash hook works on Windows via Git Bash, which is near-universal on Windows dev machines with git installed.
Fixes #913