Skip to main content
AI RADARVibe Coding
4•11/14/2026, 17:35•2 min read

Claude Stop Hook: Why exit 2 Makes the Model Retry

Claude Stop Hook: Why exit 2 Makes the Model Retry
Executive TL;DR30s read

A Claude Stop hook can return the model to a task after a failed check, but it must exit with code 2 and send errors to stderr.

Claude Stop Hook: Why exit 2 Makes the Model Retry

A Stop hook can make Claude retry when a check fails. However, the hook must exit with code 2.

Differences between exit codes:

  • exit 2 returns Claude to task execution and passes the hook's stderr contents to it, allowing the model to fix the error.
  • exit 1 does not block completion, so Claude simply finishes even if the check failed.

Additionally, exit 1 may indicate an error in the hook itself, such as a missing dependency or a bug in its script.

So, if you want Claude to retry, use exit 2 and send error output to stderr.

Example:

BASH
[your command] >&2 || { echo failed; exit 2; }

Why it matters

Analysis

Correct exit codes turn Stop hooks into an actionable self-correction mechanism for AI coding agents, rather than a silent failure signal.

Discuss in community

Share your questions and insights with developers

Join Telegram
+5 Points
← Back to news feed

Related in Ecosystem

Practical guides, core terminology, and agent skills