C Claude Code Internals
| EN | ES

重试逻辑

Claude Code 实现指数退避,最多重试 10 次。不同的错误代码有不同的重试策略,无人值守模式对长时间运行的任务有特殊处理。

10 最大重试次数(默认) 500ms 基础退避延迟 5min 最大退避延迟 6h 无人值守模式上限

重试流程

1
API call fails
Error received from the Anthropic API.
2
Check error code
Different codes have different retry budgets and delays.
3
Calculate backoff 500ms → 5min
Exponential backoff: 500ms base, doubles each attempt, capped at 5 minutes.
4
Wait and retry
Wait the calculated delay, then retry the request.
5
Max retries reached?
After 10 attempts (default), surface the error to the user.

错误代码行为

Error Name Max retries Notes
529 Overloaded 3 Only for foreground queries. Background queries are not retried on 529.
429 Rate limited 10 Uses retry-after headers from the response if present, otherwise uses exponential backoff.
Other 5xx Server errors 10 Standard exponential backoff applies.

无人值守模式(内部)

Used internally for long-running automated tasks. Unattended mode has different retry behavior:

  • · Indefinite retries (no max retry limit)
  • · 30-second heartbeat keeps the process alive
  • · 6-hour hard cap prevents runaway processes
  • · Not available in standard user sessions
i 退避是每个会话的,不是全局的
重试计数器在单独的 API 调用之间重置。如果 Claude 在一个会话中进行 10 次工具调用, 每次调用都有自己独立的 10 次重试预算。单个缓慢的 API 响应不会消耗其他操作的重试次数。