What it does
Sets a hard limit on how many times Claude Code can retry a failing approach before escalating to the human. Each retry must vary the approach — no identical retries. After 3 failed attempts, the agent stops and explains what it tried, what failed, and what it recommends.
When to use it
- In any project where you pay per token (every retry costs money)
- When working with a non-technical product owner who can’t debug alongside the agent
- In CI/CD debugging where the agent might loop on environment issues
- Anytime you’ve watched an AI agent spin for 10 minutes on the same error
How it works
Add to your CLAUDE.md:
## Error Escalation
- Try to self-resolve up to 3 attempts on any problem. Vary your approach each time.
- After 3 failed attempts, surface the problem in plain language: what you tried,
what failed, and what you recommend next.
- Never spin silently. If you're stuck, say so early rather than wasting tokens.
The agent will:
- Attempt to solve the problem (attempt 1)
- If that fails, try a different approach (attempt 2)
- If that fails, try yet another approach (attempt 3)
- If still failing, stop and report:
- What the problem is
- What 3 approaches were tried
- Why each failed
- A recommended next step
Example escalation output
## Stuck: migration failing on CI
**Attempt 1:** Ran `drizzle-kit migrate` with direct connection string → timeout after 30s
**Attempt 2:** Switched to pooler URL with `?sslmode=require` → SSL handshake error
**Attempt 3:** Added `?pgbouncer=true&connection_limit=1` → connected but permission denied on schema
**Diagnosis:** The CI database user likely doesn't have DDL permissions. This is an infrastructure issue, not a code issue.
**Recommended next step:** Check the CI database user's role and grant `CREATE` permission on the target schema, or use a migration-specific user with elevated privileges.
Why it matters
AI agents are optimistic by default — they’ll keep trying variations of the same approach, burning context window and tokens, without recognizing that the problem is outside their control. The 3-strike rule converts silent spinning into actionable information.