Hook silently fails when rtk not in Claude Code's restricted PATH (Homebrew installs)
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 81.1k
- Forks
- 5.1k
- Avg merge
- 4d 21h
- Merged PRs (30d)
- 35
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the rtk init -g implementation and the generated rtk-rewrite.sh hook. Reproduce the failure using the clean-environment command from the issue, then trace how the installed binary is resolved. Done means a Homebrew-installed binary is found under Claude Code's restricted PATH, with the hook still behaving correctly when rtk is unavailable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, shell
- Domain
- cli, developer-experience
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100