Claude Code hooks fail open unless you say so
Most people assume a security hook in Claude Code is a wall. I did too, until I read the hooks reference closely this week. By default a hook that crashes, times out or returns garbage does not stop anything: the docs say that on most events, when a hook fails or times out, Claude Code still carries out the action. Release 2.1.328, published today, closes one gap in that story, so it is a good moment to check my own setup.
What onFailure actually does
The hooks reference describes an onFailure field on the hook handler with two values, "continue" and "block". Leaving it unset behaves like continue. With "block", a failure is treated like exit code 2 on that event, so a failing PreToolUse hook blocks the tool call, and on PermissionRequest it denies the request. What counts as a failure: a command that cannot start, an exit code other than 0 or 2, an HTTP connection error or non-2xx status, a timeout, or invalid output.
It has no effect on Stop, SubagentStop, TaskCompleted, TeammateIdle, or on background command hooks that set async or asyncRewake. The field needs v2.1.295 or later.
{
"type": "command",
"command": "node",
"args": ["${CLAUDE_PROJECT_DIR}/.claude/hooks/check-command.js"],
"onFailure": "block"
}
That snippet is the example from the docs. If node is missing, or the script throws, the tool call is blocked instead of quietly waved through.
What 2.1.328 adds
The release notes say: "Added "onFailure": "block" for mcp_tool hooks, as for command and HTTP hooks: a hook whose call fails blocks the action". One caveat from my reading: the hooks page I checked only lists onFailure in the field tables for command and HTTP hooks, so I would confirm the mcp_tool behaviour on your own install rather than trust the docs table alone.
Two neighbouring changes matter for anyone running managed policy. In 2.1.326, managed PreToolUse hooks that refused a direct tool call now leave an OpenTelemetry tool_decision event and a permission_denials entry, which they previously did not. And 2.1.328 changes managed PostToolUse hooks so they no longer fire for calls that were refused before they ran: no log entry, rewrite, block or stop there. If you built audit logging on PostToolUse, refused calls now vanish from it, so the telemetry event is where to look.
What I'm changing in my own config
I audited my hooks by one question: if this hook dies, do I want the action to proceed? For a hook that blocks writes to .env or vetoes destructive Bash commands, the answer is no, so those get "onFailure": "block". For a formatter or a notification hook, failing open is correct, because a flaky linter should not freeze a session.
The trade-off is real. A fail-closed hook with a slow dependency will stall you, and an HTTP hook pointing at a remote policy server now makes that server part of your availability. I keep the check local and fast for exactly that reason.
The takeaway: a guard that fails open is a suggestion. Check which of your hooks you would actually want to fail closed, and set it explicitly, because the default will not do it for you.