Skip to content

feat: native cross-platform hook for Windows support#551

Closed
bz00qa wants to merge 3 commits intortk-ai:developfrom
bz00qa:feat/windows-native-hook
Closed

feat: native cross-platform hook for Windows support#551
bz00qa wants to merge 3 commits intortk-ai:developfrom
bz00qa:feat/windows-native-hook

Conversation

@bz00qa
Copy link
Copy Markdown

@bz00qa bz00qa commented Mar 12, 2026

Summary

  • rtk hook-rewrite command: Native Claude Code PreToolUse hook that reads JSON from stdin, rewrites commands via the registry, and outputs hook response JSON — replaces the bash+jq dependency for cross-platform support
  • Windows rtk init -g: Now registers native hook instead of falling back to --claude-md mode
  • Windows rtk init -g --hook-only: Uses native hook instead of bailing with an error
  • #[cfg(unix)] guards: Bash-only code paths (REWRITE_HOOK, prepare_hook_paths) properly gated
  • Clippy fixes: Unnecessary borrows, dead code annotations in init.rs

Why

Windows users currently get a degraded experience — rtk init -g falls back to --claude-md mode because the bash hook (rtk-rewrite.sh) requires Unix. The native rtk hook-rewrite command eliminates the bash/jq dependency entirely, making the hook work on all platforms.

Changes

File Description
src/hook_rewrite_cmd.rs New native hook: parse stdin JSON, rewrite via registry, output hook response
src/main.rs Add mod hook_rewrite_cmd, HookRewrite command variant + routing
src/init.rs Windows default/hook-only modes use native hook, #[cfg(unix)] guards, clippy fixes

Test plan

  • All 891 tests pass (1 pre-existing binlog CRLF failure)
  • 4 new tests: hook JSON structure, field preservation, unsupported commands, already-rtk passthrough
  • cargo fmt --all --check passes
  • Manual: rtk init -g on Windows, verify settings.json gets rtk hook-rewrite entry
  • Manual: pipe hook JSON to echo '{"tool_input":{"command":"git status"}}' | rtk hook-rewrite

🤖 Generated with Claude Code

bz00qa and others added 2 commits March 13, 2026 17:34
- Add `rtk hook-rewrite` command: native Claude Code PreToolUse hook
  that reads JSON from stdin, rewrites commands via registry, and
  outputs hook response JSON (replaces bash+jq dependency)
- Update Windows `rtk init -g` to register native hook instead of
  falling back to --claude-md mode
- Update Windows `rtk init -g --hook-only` to use native hook
- Add `#[cfg(unix)]` guards for bash-only code paths
- Fix clippy warnings in init.rs (unnecessary borrows, dead code)
- Add 4 tests for hook JSON structure, field preservation, routing

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: bz00qa <bz00qa.hub@gmail.com>
hook_installed_path() only checked for ~/.claude/hooks/rtk-rewrite.sh,
causing false "No hook installed" warnings on Windows where the native
PreToolUse hook is configured in settings.json. Now also checks
settings.json for "rtk hook-rewrite" command entries.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: bz00qa <bz00qa.hub@gmail.com>
@bz00qa bz00qa force-pushed the feat/windows-native-hook branch from 5b58bd0 to 80de155 Compare March 13, 2026 16:34
@bz00qa bz00qa changed the base branch from master to develop March 13, 2026 16:34
Revert 3 unrelated clippy fixes in init.rs to keep PR focused on
Windows native hook support. Add CHANGELOG and README documentation.

Signed-off-by: bZ00qa <167500396+bz00qa@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
bz00qa added a commit to bz00qa/rtk_fork that referenced this pull request Mar 13, 2026
Apply clippy suggestions carved out from feature PRs rtk-ai#551 and rtk-ai#552:
- container.rs: .last() → .next_back() (2 instances)
- git.rs: .map_or(false, ...) → .is_some_and(...) (2 instances)
- git.rs: .last() → .next_back() (1 instance)
- init.rs: unnecessary format!() → .to_string() (1 instance)
- init.rs: unnecessary & on &str parameters (2 instances)

Signed-off-by: bZ00qa <167500396+bz00qa@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@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.
You have signed the CLA already but the status is still pending? Let us recheck it.

@MarlonPassos-git
Copy link
Copy Markdown

@bz00qa please sign the CLA

@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
@aeppling
Copy link
Copy Markdown
Contributor

Thanks for contributing @bz00qa — the early native cross-platform hook approach helped shape the direction.

This is now superseded by the v0.37.x releases: master ships a full native binary hook system (rtk hook claude) with proper JSON-based detection. Closing as resolved.

@aeppling aeppling closed this Apr 24, 2026
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.

5 participants