Skip to content

feat(windows): add Python hook for Claude Code on Windows#905

Open
acastango wants to merge 1 commit intortk-ai:developfrom
acastango:feat-windows-python-hook-for-claude-code
Open

feat(windows): add Python hook for Claude Code on Windows#905
acastango wants to merge 1 commit intortk-ai:developfrom
acastango:feat-windows-python-hook-for-claude-code

Conversation

@acastango
Copy link
Copy Markdown

@acastango acastango commented Mar 29, 2026

Summary

  • Adds hooks/claude/rtk-rewrite.py — a drop-in alternative to rtk-rewrite.sh for Windows
  • Adds hooks/claude/test-rtk-rewrite.py — 61-test Python suite mirroring the bash test suite
  • Updates hooks/claude/README.md to document both hooks and manual Windows install steps

Why Python instead of bash + jq

rtk init -g on Windows currently falls back to --claude-md mode because the bash hook requires jq, which is not reliably available on Windows. Claude Code does support PreToolUse hooks on Windows via Git Bash — the only missing piece was a hook that doesn't depend on jq.

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, same updatedInput JSON format, same graceful degradation on all error paths.

Test results

ALL 61 TESTS PASSED

Tested on Windows 10 Pro with Python 3.11 and rtk 0.34.1.

Note: the Python test suite reflects current rtk rewrite behavior (v0.34.1). A few expectations differ from test-rtk-rewrite.sh where the bash suite has stale cases (e.g. npm test, vue-tsc, find, vitest no-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

  • Copy hooks/claude/rtk-rewrite.py to ~/.claude/hooks/ on a Windows machine
  • Add the PreToolUse hook entry to ~/.claude/settings.json per the README
  • Restart Claude Code and run git status — confirm it executes as rtk git status
  • Run python hooks/claude/test-rtk-rewrite.py — all 61 tests should pass

🤖 Generated with Claude Code

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

CLAassistant commented Mar 29, 2026

CLA assistant check
All committers have signed the CLA.

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.

2 participants