feat: add Windows hook support for rtk init --global#452
Open
daixudk96-max wants to merge 1 commit intortk-ai:masterfrom
Open
feat: add Windows hook support for rtk init --global#452daixudk96-max wants to merge 1 commit intortk-ai:masterfrom
daixudk96-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
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
#[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.