Hook silently fails when rtk not in Claude Code's restricted PATH (Homebrew installs)
Problem
When RTK is installed via Homebrew, the rtk-rewrite.sh hook silently stops working because Claude Code runs hooks with a restricted PATH that does not include /opt/homebrew/bin.
The hook does:
if ! command -v rtk &>/dev/null; then
exit 0 # silent failure — no rewrite happens, no warning
fi
This means all Bash commands pass through unmodified with zero indication anything is wrong. rtk gain still works fine from the terminal (because the user's shell has Homebrew in PATH), so the breakage is invisible.
How it breaks
- User installs RTK via
cargo install rtk→ binary at~/.cargo/bin/rtk - Hook works (cargo bin may be in PATH, or user never notices)
- User switches to
brew install rtk→ binary moves to/opt/homebrew/bin/rtk - Hook silently fails —
command -v rtkreturns nothing in Claude Code's hook environment rtk gain --historystops updating, but user assumes hook is fine
Verification
You can reproduce by running the hook with a clean environment:
env -i HOME="$HOME" echo '{"tool_input":{"command":"git status"}}' | env -i HOME="$HOME" bash ~/.claude/hooks/rtk-rewrite.sh
# Output: (nothing) — exits 0 silently, no rewrite
Root cause
rtk init -g installs a hook that uses rtk by name and relies on it being in PATH. But Claude Code's hook subprocess does not inherit the user's full shell PATH (no Homebrew, no cargo, etc. on macOS).
Suggested fixes
Option A (best): rtk init -g should inject the absolute path to the current binary into the hook at install time:
# Generated by rtk init -g
RTK_BIN="/opt/homebrew/bin/rtk" # resolved at install time
Option B: The hook should probe known install locations as fallback:
export PATH="/opt/homebrew/bin:/usr/local/bin:$HOME/.cargo/bin:$PATH"
Option C: Emit a visible warning (not just exit 0) when rtk is not found — at minimum >&2 echo "[rtk] WARNING: rtk not found in PATH, hook disabled" so users know something is wrong.
Note: Option C has already been partially addressed (warnings added to the hook), but the silent failure on Homebrew installs is the main UX problem.
Environment
- macOS (Apple Silicon) — Homebrew installs to
/opt/homebrew/bin - RTK installed via
brew install rtk - Claude Code hook PATH does not include
/opt/homebrew/bin
Workaround
In ~/.claude/settings.json, change the hook command from:
/Users/<you>/.claude/hooks/rtk-rewrite.sh
to:
PATH="/opt/homebrew/bin:/usr/local/bin:$PATH" bash /Users/<you>/.claude/hooks/rtk-rewrite.sh
Additional issue: updatedInput silently dropped when other PreToolUse hooks are present
After fixing the PATH issue (by prepending /opt/homebrew/bin to the hook command), I ran into a second silent failure.
Problem
Even with the PATH fix applied and the hook correctly producing updatedInput JSON, Claude Code was still executing the original unrewritten command. The hook ran (verified via debug log), produced the correct JSON output, but the rewrite was never applied.
Root cause
Claude Code bug: When multiple PreToolUse hooks match the same tool, updatedInput is not aggregated — the last hook's output wins, even if it's empty.
In my case, claude-code-wakatime was registered with matcher: "*" in PreToolUse, so it fired after the RTK hook and its empty output wiped the updatedInput rewrite. This is tracked as Claude Code issue #15897.
This means RTK's hook silently does nothing on any Claude Code setup that has any other matcher: "*" PreToolUse hook installed — a very common configuration.
Fix
Remove or reorder any matcher: "*" PreToolUse hooks so RTK fires last, or (more reliably) ensure no other PreToolUse hook fires for Bash tool calls after RTK.
In ~/.claude/settings.json, the RTK hook entry must be the last PreToolUse entry, and no other hook with matcher: "*" or matcher: "Bash" should follow it.
Suggested improvements for RTK
- Document this limitation in the hook installation docs — users with plugins like
claude-code-wakatimewill silently lose rewrites rtk verifycould detect other PreToolUse hooks insettings.jsonand warn if anymatcher: "*"hooks follow the RTK hookrtk init -gcould automatically place the RTK hook last in the PreToolUse array
Environment
- Claude Code 2.1.78
- RTK 0.30.0
- macOS (Apple Silicon)
wshm · Automated triage by AI
🔍 Automated Triage
| 🐛 Category | bug |
| 🟠 Priority | high |
| 🎯 Confidence | 91% |
Summary
Hook silently no-ops for Homebrew RTK installs because Claude Code's restricted PATH excludes /opt/homebrew/bin; fix by injecting absolute binary path at rtk init -g time
This looks like a simple fix that could be auto-resolved. Repo maintainers can use
/wshm fixto attempt it.
📁 Relevant files
hooks/rtk-rewrite.shsrc/init.rs
Triaged automatically by wshm · This is an automated analysis, not a human review.
anyone got it working on claude code?
anyone got it working on claude code?
I got it working by using the workaround described in the PR description message.