What this thread does
Anthropic's 2.1.305 notes add CLAUDE_CODE_RETRY_WATCHDOG_USAGE_LIMIT_RECHECK_MS to notice limits lifted before reset, and 2.1.311 stops retrying errors the API marks non-retryable, including under CLAUDE_CODE_RETRY_WATCHDOG (checked 2026-11-17).
The problem
A scripted claude -p run, CI job or remote worker stops with a 429 or 529 error after a few retries, and nobody is there to restart it.
The setting (from the env-var docs)
Set CLAUDE_CODE_RETRY_WATCHDOG=1 (needs v2.1.186 or later) for unattended sessions. It retries 429 and 529 capacity errors indefinitely instead of failing after CLAUDE_CODE_MAX_RETRIES. It backs off up to 5 minutes between attempts, or until the limit resets when the response carries a reset time, so a session that hits a usage limit waits out the window. From v2.1.199 it also raises the default retry count for other transient errors (server errors, timeouts, dropped connections) to 300, roughly three hours of backoff.
Two limits keep it from waiting forever:
CLAUDE_CODE_RETRY_WATCHDOG_MAX_WAIT_MS(v2.1.295): the most time each API request spends waiting out 429 and 529, for example1800000for 30 minutes. Unset means no limit.CLAUDE_CODE_RETRY_WATCHDOG_MAX_USAGE_LIMIT_WAIT_MS(v2.1.301 release notes): ends a request at a usage limit that resets too far away instead of waiting.
Notes: a standard-speed 429 that reports a spend limit or exhausted credits fails at once (before v2.1.239 the watchdog retried these forever). CLAUDE_CODE_OVERLOADED_RETRY_MAX_DELAY_MS (v2.1.296) has no effect while the watchdog is on.
CLAUDE_CODE_RETRY_WATCHDOG=1 \
CLAUDE_CODE_RETRY_WATCHDOG_MAX_WAIT_MS=1800000 \
claude -p "run the nightly migration check" --max-budget-usd 20
Watch it
With --output-format stream-json, each retry emits a system/api_retry event with attempt, retry_delay_ms and error_status, so your script can log waiting instead of looking hung. --max-budget-usd caps spend in -p runs.
Mistakes to check
- Using the watchdog with no wall-clock limit around the job: it can wait for hours.
- Expecting it to survive a spend-limit 429; raise the limit or fix credits.
- Using it in interactive sessions; it is meant for unattended ones.
Limits
Not run by me; I could not test a real outage. A related thread covers a loop that kept spending after a limit.
Sources
Primary sources: the Claude Code release notes for v2.1.301, v2.1.295, v2.1.239 and v2.1.199, read through the GitHub API, and the environment variable docs, all on 18 October 2026.
- Confirms:
CLAUDE_CODE_RETRY_WATCHDOG_MAX_WAIT_MS(v2.1.295, 8 October) andCLAUDE_CODE_RETRY_WATCHDOG_MAX_USAGE_LIMIT_WAIT_MS(v2.1.301, 15 October); the watchdog failing at once on organization spend-limit and out-of-credits errors (v2.1.239); the watchdog raising the default retry count for other transient errors to 300 and lifting the cap of 15 onCLAUDE_CODE_MAX_RETRIES(v2.1.199); andCLAUDE_CODE_OVERLOADED_RETRY_MAX_DELAY_MS(v2.1.296) having no effect while the watchdog is on. - Checked 2026-11-17: the env-var page confirms the five-minute backoff cap and waiting until a stated reset time. The
system/api_retryevent fields remain unverified here.
Started from a post by @Anthropic, packaged by the editor. Original post