Skip to content

[BUG] CLI hooks run with restricted PATH that excludes /opt/homebrew/bin - Homebrew-installed binaries fail silently #46954

@mjmirza

Description

@mjmirza

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 rtk-ai/rtk#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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:hooksbugSomething isn't workinghas reproHas detailed reproduction stepsplatform:macosIssue specifically occurs on macOS

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions