feat(windows): add Python hook for Claude Code on Windows#905
Open
acastango wants to merge 1 commit intortk-ai:developfrom
Open
feat(windows): add Python hook for Claude Code on Windows#905acastango wants to merge 1 commit intortk-ai:developfrom
acastango wants to merge 1 commit intortk-ai:developfrom
Conversation
rtk-rewrite.py is a drop-in alternative to rtk-rewrite.sh that requires only Python 3 and rtk >= 0.23.0 — no jq, no bash dependency. It implements the same PreToolUse hook protocol (exit codes, updatedInput JSON, graceful degradation) and works via Claude Code's Git Bash environment on Windows. Closes rtk-ai#330, closes rtk-ai#502 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
hooks/claude/rtk-rewrite.py— a drop-in alternative tortk-rewrite.shfor Windowshooks/claude/test-rtk-rewrite.py— 61-test Python suite mirroring the bash test suitehooks/claude/README.mdto document both hooks and manual Windows install stepsWhy Python instead of bash + jq
rtk init -gon Windows currently falls back to--claude-mdmode because the bash hook requiresjq, which is not reliably available on Windows. Claude Code does supportPreToolUsehooks on Windows via Git Bash — the only missing piece was a hook that doesn't depend onjq.Python 3 is commonly installed on Windows developer machines and has no third-party dependencies for this use case. The hook is a thin delegate:
json.load(stdin)→subprocess.run(["rtk", "rewrite", cmd])→print(json.dumps(output)). Same exit-code protocol, sameupdatedInputJSON format, same graceful degradation on all error paths.Test results
Tested on Windows 10 Pro with Python 3.11 and rtk 0.34.1.
Note: the Python test suite reflects current
rtk rewritebehavior (v0.34.1). A few expectations differ fromtest-rtk-rewrite.shwhere the bash suite has stale cases (e.g.npm test,vue-tsc,find,vitestno-args). Those divergences are in the Rust registry, not the hook — flagging here in case a separate fix is wanted for the bash suite.Closes
Closes #330
Closes #502
Test plan
hooks/claude/rtk-rewrite.pyto~/.claude/hooks/on a Windows machinePreToolUsehook entry to~/.claude/settings.jsonper the READMEgit status— confirm it executes asrtk git statuspython hooks/claude/test-rtk-rewrite.py— all 61 tests should pass🤖 Generated with Claude Code