[Bug] Anthropic API Error: Connection closed mid-response
Status Open
Reported on v2.1.186
Maintainer reply None cached
Activity 18 comments · opened Jun 23, 2026
Bug Description
claude-code keeps stopping mid work, with the following message: ⏺ API Error: Connection closed mid-response. The response above may be incomplete.
This is costing real time and money.
Environment Info
- Platform: darwin
- Terminal: Apple_Terminal
- Version: 2.1.186
- Feedback ID: 44bd4a9a-a92e-4abe-9b05-e03afbfd8949
Errors
[]Showing cached comments. Read the full discussion on GitHub ↗
13 Comments
same issues
i ge the same issue out of nowhere, on many different networks, this is costing me money!!! i have to restart whole workflows because of this
Using Claude Code VSCode extension inside a Dev Container. It happens 3/4 times per session.
Same issue, both VS Code extension and CLI
try setting
CLAUDE_STREAM_IDLE_TIMEOUT_MSto larger timeout number or settingCLAUDE_ENABLE_BYTE_WATCHDOG/CLAUDE_ENABLE_STREAM_WATCHDOGto 0Haven't noticed a difference. Still getting the error. Also, here's what Claude had to say about it:
_How do these relate to claude-code experiencing this: API Error: Connection closed mid-response._
I had the same problem and was directed to the "closed as duplicate" issue by claude. Here's the report, hope it helps:
<html><body>
<!--StartFragment--><html><head></head><body><h2>Additional data point: repeated mid-stream stalls correlated with in-place extension version churn</h2>
<p><strong>Environment</strong></p>
<ul>
<li>Platform: Windows 10</li>
<li>Client: VS Code extension (<code>entrypoint: claude-vscode</code>)</li>
<li>Shell: Git Bash</li>
<li>Session type: long-running, tool-heavy conversation (multiple Explore/Agent subagent dispatches, large file reads)</li>
<li>Extension versions seen <strong>within a single session</strong>: 2.1.205 → 2.1.206 → 2.1.207</li>
</ul>
<p><strong>Summary</strong></p>
<p>Over a single Claude Code session I hit 11 distinct "Response stalled mid-stream" recoveries. Each recovery shows up in the local transcript as a synthetic client-generated message (<code>model: "<synthetic>"</code>, <code>stop_reason: "stop_sequence"</code>, zero token usage) rather than a real model turn, so the transcript itself doesn't capture the underlying network/process failure reason — only that a recovery was needed.</p>
<p>Switching models (Sonnet → Opus) did not resolve it; the same stall pattern resumed after a short delay. No VPN or proxy in use.</p>
<p><strong>Interruption timeline</strong></p>
Time (UTC) | Client version | Gap since last interruption
-- | -- | --
2026-07-10 20:17:36 | 2.1.205 | — (session start)
20:24:44 | 2.1.205 | 7.1 min
20:31:47 | 2.1.205 | 7.0 min
20:40:58 | 2.1.205 | 9.2 min
20:49:59 | 2.1.205 | 9.0 min
21:01:37 | 2.1.205 | 11.6 min
21:18:03 | 2.1.205 | 16.4 min
21:33:49 | 2.1.206 | 15.8 min
2026-07-11 08:24:00 | 2.1.206 | 650 min (session idle overnight)
08:28:48 | 2.1.207 | 4.8 min
08:43:35 | 2.1.207 | 14.8 min
<p><strong>Observations</strong></p>
<ol>
<li><strong>Periodic recurrence, not one-off flakiness.</strong> During the first active cluster (20:17–21:33 UTC), stalls recurred roughly every 7–16 minutes — consistent with a timeout/reconnect cycle on some underlying channel rather than random packet loss.</li>
<li><strong>Version churn mid-session.</strong> The extension's reported client version incremented twice (2.1.205 → 2.1.206 → 2.1.207) without the session restarting. This suggests the VS Code extension auto-updated in place at least twice while a long-lived connection to the CLI subprocess (or the subprocess's own connection upstream) stayed open. This is the one concrete correlated event visible in the transcript, and a plausible candidate cause: an in-place extension update may not cleanly hand off or re-establish whatever long-lived channel (SSE/websocket) backs the stream.</li>
<li><strong>No explicit error string in the transcript.</strong> No <code>ECONNRESET</code>, timeout, or "socket hang up" string appears anywhere in the local JSONL — the file only records the synthetic recovery prompt, not the network-layer failure. That detail likely only exists in <code>claude --debug</code> output or the extension's own output channel/log, neither of which was captured for this session.</li>
<li><strong>Not resolved by switching models.</strong> Sonnet → Opus initially appeared to help but the same stall pattern returned.</li>
</ol>
<p><strong>Source</strong></p>
<p>Local transcript: <code>~/.claude/projects/c--Users-stefan-Claude-Projects-Der-Gouverneur/8cb1d86d-0be9-4609-8550-9486bf72effd.jsonl</code></p>
<p><strong>Question for the team</strong></p>
<p>Does the VS Code extension hot-update while a session's connection is open, and if so, could that update interrupt or fail to restore the underlying stream? Happy to provide raw JSON for any of the 11 events above, or re-run with <code>claude --debug</code> if that would help isolate the actual network-layer error.</p></body></html><!--EndFragment-->
</body>
</html>
This is still happening, and apparently at a higher frequency. Is anybody from Anthropic paying attention?
!image
+1, same issue since yesterday in Claude Code via iTerm
Same issue ..
<img width="679" height="634" alt="Image" src="https://github.com/user-attachments/assets/47db8504-87a8-462e-8d7a-d6a5bd78d697" />
I found a temporary solution: The problem is probably that the agent is trying to enter too much data into a tool (in my case, creating a plan). So I asked him to write the plan step by step (he wrote the plan in several “chunks” in the same file), and I didn't have any issues.
you could try this: https://github.com/anthropics/claude-code/issues/70217#issuecomment-4929077488
Additional data point: local network ruled out with a 25-minute parallel probe
Environment
Symptoms (2026-07-21, all day)
ECONNRESETon the API socket, visible assystem/api_errorentries in~/.claude/projects/*/*.jsonlwithretryAttempt N / maxRetries 10,isSSLError: false. 83 ECONNRESET events on the worst day, 3 requests exhausted all 10 retries.CLAUDE_STREAM_IDLE_TIMEOUT_MS, then injects "API Error: Stream idle timeout - no chunks received" / "Connection closed mid-response". The desktop app logs it astimed out after ~1000s of inactivity, reason=incomplete_response, and the UI shows "Request interrupted by user" even though nobody touched anything.Why I'm confident it is not my network
api.anthropic.com(got expected 401), one to google.com, and a 1 MB upload. 82 rounds, zero connection errors, zero resets, while Claude Code sessions on the same machine were stalling at the same time.api.anthropic.comis the genuine Google Trust Services chain (no corporate MITM, no system proxy).overloaded_errorentries in the whole log.Mitigation that helps a little
CLAUDE_STREAM_IDLE_TIMEOUT_MS=120000(fail fast and retry instead of waiting 10 minutes). It does not fix the resets, it just shortens the hang.Happy to share sanitized
api_errorJSONL excerpts or app logs if useful.