Skip to content

fix(init): enable hook-based mode on Windows#1027

Open
daywhirls wants to merge 1 commit intortk-ai:developfrom
daywhirls:fix/windows-hook-support
Open

fix(init): enable hook-based mode on Windows#1027
daywhirls wants to merge 1 commit intortk-ai:developfrom
daywhirls:fix/windows-hook-support

Conversation

@daywhirls
Copy link
Copy Markdown

Summary

rtk init -g on Windows falls back to --claude-md mode with a warning ("Hook-based mode requires Unix"), and rtk rewrite emits a persistent "Hook outdated" warning — even when a working bash hook exists. This is because the entire ensure_hook_installed, run_default_mode, and run_hook_only_mode functions are gated behind #[cfg(unix)], but the only Unix-specific operation is chmod +x.

This PR removes the platform gates and makes hook installation cross-platform:

  • ensure_hook_installed: Remove #[cfg(unix)] from the function; wrap only the chmod call in #[cfg(unix)]
  • run_default_mode / run_hook_only_mode: Delete the #[cfg(not(unix))] fallback stubs; remove #[cfg(unix)] from the real implementations
  • patch_settings_json: On Windows, prefix the hook command with bash so the .sh script 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 failures
  • New test: test_ensure_hook_installed_cross_platform — verifies hook creation, content, and idempotency on all platforms
  • New test: test_hook_already_present_bash_wrapped — verifies bash "..." wrapped commands are detected by hook_already_present
  • End-to-end: built release binary on Windows 11, ran rtk init -g, confirmed hook installed and rtk rewrite no longer warns

Context

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

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
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 4, 2026

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants