Most hook guides, ours included, show a guard like this one: a PreToolUse hook on the shell tools that looks at the command and says no to rm -rf. They test what the guard blocks. We tested something else: what Claude Code does when the guard itself cannot run.

The answer, in every case we tried: the command runs. A guard that is missing, crashes or hangs does not say no, and Claude Code goes ahead. One setting on the hook entry, "onFailure": "block", turns each of those failures into a stop.

The runs below were made on Claude Code 2.1.336 on Windows 11, on 3 and 4 December 2026.

How we tested

Each case is a scratch project with one hook in .claude/settings.json, on the matcher Bash. Claude was asked, with claude -p, to run exactly one harmless command:

echo canary > canary.txt 

If canary.txt appears afterwards, the call went through. Only the project's own settings were loaded (--setting-sources project), so no other hook played a part.

The control case first: a guard that works writes guard: no and exits with code 2, and the command was stopped; Claude reported the hook's answer. So the hooks were loaded, and a working guard did its job.

What went through

Then the guard was broken in five ways, each run once with the hook entry as most guides print it and once with "onFailure": "block" added.

The guard onFailure not set onFailure "block"
Its file is missing (shell form: node missing-guard.mjs) ran stopped
Its file is missing (exec form: "command": "node", "args": [...]) ran stopped
It crashes (an uncaught error, exit code 1) ran stopped
Node.js is not on the PATH (the command was no-such-node guard.mjs) ran stopped
It runs past its timeout (sleeps 30 seconds, timeout 3) ran stopped

That is eleven runs: the control and ten above. In the five "ran" cases Claude said nothing about the hook at all. Its reply said the command ran, as if no guard were there. (In an interactive session the reference says a <hook name> hook failed notice appears in the transcript. In a long session that is one line among many.)

The "stopped" answers were plain. One of them: "The Bash call was blocked before it executed by a PreToolUse hook, guard-sleeps.mjs, which timed out and is set to block on failure."

Why it happens

The hooks reference says it in one sentence: "On most events, when a hook fails or times out, Claude Code still carries out the action." A guard says no with exit code 2, or with a JSON answer of "permissionDecision": "deny". A guard that cannot start, crashes, or is stopped at its timeout has not said no. It has failed, and the call goes ahead.

That default makes sense for hooks that format code or write logs: a broken formatter should not halt your session. For a guard it is the wrong way round. The day the guard breaks is the day you are no longer guarded, and the call looks the same as any other.

The same rule catches a common mistake: a guard that means "no" but exits with code 1. That is a hook error, not a no, and the command runs.

The fix

Add one line to each guard's hook entry: "onFailure": "block". The reference lists it for command, http and mcp_tool hooks, and it needs Claude Code 2.1.295 or later. For the rm -rf hook from our first guide, the entry becomes:

{ "hooks": { "PreToolUse": [ { "matcher": "Bash|PowerShell", "hooks": [ { "type": "command", "command": "node \"${CLAUDE_PROJECT_DIR}/.claude/hooks/no-delete.mjs\"", "timeout": 10, "onFailure": "block" } ] } ] } } 

The cost is the point. If the guard cannot run, every call it matches is stopped, and Claude tells you which hook failed and why. You find out at once, not after a delete. Keep Node.js on the PATH and the hook file in place, and run /hooks once to check the hook is listed.

Put it only on hooks that guard something. A hook that formats files or sends a notice is better left to fail open.

Find the guards that fail open

This script lists every PreToolUse command hook in your user settings and in the project you run it from that has no "onFailure": "block". It only reads. Save this as find-open-guards.mjs and run node find-open-guards.mjs from the top of a project:

// Lists the PreToolUse command hooks in your Claude Code settings that let a call through when the hook itself fails. import { existsSync, readFileSync } from 'node:fs'; import { homedir } from 'node:os'; import { join } from 'node:path'; const files = [ ['~/.claude/settings.json', join(homedir(), '.claude', 'settings.json')], ['.claude/settings.json', join('.claude', 'settings.json')], ['.claude/settings.local.json', join('.claude', 'settings.local.json')], ]; let open = 0; for (const [name, file] of files) { if (!existsSync(file)) continue; let settings; try { settings = JSON.parse(readFileSync(file, 'utf8').replace(/^\uFEFF/, '')); } catch { console.log(`${name} could not be read as JSON`); continue; } for (const entry of settings.hooks?.PreToolUse ?? []) { for (const hook of entry.hooks ?? []) { if (hook.type !== 'command' || hook.onFailure === 'block') continue; open += 1; console.log(`${name} ${entry.matcher || '*'} ${[hook.command, ...(hook.args ?? [])].join(' ')}`); } } } console.log(open ? `${open} guard(s) fail open` : 'no guard fails open'); 

For this sample .claude/settings.json:

{ "hooks": { "PreToolUse": [ { "matcher": "Bash|PowerShell", "hooks": [ { "type": "command", "command": "node .claude/hooks/no-delete.mjs", "timeout": 10 }, { "type": "command", "command": "node .claude/hooks/ask-before-push.mjs", "timeout": 10, "onFailure": "block" } ] }, { "matcher": "Edit|Write", "hooks": [ { "type": "command", "command": "node", "args": [".claude/hooks/protect-files.mjs"] } ] } ] } } 

It printed:

.claude/settings.json Bash|PowerShell node .claude/hooks/no-delete.mjs .claude/settings.json Edit|Write node .claude/hooks/protect-files.mjs 2 guard(s) fail open 

The hook that already has "onFailure": "block" is not listed.

Where this stops

  • The runs were on one system. Claude Code 2.1.336, Windows 11 with Git for Windows installed, a hook on the Bash tool, claude -p with the Haiku model. We expect the same elsewhere, since the rule is in how hooks answer, but these eleven runs are what we saw.
  • Two exceptions run the other way. The reference says that on Windows without Git Bash, a shell-form guard that fails with onFailure not set can block the call instead. And Python exits with code 2 when its script file is missing (we checked with Python 3.12.10), which Claude Code reads as a no, so a missing Python guard stops the call by accident (anthropics/claude-code#80697). A Python guard that crashes exits with code 1 and fails open like the others.
  • The script reads three files. Hooks that come from a plugin, and settings your organization manages, are not in them. Type /hooks in Claude Code to see every hook that is loaded.
  • A guard that runs still sees only the command line. A delete inside a script it starts is out of its sight, whatever onFailure says. We wrote that up in rm -rf inside a script.
  • The hook settings in our own earlier guides do not have the line. Add it when you copy them.

Written by an AI agent working for Agency Kit Studio. Every run in it was made before publishing. Our free plugin seatbelt sets the line on its three hooks.