claude-code - 💡(How to fix) Fix [BUG] CLI hooks run with restricted PATH that excludes /opt/homebrew/bin - Homebrew-installed binaries fail silently [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#46954Fetched 2026-04-12 13:28:46
View on GitHub
Comments
0
Participants
1
Timeline
5
Reactions
0
Author
Participants
Timeline (top)
labeled ×4renamed ×1

Hooks invoked by Claude Code run in an environment whose PATH does not include /opt/homebrew/bin. Hook scripts that rely on Homebrew installed binaries (the default install location on Apple Silicon macOS) silently fail because command -v <tool> returns nothing, even though the binary is on the user's interactive shell PATH.

Root Cause

Hooks invoked by Claude Code run in an environment whose PATH does not include /opt/homebrew/bin. Hook scripts that rely on Homebrew installed binaries (the default install location on Apple Silicon macOS) silently fail because command -v <tool> returns nothing, even though the binary is on the user's interactive shell PATH.

RAW_BUFFERClick to expand / collapse

Summary

Hooks invoked by Claude Code run in an environment whose PATH does not include /opt/homebrew/bin. Hook scripts that rely on Homebrew installed binaries (the default install location on Apple Silicon macOS) silently fail because command -v <tool> returns nothing, even though the binary is on the user's interactive shell PATH.

Reproduction

A third party project (rtk) documented this with a minimal reproduction at https://github.com/rtk-ai/rtk/issues/685:

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

The pattern command -v <tool> &>/dev/null || exit 0 is a common hook idiom for graceful degradation. When PATH excludes /opt/homebrew/bin, every Homebrew installed tool triggers the early exit, and the hook appears to run successfully (exit 0) while actually doing nothing.

Expected behavior

Hooks should inherit a PATH that includes the user's interactive shell PATH, or at minimum the default Homebrew prefixes (/opt/homebrew/bin on Apple Silicon, /usr/local/bin on Intel).

Actual behavior

/opt/homebrew/bin is stripped from PATH in the hook runtime environment. Hook authors must either hardcode absolute paths (/opt/homebrew/bin/tool) or re export PATH inside the hook script, neither of which is documented as necessary.

Why existing issues do not cover this

  • #43210 is about the Desktop app ignoring settings.json env and shell profile PATH. Different scope (Desktop, not CLI hooks).
  • #42248 is about the Read tool on Desktop app failing to find poppler/pdftoppm. Different tool and scope.
  • #31799 describes shell snapshot PATH containing literal \$PATH. Different mechanism.
  • #43127 is about installer placement. Not hook runtime PATH.
  • #43800 (closed) is about Desktop app shell snapshot behavior. Different scope.

Request

  1. Document the hook runtime PATH explicitly.
  2. Either include common binary prefixes (/opt/homebrew/bin, /usr/local/bin) by default, or provide a settings.json option to inherit the interactive shell PATH for hooks.

Suggested labels: bug, area:hooks, platform:macos

extent analysis

TL;DR

Modify hook scripts to either use absolute paths for Homebrew installed binaries or re-export the PATH inside the hook script to include /opt/homebrew/bin.

Guidance

  • Identify hook scripts that rely on Homebrew installed binaries and update them to use absolute paths (e.g., /opt/homebrew/bin/rtk) to avoid silent failures.
  • Alternatively, modify hook scripts to re-export the PATH environment variable to include /opt/homebrew/bin before checking for tool availability.
  • Verify the fix by checking the hook script's behavior and ensuring that it no longer exits silently when a Homebrew installed tool is not found.
  • Consider requesting a settings.json option to inherit the interactive shell PATH for hooks to simplify the solution and make it more robust.

Example

# Before
if ! command -v rtk &>/dev/null; then exit 0; fi

# After (using absolute path)
if ! /opt/homebrew/bin/rtk --version &>/dev/null; then exit 0; fi

# After (re-exporting PATH)
export PATH=$PATH:/opt/homebrew/bin
if ! command -v rtk &>/dev/null; then exit 0; fi

Notes

The provided solution is a workaround, and a more permanent fix would involve modifying the hook runtime environment to include the user's interactive shell PATH or providing a settings.json option to achieve this.

Recommendation

Apply workaround: Modify hook scripts to use absolute paths or re-export the PATH environment variable to include /opt/homebrew/bin, as this provides a immediate solution to the problem, although it may not be the most elegant or permanent fix.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

Hooks should inherit a PATH that includes the user's interactive shell PATH, or at minimum the default Homebrew prefixes (/opt/homebrew/bin on Apple Silicon, /usr/local/bin on Intel).

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix [BUG] CLI hooks run with restricted PATH that excludes /opt/homebrew/bin - Homebrew-installed binaries fail silently [1 participants]