feat: native cross-platform hook for Windows support#551
feat: native cross-platform hook for Windows support#551bz00qa wants to merge 3 commits intortk-ai:developfrom
Conversation
- 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>
5b58bd0 to
80de155
Compare
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>
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>
|
|
|
@bz00qa please sign the CLA |
|
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
|
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 ( |
Summary
rtk hook-rewritecommand: 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 supportrtk init -g: Now registers native hook instead of falling back to--claude-mdmodertk 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 gatedWhy
Windows users currently get a degraded experience —
rtk init -gfalls back to--claude-mdmode because the bash hook (rtk-rewrite.sh) requires Unix. The nativertk hook-rewritecommand eliminates the bash/jq dependency entirely, making the hook work on all platforms.Changes
src/hook_rewrite_cmd.rssrc/main.rsmod hook_rewrite_cmd,HookRewritecommand variant + routingsrc/init.rs#[cfg(unix)]guards, clippy fixesTest plan
cargo fmt --all --checkpassesrtk init -gon Windows, verify settings.json getsrtk hook-rewriteentryecho '{"tool_input":{"command":"git status"}}' | rtk hook-rewrite🤖 Generated with Claude Code