GrepBoard/Manuals
605 manuals ·

Fix Claude Code "Connection lost before a response was produced"

·Tested on Claude Code official docs · 2026-10·Test scope ↓·6 steps

Claude Code "Connection lost before a response was produced": auto-retries failed after a drop between thinking and output. Resend, then check the network.

output
Connection lost before a response was producedYour computer went to sleep before a response was producedThe response stalled before a response was produced

Thinking had finished, but the connection dropped (sleep included) or stalled before any text or tool call had started. Claude Code re-issued the request the allowed number of times, failed at the same point each time, and ended the turn. No text or tool call was left behind, so send the same message again. Look at the network path only if it keeps happening.

If part of the response had already arrived when the stream broke, the message ends in The response above may be incomplete instead, and the fix is different. See The response above may be incomplete.

[1] Find where the request broke in this table. When you see one of these messages, Claude Code has already made whatever retries apply to that failure (per the docs' Automatic retries section).

Where it brokeAutomatic retryWhen it gives up
Connection drop before any part of the response, thinking included, has completedRe-issued with the same exponential backoff; the turn continues even if some text had started streamingError by cause once the budget (10 by default) is spent
Connection drop after thinking, before any text or tool callUp to two quick re-issuesConnection lost before a response was produced
The drop above was caused by the computer sleepingSame rules as a drop; the retry label reads Connection lost while your computer was asleepYour computer went to sleep before a response was produced
Headers arrived but no response, or a stall after thinkingAborts the stalled connection and streams again at most onceThe response stalled before a response was produced if it stalls a second time after thinking
Overloaded or server error after thinking, before any outputUp to two retries (v2.1.284 and later; earlier versions ended the turn)The server error message
A response says Claude is calling a tool but contains no tool callAsks for the tool call up to two times (once before v2.1.307)The model's tool call could not be parsed (retry also failed).
A dropped or damaged stream event when only thinking had completedRe-issuedPart of the response never arrived and no response was produced. Try again. or The response stream was malformed and no response was produced. Try again.

Before v2.1.227, Connection lost before a response was produced read Connection closed while thinking, before producing a response, and The response stalled before a response was produced read Response stalled while thinking, before producing a response. On an older version those mean the same thing.

[2] Send the message again. The original message is still in the conversation, so for a long prompt typing try again is enough (the docs suggest this under server errors). For the tool call parse failure, the docs' fix is also to send another message. If the next attempt succeeds, the drop was transient and nothing else is needed.

[3] If the message mentions sleep, stop the computer from sleeping. Claude Code detects that the machine slept partway through a request and counts it as a dropped connection. The docs go no further, so the practical step is to keep the laptop awake while a long task runs, lid closed or not.

[4] Learn to read the retry spinner, so the next failure is easier to place.

On screenMeaning
Retrying in Ns · attempt x/yWaiting to retry; the label in front names the reason
The label reads API errorThe specific reason isn't shown yet. As of v2.1.198 it switches to the specific reason from the third attempt
Network down, TLS handshake failed, rate limitReasons you can act on are named from the first attempt
Waiting for API response · will retry in … · check your networkNo data for at least 20 seconds. The request hasn't failed yet

The Waiting for API response banner and its longer delay behind gateways are covered in No response from API.

[5] If it breaks at the same point every time, check the path. A repeating Connection lost is the cue to investigate the network path. The candidates (internet connection, proxy, VPN, firewall) and the order to check them are in Unable to connect to API. Repetition alone does not say which one is at fault, so check them one at a time before changing any setting. A repeating stalled means the connection stays open while data stops, so check the watchdog table in Stream idle timeout.

[6] Log retries in -p CI runs. Claude Code emits a system/api_retry event before a retry, with attempt, max_retries, retry_delay_ms, error_status (null when no HTTP response came back) and error. One exception: on v2.1.246 and later, when a 401 or 403 rejects an apiKeyHelper credential, the first two retries are quiet with no event (they still count toward attempt), and events start from the third consecutive retry. Read attempt rather than counting events.

console
$ claude -p "Run the test suite and fix failures" --output-format stream-json --verbose | jq -c 'select(.type == "system" and .subtype == "api_retry") | {attempt, max_retries, retry_delay_ms, error_status, error}'

Change the retry count with environment variables.

VariableDefaultUse
CLAUDE_CODE_MAX_RETRIES10Lower it to surface failures faster in scripts. Capped at 15 as of v2.1.186
CLAUDE_CODE_RETRY_WATCHDOGunset1 raises the default retry count for transient errors such as server errors, timeouts and dropped connections to 300, roughly three hours of backoff, and removes the cap of 15 (v2.1.199 and later). For unattended runs

#claude-code#retry#streaming#api-error