fix(init): enable hook installation on Windows - #1123
Conversation
Remove #[cfg(not(unix))] bail/fallback from run_default_mode and run_hook_only_mode. Guard the chmod(0o755) call inside ensure_hook_installed with an inline #[cfg(unix)] block instead of gating the entire function. This matches the existing cross-platform pattern already used by install_cursor_hooks (line 1622) and the Gemini hook installer (line 2152) in this same file. Verified on Windows 11 + Claude Code CLI + git-bash: - rtk init --show: [ok] Hook + [ok] settings.json - PreToolUse hook fires for git/ls/grep commands - rtk gain counter: 1137 → 1234 (+97 auto-rewritten commands) - Subagent sessions inherit the hook - No "No hook installed" warning Closes rtk-ai#682, rtk-ai#913 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Relationship to #1090Heads-up that @ayoub-khemissi already has #1090 open addressing the same Windows gap via a different approach: a new The two PRs look orthogonal, not competing:
Non-conflicting at the code level#1090 adds new functions ( This PR does the opposite: removes the Why both can coexistWith both merged, Windows users get a tiered experience:
With only #1090 merged, every Windows user needs to remember the Deferring to the maintainers. Closing this PR in favor of #1090 is also fine — the AccelixGames team has already verified the bash hook path works end-to-end on Windows 11 via hand-install (evidence in the PR description), so users can work around until either approach lands. |
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
|
Hey, solved on latest releases 0.37.x Thanks for contributing and trying to address this issue. Closing this for clean up |
Removing old guards, windows can now just use the binary hook engine from 0.37 Related issues: - Fixes rtk-ai#502 : rtk init --global falls back to --claude-md on Windows - Fixes rtk-ai#1353 : Feature request: hook-based mode on Windows - Partially addresses rtk-ai#330 : Add hooks support for Windows - Partially addresses rtk-ai#913 : Persistent "No hook installed" warning on Windows - Partially addresses rtk-ai#1373 : Suppress "No hook installed" warning on Windows - Partially addresses rtk-ai#682 : Config to suppress hook warning - Related to rtk-ai#1248 : Windows PowerShell compatibility gaps Supersedes community PRs: - rtk-ai#1123 fix(init): enable hook installation on Windows - rtk-ai#1027 fix(init): enable hook-based mode on Windows - rtk-ai#809 feat: enable hook-based mode on Windows - rtk-ai#452 feat: add Windows hook support for rtk init --global - rtk-ai#551 feat: native cross-platform hook for Windows support - #150 feat(hook): native cross-platform hook-rewrite command - rtk-ai#1063 Feat/windows hooks
Removing old guards, windows can now just use the binary hook engine from 0.37 Related issues: - Fixes rtk-ai#502 : rtk init --global falls back to --claude-md on Windows - Fixes rtk-ai#1353 : Feature request: hook-based mode on Windows - Partially addresses rtk-ai#330 : Add hooks support for Windows - Partially addresses rtk-ai#913 : Persistent "No hook installed" warning on Windows - Partially addresses rtk-ai#1373 : Suppress "No hook installed" warning on Windows - Partially addresses rtk-ai#682 : Config to suppress hook warning - Related to rtk-ai#1248 : Windows PowerShell compatibility gaps Supersedes community PRs: - rtk-ai#1123 fix(init): enable hook installation on Windows - rtk-ai#1027 fix(init): enable hook-based mode on Windows - rtk-ai#809 feat: enable hook-based mode on Windows - rtk-ai#452 feat: add Windows hook support for rtk init --global - rtk-ai#551 feat: native cross-platform hook for Windows support - #150 feat(hook): native cross-platform hook-rewrite command - rtk-ai#1063 Feat/windows hooks
Summary
Enable
rtk init -ghook installation on Windows by removing the#[cfg(not(unix))]blockers insrc/hooks/init.rs, applying the same inlinechmodguard pattern already used by the Cursor and Gemini installers in this file.Net diff: +25 / −33 lines, one file touched.
Problem
On Windows,
rtk init -gcurrently bails with:Related user reports: #682 (persistent "No hook installed" warning, stuck on Windows), #913.
The block is compile-time:
run_default_mode,run_hook_only_mode, andensure_hook_installedare each gated with#[cfg(unix)], and the#[cfg(not(unix))]variants either warn-and-fallback orbail!().Root cause
Only one line actually needs Unix:
PermissionsExtisstd::os::unix::fs::PermissionsExt. Everything else compiles and runs fine on Windows.The hook script itself (
rtk-rewrite.sh) is purebash + jq, which Claude Code already executes via git-bash on Windows — no execute bit is required to invoke a script asbash /path/to/script.sh.Fix
Mirror the pattern already used by
install_cursor_hooks(line 1622) and the Gemini hook installer (line 2152) in this same file: one unified function body, with only thechmodcall wrapped in an inline#[cfg(unix)]block.The
#[cfg(not(unix))]warn/bail fallback variants ofrun_default_modeandrun_hook_only_modeare deleted, and the#[cfg(unix)]attribute is removed from the remaining unified bodies. Doc comments are extended to explain the cross-platform rationale for future maintainers.Verification
Verified manually on Windows 11 + Claude Code CLI + git-bash by hand-installing the equivalent hook setup (hook script at
~/.claude/hooks/rtk-rewrite.sh+PreToolUseentry in~/.claude/settings.json) before writing this PR:rtk init --show[ok] Hook: ... (exists)+[ok] settings.json: RTK hook configuredgit status(nortkprefix)rtk git status; compressed output (* master...origin/master,~ Modified:,? Untracked:)ls -la(nortkprefix)rtk ls,-lacolumns stripped as expectedgit log --oneline -3pwd && git branch&&-segment rewritten individuallyecho "test"rtk git statusas inputrtk gaincounter[rtk] /!\ No hook installedwarningrtk gain,rtk ls,rtk init --showAgenttool)PostToolUsehookIndependently verified on multiple Windows 11 machines (team members, rtk v0.35.0 + Claude Code CLI, hand-installed the same hook setup). All reported successful installation, hook fire, and no
No hook installedwarning.Scope
src/hooks/init.rs(one file)#[cfg(unix)]blocks are test-only and out of scopertk init --showClaude hook status display code (line 1839+) — currently uses#[cfg(unix)]forexecutable/is_thin_delegatorchecks. Left for a follow-up PR to keep this change minimal; the existing behavior already produces a usable[ok] Hook: existson Windows.Related
rtk init -gfor automatic token savings" #682Draft status
Marked draft pending CI confirmation (Windows/Linux/macOS build matrix). Will flip to ready-for-review once CI is green.