Claude Code

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

2min read
2prompts to copy
5numbered steps
6sections

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.

Free, for your email

Get the full setup steps + the copy-paste setup prompt

The rest of this guide (5 more sections, 2 copy-paste prompts) opens right here. The setup prompt, one paste into Claude that sets it all up, comes by email only. Use your real address.

Unlocks: The config · What counts as a failure · Test it in two minutes · The catch · Sources

50,000+ follow where these guides come from. No spam, reply “unsubscribe” any time.

Read next