Skip to content

feat: add Windows hook support for rtk init --global#452

Open
daixudk96-max wants to merge 1 commit intortk-ai:masterfrom
daixudk96-max:feat/windows-hook-support
Open

feat: add Windows hook support for rtk init --global#452
daixudk96-max wants to merge 1 commit intortk-ai:masterfrom
daixudk96-max:feat/windows-hook-support

Conversation

@daixudk96-max
Copy link

Summary

  • Removes Unix-only #[cfg(unix)] guards from src/init.rs, enabling hook-based mode on Windows
  • Adds hooks/rtk-rewrite.js: a Node.js PreToolUse hook that calls rtk rewrite via execFileSync, with fail-open behavior (silently passes through on error)
  • Platform-aware helpers: hook_filename(), hook_content(), build_hook_command() select .sh on Unix and .js on Windows
  • Windows hook command format: node "C:\Users\...\.claude\hooks\rtk-rewrite.js" (object-style {"type":"command","command":"..."})
  • Adds 3 Windows-specific tests: test_windows_hook_uses_rtk_rewrite, test_insert_hook_entry_windows_command, test_hook_already_present_windows_command

Motivation

Currently rtk init --global falls back to --claude-md mode on Windows, which injects ~137 lines into CLAUDE.md and relies on the LLM to "remember" to prefix commands with rtk. 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::tests passes (all existing + new Windows tests)
  • cargo check clean (no new warnings from this PR)
  • On Windows: rtk init --global --auto-patch installs rtk-rewrite.js to ~/.claude/hooks/ and patches settings.json
  • On Unix: behavior unchanged (still uses rtk-rewrite.sh)

Known issue

On Windows with default stack size, cargo run may hit STATUS_STACK_OVERFLOW due to large embedded string constants. Adding .cargo/config.toml with rustflags = ["-C", "link-arg=/STACK:8388608"] resolves this. Not included in this PR as it may be environment-specific.

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
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.

1 participant