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
Copy Markdown

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
@pszymkowiak
Copy link
Copy Markdown
Collaborator

Hi! Thanks for the contribution! Since March 6, all PRs should target the develop branch instead of master (see CONTRIBUTING.md).

Could you update the base branch? Click Edit at the top right of this PR and change it from master to develop.

Thanks!

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


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.

@pszymkowiak
Copy link
Copy Markdown
Collaborator

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!

@pszymkowiak pszymkowiak added duplicate This issue or pull request already exists resolved-pending-close Answered/resolved — will close if no response labels Mar 26, 2026
@aeppling
Copy link
Copy Markdown
Contributor

Hey

We are cleaning up the codebase and improving the project structure for better onboarding. As part of this effort, PR #826 reorganizes src/ from a flat layout into subfolders.

No logic changes — only file moves and import path updates.

What you need to do

Rebase your branch on develop when receiving this comment:

git fetch origin && git rebase origin/develop

Git 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

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate This issue or pull request already exists resolved-pending-close Answered/resolved — will close if no response

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants