Make a Crashed Claude Hook Block the Action, Not Let It Through
By default, a Claude Code hook that crashes, times out or can't start lets the action run anyway. One setting flips that. The exact config, what counts as a failure, and where it does nothing
A hook you wrote to guard something, say a script that checks every shell command, fails open by default. If the script path is wrong or the script crashes, Claude Code shows a small error and carries out the action anyway. Version 2.1.295 added a setting that makes the same failure block the action.
Here's the config, a two-minute test, and the places it does nothing.
What changed
- New field on command and HTTP hooks: onFailure, with two values, "continue" (the default) and "block".
- With "block", a failure does what exit code 2 does on that event. A PreToolUse failure blocks the tool call and a UserPromptSubmit failure blocks the prompt. On PermissionRequest it denies the request.
- It needs Claude Code v2.1.295 or later.
Keep reading
Free, for an email.
Unlocks 5 more sections, 2 copy-paste prompts, the document version, and every other guide on the site, for free. Enter your email once to keep reading.
45,000+ follow where these guides come from.No spam. Unsubscribe in one click.