Replies: 1 comment
|
thanks that worked here |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
RTK Hook Setup on Windows — Complete Guide
The Problem
rtk init -ginstalls aPreToolUsehook for Claude Code by writing a bashscript (
rtk-rewrite.sh) and patching~/.claude/settings.json. However, thehook installation explicitly blocks on Windows:
This means Windows users always see:
even though the rest of RTK works fine. Only
CLAUDE.mdgets updated — nohook, no
settings.jsonentry, noRTK.md. RTK then relies entirely on theLLM reading the instructions and choosing to follow them (~70-80% reliability
vs ~100% with a hook).
Root Cause
Three Unix-specific dependencies block hook installation on Windows
(
src/hooks/init.rsis gated behind#[cfg(unix)]):rtk-rewrite.shis a bash script. No native bash on Windows.jq— the hook usesjqto parse/build JSON. Not available by default on Windows.chmod 755usesstd::os::unix::fs::PermissionsExt,a Rust trait that doesn't compile on Windows at all.
Three Working Approaches
Pick the one that matches your setup:
Option A — Git Bash (Simplest)
Prerequisites: Git for Windows installed (provides
bashandjq-lessalternative). Discovered by @cobrabr.
Claude Code on Windows uses Git Bash internally to run hook commands, so a
.shfile works directly — no WSL needed.Step 1 — Create the hook directory and script
Download the official hook script from the RTK repo and save it to
~/.claude/hooks/rtk-rewrite.sh:Step 2 — Install
jq(required by the hook)The hook script uses
jqto parse JSON. Install it viaChocolatey:
choco install jq -yOr download the binary from jqlang.github.io/jq
and place it anywhere in your
PATH.Step 3 — Patch
settings.jsonAdd the hook entry to
~/.claude/settings.json. Use forward slashes in thepath — Git Bash strips backslashes silently:
{ "hooks": { "PreToolUse": [ { "matcher": "Bash", "hooks": [ { "type": "command", "command": "bash '/c/Users/<YOUR_USERNAME>/.claude/hooks/rtk-rewrite.sh'", "timeout": 5 } ] } ] } }Step 4 — Create
RTK.mdmanuallyThen add
@RTK.mdto~/.claude/CLAUDE.md(create the file if it doesn't exist).Step 5 — Test
Expected:
{"hookSpecificOutput":{"hookEventName":"PreToolUse","updatedInput":{"command":"rtk git status"}}}Option B — PowerShell (No Extra Tools)
Prerequisites: PowerShell 7+ (built into Windows). No Git Bash, no WSL, no
jq. Discovered by @skymat.PowerShell's
ConvertFrom-Json/ConvertTo-Jsonreplacesjq, and thescript runs natively without any additional dependencies.
Step 1 — Create the hook script
Create
~/.claude/hooks/rtk-rewrite.ps1:Step 2 — Patch
settings.jsonAdd
-ExecutionPolicy Bypassto avoid script execution policy errors(@sguryev):
{ "hooks": { "PreToolUse": [ { "matcher": "Bash", "hooks": [ { "type": "command", "command": "powershell -NoProfile -ExecutionPolicy Bypass -File C:\\Users\\<YOUR_USERNAME>\\.claude\\hooks\\rtk-rewrite.ps1", "timeout": 5 } ] } ] } }Step 3 — Test
Expected:
{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"allow","updatedInput":{"command":"rtk git status"}}}Known gotchas (PowerShell)
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8-ExecutionPolicy Bypass"async": truecloses stdin pipe"async"field)Set-Content -Encoding UTF8adds BOM[System.IO.File]::WriteAllText()withUTF8Encoding($false)Option C — WSL (Full Native Compatibility)
Prerequisites: WSL2 installed with Ubuntu. This is the only approach that
makes
rtk init --showreport all[ok]with no warnings, because RTK runsits own installer via WSL and generates the integrity hash for the real
rtk-rewrite.shbash script.The key challenge: Windows
$PATHbreaks WSL bashWhen WSL inherits the Windows environment, paths like
C:\Program Files (x86)\...become/mnt/c/Program Files (x86)/.... Theparentheses are valid bash syntax —
(x86)is interpreted as a subshellexpression — causing:
The fix is
env -i: start WSL with a completely empty environment, thenexplicitly set only what bash needs.
Step 1 — Install RTK inside WSL
Step 2 — Install
jqinside WSLStep 3 — Run
rtk init -gtargeting the Windows home directoryWSL mounts
C:at/mnt/c. OverrideHOMEso RTK installs into the Windows~/.claude/directory instead of the WSL home:This creates:
~/.claude/hooks/rtk-rewrite.sh— the real bash hook script~/.claude/hooks/.rtk-hook.sha256— integrity hash (what silences the warning)~/.claude/RTK.md— slim RTK awareness file~/.claude/CLAUDE.mdwith@RTK.mdreferenceStep 4 — Patch
settings.jsonwithenv -i{ "hooks": { "PreToolUse": [ { "matcher": "Bash", "hooks": [ { "type": "command", "command": "wsl env -i PATH=/home/<WSL_USER>/.local/bin:/usr/bin:/bin HOME=/home/<WSL_USER> bash /mnt/c/Users/<YOUR_USERNAME>/.claude/hooks/rtk-rewrite.sh", "timeout": 5 } ] } ] } }Step 5 — Verify
rtk init --showExpected (all green, no warning):
Step 6 — Test end-to-end
Expected:
{ "hookSpecificOutput": { "hookEventName": "PreToolUse", "updatedInput": { "command": "rtk git status" } } }Common Gotchas (All Approaches)
Project hooks override global hooks
Claude Code does not merge hooks. If a project has its own
PreToolUsein.claude/settings.json, it completely replaces the global one — RTKsilently disappears for that project.
Fix: duplicate the RTK hook entry in each project-level
settings.jsonthat declares its own hooks.
permissions.allowfor rewritten commandsIf
defaultModeis notbypassPermissions, add a rule to avoid a permissionprompt on every rewritten command:
Updating RTK in the Future
Option A (Git Bash)
Re-download the hook script (Step 1) to get the latest version.
Option B (PowerShell)
No update needed — the PowerShell script calls
rtk rewriteat runtime, so itpicks up new rewrite rules automatically with each RTK binary update.
Option C (WSL)
What Native Support Could Look Like
For
rtk init -gto work natively on Windows,src/hooks/init.rswould needa
#[cfg(windows)]path that auto-detects the available runtime and picks thebest approach:
A
--wslflag onrtk init -gcould also make the WSL approach explicit andopt-in for users who prefer it.
Success
All reactions