If the line under the tool call reads PreToolUse:Bash hook error: followed by the reason your script printed, and the command didn’t run, the hook did its job. PreToolUse:Bash hook failed means the guard broke and the command already ran.
Claude Code runs the command unless your hook hands back a clear “no” in a form it reads, such as exit 2 or a JSON deny decision; a guard that breaks lets the command through. /hooks showed something wrong only for the file, event-name and JSON mistakes; the rest looked exactly like a working guard.

Data (CSV)CC BY 4.0
When a guard isn’t firing or isn’t blocking, start from the screen you already looked at:
hook failedunder the tool call: the shell error below it names the fix.no hooks yetin/hooks: the settings file, the event name or the JSON.- Listed in
/hooks, no message anywhere: log the script’s first line. - Only
claude -poutput: run the hook by hand.
On this page
- “PreToolUse:Bash hook failed”: fix the path, the execute bit or the exit code
- “no hooks yet” in /hooks: the file, the event name or the JSON
- Listed in /hooks, no message: log the first line
- Under claude -p, hooks run but every warning disappears
- A guard holds only once you’ve watched it block a fake .env
“PreToolUse:Bash hook failed”: fix the path, the execute bit or the exit code
hook failed is Claude Code reporting that it got no answer from your hook and went ahead without one:

The shell error printed under it names which one:
not found: the path is wrong. Write it as"$CLAUDE_PROJECT_DIR"/.claude/hooks/guard.sh. A relative./.claude/hooks/guard.shcan break once Claude hascd‘d into another folder.Permission denied: the script isn’t executable. Runchmod +xon it.- Your own block message: the script ran and exited 1. Only
exit 2blocks a PreToolUse call; Claude Code reports exit 1 and carries on.
“no hooks yet” in /hooks: the file, the event name or the JSON
/hooks lists what Claude Code actually loaded, so no hooks yet under PreToolUse means your file was never read or was thrown away whole. In the second case one trailing comma switches off every hook in that file, not just the one you were editing.
Claude Code reads hooks from three settings files:
.claude/settings.json.claude/settings.local.json~/.claude/settings.json
An event typo or broken JSON shows in an interactive session only, in a dialog that opens before your first prompt; a hook in the wrong file shows nothing. Pick Continue and it’s gone; quit and start claude again in that folder to see it once more:
| Mistake | At startup | Fix |
|---|---|---|
Hook in .claude/hooks.json or a settings.json at the repo root |
No warning; it loads nowhere | Move it into one of the three files |
Event typo like PreToolUSE |
Settings Warning |
Spell the event PreToolUse |
| Broken JSON | Settings Error: “Files with errors are skipped entirely” |
Fix the JSON |
Broken JSON includes a handler placed straight under the event. The event holds matcher groups, and each group holds its own hooks list:
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{ "type": "command", "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/guard.sh" }
]
}
]
}
}
You don’t need to restart after fixing it: in my test session, the next cat .env after the edit was already blocked.
Listed in /hooks, no message: log the first line
A hook in /hooks is registered, and that’s all it proves. Two steps come after registration and leave no trace when they fail: whether the matcher catches this tool’s name, and whether the script’s answer is a “no” Claude Code reads.
One log line, right under the shebang, tells them apart. Here it is in a minimal guard, built like the one I tested every case with (it needs jq):
#!/bin/bash echo "$(date +%T) fired" >> /tmp/guard-hook.log cmd=$(jq -r '.tool_input.command // ""') if [[ "$cmd" == *.env* ]]; then echo "blocked: .env read not allowed" >&2 exit 2 fi exit 0
Keep the >&2. With exit 2, Claude Code takes the block reason from stderr; a message echoed to stdout still blocks, but Claude has nothing to quote.
Ask Claude for one command the matcher should catch, then run cat /tmp/guard-hook.log.
No log line: the matcher doesn’t match the tool name
A matcher made of plain names has to match the tool name exactly, case included, so "bash" never fires for the Bash tool. That was my first .env guard: cat .env went straight through, yet the script exited 2 with the right message when I piped a sample in by hand.
/hooks lists it as bash · command, just like a working guard, so I kept debugging the script; only the log file that never appeared pointed me at the matcher.
Write it "Bash"; for several tools, separate the names with | or a comma, as in "Bash|Read". Any other character, such as *, turns the matcher into a regular expression.
Log written, command ran: the answer wasn’t a “no” Claude Code reads
The hook ran, so the fault is in what it said back:
- No shebang. The script runs under
/bin/sh, which on my machine stopped at[[withnot foundand fell through to exit 0. Put#!/bin/bashabove the log line. - A guard on PostToolUse. It runs after the tool, when the output has already reached the model. Move it to PreToolUse.
- Slower than its
timeout. The tool call showsrunning PreToolUse hookwith a seconds counter, then the command runs with no message once time is up. Make the script faster, or raisetimeout, in seconds, on the same handler ascommand. - A deny at the top level.
permissionDecisiononly counts insidehookSpecificOutput; at the top level it’s ignored without an error. This form, with exit 0, blocks:
{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"no .env"}}
Under claude -p, hooks run but every warning disappears
Hooks do run under claude -p, and a working guard blocks there too. What -p drops is the messages: no Settings Warning, no Settings Error, no hook failed. So a silent CI run can hide any row of the grid, a wrong path included.
For CI, add --output-format stream-json --verbose. A hook that couldn’t start or ran out of time then leaves a system event tagged hook_no_verdict, and a step can fail the job when grep -q hook_no_verdict finds it. exit 1 and the other rows leave no event.
To see which mistake you have, run the command from your settings file by hand, from the repo root:
export CLAUDE_PROJECT_DIR="$PWD"
echo '{"tool_name":"Bash","tool_input":{"command":"cat .env"}}' | "$CLAUDE_PROJECT_DIR"/.claude/hooks/guard.sh; echo "exit $?"
A shell error or exit 1 sends you to the hook failed fixes. exit 2 with your message, from a script that starts with #!/bin/bash, means the script is fine and the settings file is at fault: open the folder interactively once and check /hooks.
A guard holds only once you’ve watched it block a fake .env
Whichever row you came from, neither /hooks nor a setting tells you the fix worked; only seeing the guard stop a command does.
Why “onFailure”: “block” doesn’t prove it
"onFailure": "block", set on the handler next to command, turns a failed hook into a refusal. It can only act when Claude Code knows something failed:

When my own guard broke with exit 1 under the option, every command stopped, a plain git status included, with No stderr output under the block message and no hint of why. The lowercase matcher I’d actually tripped on gets past the option anyway, so I left it out.
The fake .env test
- Put a
.envholding a fake value such asFAKE_KEY=test-not-realin the repo and ask Claude to runcat .env. - Check that Claude quotes your block message and stops instead of finding another way to read the file. If the key prints, go back to the grid with what you saw this time.
- Ask for one ordinary command with no
.envin it, such asgit status, and check that it runs.
Sources
- Research note on loopnotes-lab: every broken-hook case, three runs each, with the screens, the figure data and the dataset, Claude Code 2.1.328 on Linux, measured November 19, 2026
- Hooks reference, Claude Code Docs, checked 2026-11-19: exit codes, hooks that can’t start or time out don’t block,
timeoutin seconds (default 600),onFailure(v2.1.295+), matcher groups and matcher lists - Automate actions with hooks, Claude Code Docs, checked 2026-11-19: settings file locations, case-sensitive matchers,
permissionDecisionplacement, PostToolUse limits, file watcher - Claude Code CHANGELOG, Anthropic, checked 2026-11-19: version measured