Hook silently fails when rtk not in Claude Code's restricted PATH (Homebrew installs)
#685 opened on 2026年3月18日
説明
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