Skip to content

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

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

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.

@klauspost
Copy link
Copy Markdown

Just give me some way to disable this when I don't want a hook.

aeppling added a commit that referenced this pull request Apr 19, 2026
Removing old guards, windows can now just use the binary hook engine from 0.37

Related issues:
- Fixes #502 : rtk init --global falls back to --claude-md on Windows
- Fixes #1353 : Feature request: hook-based mode on Windows
- Partially addresses #330 : Add hooks support for Windows
- Partially addresses #913 :  Persistent "No hook installed" warning on Windows
- Partially addresses #1373 : Suppress "No hook installed" warning on Windows
- Partially addresses #682 : Config to suppress hook warning
- Related to #1248 : Windows PowerShell compatibility gaps

Supersedes community PRs:
- #1123 fix(init): enable hook installation on Windows
- #1027 fix(init): enable hook-based mode on Windows
- #809 feat: enable hook-based mode on Windows
- #452 feat: add Windows hook support for rtk init --global
- #551 feat: native cross-platform hook for Windows support
- #150 feat(hook): native cross-platform hook-rewrite command
- #1063 Feat/windows hooks
@aeppling
Copy link
Copy Markdown
Contributor

Hey, solved on latest releases 0.37.x

Thanks for contributing and trying to address this issue.

Closing this for clean up

@aeppling aeppling closed this Apr 24, 2026
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.

4 participants