Summary
When Claude Code hooks execute (PreToolUse, PostToolUse, Stop, etc.), they run in a non-interactive shell with no .bashrc, no .zshrc, and no user PATH. The only PATH available to hooks is the one explicitly set in the env block of ~/.claude/settings.json.
This means tools like rg, fd, bun, and rtk — all of which PAI hooks invoke — are invisible to hooks even when correctly installed on the system, unless their directories appear in settings.json env.PATH.
Current State
This is not documented anywhere in PAI. HookSystem.md, CLAUDE.md, and CliFirstArchitecture.md don't mention the stripped environment. The failure mode is completely silent: hooks that depend on missing-PATH tools either skip (if they have guards) or fail with opaque errors, with no signal to the user.
Discovery
Found on a Hetzner VPS (Ubuntu 24.04) when the ContextReduction hook was silently skipping every Bash call because rtk and rg weren't on the hook PATH — despite being correctly installed on the system. The hook guard (if ! command -v rtk &>/dev/null; then exit 0; fi) masked the degradation entirely. The issue only surfaced during a full PAI tool audit triggered by an unrelated fd: command not found error in a dropped session recovery.
Proposed Fix
- Add a "Hook Execution Environment" section to
HookSystem.md explicitly stating that hooks run in a stripped shell with no inherited PATH, and that settings.json env.PATH must be set explicitly.
- Add a post-install checklist item to
CliFirstArchitecture.md or a new SETUP.md: verify settings.json has an explicit PATH covering ~/.local/bin, ~/.bun/bin, and any tool directories PAI depends on.
Example Correct Configuration
{
"env": {
"PATH": "/home/{user}/.local/bin:/home/{user}/.bun/bin:/usr/local/bin:/usr/bin:/bin"
}
}
Note: the PATH value must be a literal string — shell variable expansion (e.g. ${HOME}) does not apply in this context.
Summary
When Claude Code hooks execute (PreToolUse, PostToolUse, Stop, etc.), they run in a non-interactive shell with no
.bashrc, no.zshrc, and no user PATH. The only PATH available to hooks is the one explicitly set in theenvblock of~/.claude/settings.json.This means tools like
rg,fd,bun, andrtk— all of which PAI hooks invoke — are invisible to hooks even when correctly installed on the system, unless their directories appear insettings.jsonenv.PATH.Current State
This is not documented anywhere in PAI.
HookSystem.md,CLAUDE.md, andCliFirstArchitecture.mddon't mention the stripped environment. The failure mode is completely silent: hooks that depend on missing-PATH tools either skip (if they have guards) or fail with opaque errors, with no signal to the user.Discovery
Found on a Hetzner VPS (Ubuntu 24.04) when the ContextReduction hook was silently skipping every Bash call because
rtkandrgweren't on the hook PATH — despite being correctly installed on the system. The hook guard (if ! command -v rtk &>/dev/null; then exit 0; fi) masked the degradation entirely. The issue only surfaced during a full PAI tool audit triggered by an unrelatedfd: command not founderror in a dropped session recovery.Proposed Fix
HookSystem.mdexplicitly stating that hooks run in a stripped shell with no inherited PATH, and thatsettings.jsonenv.PATHmust be set explicitly.CliFirstArchitecture.mdor a newSETUP.md: verifysettings.jsonhas an explicit PATH covering~/.local/bin,~/.bun/bin, and any tool directories PAI depends on.Example Correct Configuration
{ "env": { "PATH": "/home/{user}/.local/bin:/home/{user}/.bun/bin:/usr/local/bin:/usr/bin:/bin" } }Note: the PATH value must be a literal string — shell variable expansion (e.g.
${HOME}) does not apply in this context.