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.

The config

Add "onFailure":"block" to the hook in .claude/settings.json:

PROMPT
PASTE INTO .claude/settings.json
{ "hooks": { "PreToolUse": [ { "matcher": "Bash", "hooks": [ { "type": "command", "command": "node", "args": ["${CLAUDE_PROJECT_DIR}/.claude/hooks/check-command.js"], "onFailure": "block" } ] } ] } }

Free, for your email

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

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

Unlocks: 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.

Free MCP directory

Make your AI 100x more powerful.

Connect Claude, ChatGPT or Cursor to the apps you already use. Thousands of servers, one click to set up.

Browse free MCP servers

Read next