Appearance
Text size
Typeface
Line spacing
Tips

Hooks

One at a time. Tell it whether you knew, and the ones you did not stay in your pile.

1 / 7

Exit code 2 blocks the action; any other non-zero code does not.

On exit 2 the stderr is fed back to Claude. Choose exit codes or JSON output, not both.

The whole topic7
  • Exit code 2 blocks the action; any other non-zero code does not.

    On exit 2 the stderr is fed back to Claude. Choose exit codes or JSON output, not both.

  • Only command and http hooks are deterministic.

    prompt and agent hooks ask another model, so they are judgment, not a guarantee.

  • A Stop hook can keep Claude fixing until the typecheck passes.

    Exit 2 sends the errors back and the turn continues. Redirect the output to stderr so Claude sees it.

  • A PostToolUse hook on Edit|Write removes the "remember to format" rule.

    Deterministic formatting after every edit beats a line in CLAUDE.md that Claude might skip.

  • A Stop hook that blocks eight times in a row is overridden.

    The turn then ends. CLAUDE_CODE_STOP_HOOK_BLOCK_CAP raises the limit.

  • A PreToolUse hook can rewrite a tool's input before it runs.

    For example, turn a test command into one that greps only failures, so far less output enters your context.

  • Hooks have no CLAUDE_MODEL variable.

    A PreModelSwitch hook receives the from and to models. The input JSON always carries session_id, cwd, permission_mode and effort.