GrepBoard/Manuals
605 manuals ·

Claude Code "Agent terminated early due to an API error" fix

·Tested on Claude Code official docs · v2.1.199 or later · 2026-11·Test scope ↓·5 steps

Claude Code shows "Agent terminated early due to an API error" when a subagent's request fails. The text after the colon is the cause; match it, fix it, retry.

output
Agent terminated early due to an API error: <error detail>

A subagent's API request failed for good, so the subagent stopped before it finished its task. The sentence itself is not the cause; the <error detail> after the colon is. Find that text, follow the fix for that error, and once it clears, ask Claude to retry the task or resume the subagent.

The docs give two examples of what triggers it: a usage limit was reached, or the retries for a server error ran out. The message exists only in Claude Code v2.1.199 and later. Before that, the API error text was handed to Claude as if it were the subagent's result, so older versions never print this line.

[1] Read the text after the colon exactly as shown. Copy the whole message so you can match it in the table below.

[2] Match the detail to its section. The official errors page says to match the text after the colon to its own section and follow that section's steps.

Text after the colonWhat it isGuide
You've hit your session limit · weekly limit · Opus limit · Sonnet limitPlan usage limit. Wait for the reset time shownClaude weekly limit reached: when it resets
You've hit your monthly spend limit and variantsSpend limit on usage creditsClaude Code monthly spend limit
Request rejected (429) · Server is temporarily limiting requestsRate limit or short-lived throttleClaude Code 429: usage limit or outage
API Error: 500 Internal server errorServer-side error at the APIClaude Code 500 Internal server error
API Error: Repeated 529 Overloaded errorsAPI at capacity for all usersClaude Code errors by message

If your text is not in the table, look it up on the official errors page (https://code.claude.com/docs/en/errors). If the message ends with a status page address, open that first.

[3] If it is a usage limit, treat it as an account problem, not a subagent problem. The limit is tied to your plan, so the main conversation is blocked too. Switching models does not lift the session or weekly limit. Run /usage to see the limits and reset times. If you need more room now, run /usage-credits to buy extra usage on Pro, Max or Ultra, or to request it from your admin on Team and Enterprise.

[4] If it is a server error (500 or 529), there is little to do but wait. By the time you see this message, Claude Code has already used its automatic retries; the documented default is 10 (CLAUDE_CODE_MAX_RETRIES). Check status.claude.com. For a 529, you can try /model to switch models, because capacity is tracked per model.

[5] Once the error clears, do not start over. Tell Claude to redo the task that stopped, or ask it to continue the same subagent. The docs say a resumed subagent keeps its full conversation history. Claude does the resuming with its SendMessage tool, using the agent ID or name, so you only need to say something like "continue that code review".

Why you see this message sometimes and not others

The same API error reaches Claude in different forms, so this line does not always appear. The docs draw the line like this.

Subagent situationWhat Claude receives
Foreground; a rate limit, overload or server error cut it off, and it had already produced textThe partial output, with a note that the subagent was cut off and did not finish
Foreground; it had produced nothing, or only tool callsAgent terminated early due to an API error plus the error detail
BackgroundThe subagent is marked failed, and the message names the API error and includes its last output

So if the subagent clearly worked for a while and you still only get this line, it may have been making tool calls without writing any text. The docs say that in v2.1.199 a subagent with only tool calls returned an empty partial result instead. If text was already there, you get the "response may be incomplete" note, covered in The response above may be incomplete.

Limits are the common trigger

Running several subagents at once burns through limits faster. The 429 section of the docs suggests avoiding many parallel subagents and using a smaller model for high-volume scripted runs, and notes that a single burst of heavy activity, such as a large workflow fanout, can exhaust the weekly allowance. If you keep seeing this message, cut the number of simultaneous subagents first.

For unattended runs (CI), CLAUDE_CODE_RETRY_WATCHDOG=1 makes Claude Code retry 429 and 529 errors indefinitely. Because it never gives up on its own, set a timeout on the CI job as well. The docs also list CLAUDE_CODE_RETRY_WATCHDOG_MAX_WAIT_MS to cap how long each request waits (v2.1.295 or later). A 429 that reports a spend limit or exhausted usage credits still fails at once, and that can stop a subagent immediately.

#claude-code#subagent#api-error#troubleshooting