Skip to content
BENIBIX Learn

Hook Exit Code

AI⌨️ Claude CodeConfiguration

Also known as exit code 2, exit 2 hook

The number a hook ends with: 0 goes ahead, 2 blocks, others warn.

Think of it like

It is like a traffic light. Green goes, red stops, and a flashing light just warns.

Example

Lucy's first hook exited 1 to block a command. Nothing was blocked. She changes it to exit 2, and it works.

Why it matters

One digit decides if your guard works. Most broken hooks use the wrong one.

Definition

A hook's exit code tells Claude Code what to do next. Exit 0 means go ahead, and any JSON the hook printed is read. Exit 2 means block: on events that can block, the action stops, and the hook's stderr is the reason. Any other code is a warning. The action goes on and you see a short error notice.

Example code

bash
#!/bin/bash
cmd=$(jq -r '.tool_input.command')
if [[ "$cmd" == *"rm -rf"* ]]; then
  echo "rm -rf is not allowed here" >&2
  exit 2
fi
exit 0
Block rm -rf with exit 2.
Three exits, three outcomes.

Common mistake

Exiting 1 to block. Only 2 blocks. Exit 1 just shows a warning and lets the action run.

Key takeaways

  1. 1
    0 goes ahead. JSON is read.
  2. 2
    2 blocks. stderr is the reason.
  3. 3
    Others warn. Action goes on.