rtk-ai / rtk-ai/rtk

Hook silently fails when rtk not in Claude Code's restricted PATH (Homebrew installs)

Open
#685 4 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area:cli bug effort-small good first issue platform:macos priority:high
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

  1. User installs RTK via cargo install rtk → binary at ~/.cargo/bin/rtk
  2. Hook works (cargo bin may be in PATH, or user never notices)
  3. User switches to brew install rtk → binary moves to /opt/homebrew/bin/rtk
  4. Hook silently fails — command -v rtk returns nothing in Claude Code's hook environment
  5. rtk gain --history stops 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.