feat: add Windows hook support for rtk init --global#452
feat: add Windows hook support for rtk init --global#452daixudk96-max wants to merge 1 commit intortk-ai:masterfrom
Conversation
Remove Unix-only `#[cfg(unix)]` guards from init.rs and add cross-platform hook selection. On Windows, installs a Node.js-based hook (rtk-rewrite.js) instead of the Bash script (rtk-rewrite.sh). Changes: - Add hooks/rtk-rewrite.js: Node.js PreToolUse hook using execFileSync - Modify src/init.rs: platform-aware hook_filename(), hook_content(), build_hook_command(), and is_rtk_hook_command() helpers - Remove Windows fallback to --claude-md mode - Add Windows-specific tests for hook insertion and detection
|
Hi! Thanks for the contribution! Since March 6, all PRs should target the Could you update the base branch? Click Edit at the top right of this PR and change it from Thanks! |
|
CI User seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
|
Thanks for the contribution! This feature has already been integrated in the latest version (v0.33.1). Please verify with the latest release that everything works as expected on your side. Closing as already included — thanks! |
|
Hey We are cleaning up the codebase and improving the project structure for better onboarding. As part of this effort, PR #826 reorganizes No logic changes — only file moves and import path updates. What you need to doRebase your branch on git fetch origin && git rebase origin/developGit detects renames automatically. If you get import conflicts, update the paths: use crate::git; // now: use crate::cmds::git::git;
use crate::tracking; // now: use crate::core::tracking;
use crate::config; // now: use crate::core::config;
use crate::init; // now: use crate::hooks::init;
use crate::gain; // now: use crate::analytics::gain;Need help rebasing? Tag @aeppling |
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
Summary
#[cfg(unix)]guards fromsrc/init.rs, enabling hook-based mode on Windowshooks/rtk-rewrite.js: a Node.js PreToolUse hook that callsrtk rewriteviaexecFileSync, with fail-open behavior (silently passes through on error)hook_filename(),hook_content(),build_hook_command()select.shon Unix and.json Windowsnode "C:\Users\...\.claude\hooks\rtk-rewrite.js"(object-style{"type":"command","command":"..."})test_windows_hook_uses_rtk_rewrite,test_insert_hook_entry_windows_command,test_hook_already_present_windows_commandMotivation
Currently
rtk init --globalfalls back to--claude-mdmode on Windows, which injects ~137 lines into CLAUDE.md and relies on the LLM to "remember" to prefix commands withrtk. This is unreliable and wastes tokens. With this PR, Windows users get the same transparent hook-based interception that Unix users enjoy.Test plan
cargo test init::testspasses (all existing + new Windows tests)cargo checkclean (no new warnings from this PR)rtk init --global --auto-patchinstallsrtk-rewrite.jsto~/.claude/hooks/and patchessettings.jsonrtk-rewrite.sh)Known issue
On Windows with default stack size,
cargo runmay hitSTATUS_STACK_OVERFLOWdue to large embedded string constants. Adding.cargo/config.tomlwithrustflags = ["-C", "link-arg=/STACK:8388608"]resolves this. Not included in this PR as it may be environment-specific.