# Hook Exit Code

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

**Field:** Artificial Intelligence  
**Category:** Claude Code  
**Also known as:** exit code 2, exit 2 hook

## Think of it like

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

## 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

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

## 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.

## Why it matters

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

## Common mistake

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

## Three principles

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

## Related terms

- [Hook JSON Output](https://learn.benibix.com/term/ai/hook-json-output)
- [PreToolUse Hook](https://learn.benibix.com/term/ai/pretooluse-hook)
- [Claude Code Hook](https://learn.benibix.com/term/ai/claude-code-hook)

![What each exit code from a hook does: 0 goes ahead, 2 blocks, anything else warns.](https://learn.benibix.com/diagrams/hook-exit-codes.svg)

---

Source: https://learn.benibix.com/term/ai/hook-exit-code
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-16
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
