[BUG]"Connection closed mid-response" errors on tool calls with large output (~40+ lines), reproducible across terminal/network/install — not fixed by clock resyn
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Claude Code v2.1.226 (npm install, confirmed clean via full uninstall/reinstall) repeatedly shows 'Connection closed mid-response' immediately following tool calls with larger output payloads (~40+ line grep/read results) — the tool call itself completes successfully and Claude Code correctly processes/summarizes the result, but the connection then drops right after. Reproducible across: VS Code integrated terminal and standalone cmd (identical), multiple Wi-Fi networks, fresh login, and after fixing a genuine Windows time-sync desync (w32time was unsynced) — none of these changed the behavior. Full reinstall (npm uninstall + cache clean + reinstall) also did not resolve it
Actual behavior: connection drops immediately following (not during) tool calls returning ~40+ lines of output, reproducibly, across every environmental variable tested above.
What Should Happen?
Claude should be able to use tools that generate large outputs and display them to user without an API connection error appearing every time
Expected behavior: connection remains stable through tool calls with larger output payloads, or fails gracefully with a retriable state rather than an ambiguous "may be incomplete" notice that sometimes cascades on continue.
Error Messages/Logs
API Error: Connection closed mid-response. The response above may be incomplete.
Steps to Reproduce
- Install Claude Code via npm: npm install -g @anthropic-ai/claude-code (v2.1.226, Windows).
- Open a project directory in either (a) VS Code's Claude Code extension, or (b) a standalone terminal (cmd or PowerShell) — behavior is identical in both.
- Issue a prompt that triggers a tool call producing a moderately large output payload — e.g., a Bash grep/unzip -p | grep loop returning 40+ matching lines, or a Read of a file spanning ~100 lines. Minimal reproducing example:
bash
for f in some_directory/*.zip; do
unzip -p "$f" 2>/dev/null | grep -i "SOME_PATTERN"
done
(any command returning roughly 40+ lines of output reliably triggers it in our testing; smaller outputs, e.g. under ~20 lines, do not)
- Observe: the tool call itself completes successfully — Claude Code receives the full output and correctly processes/summarizes it (confirmed multiple times: it accurately summarized 46 lines of matched data on the last reproduction).
- Immediately after that tool result, before or during the model's next response, the session displays: API Error: Connection closed mid-response. The response above may be incomplete.
- Sending continue sometimes resumes normally, but frequently the same error recurs immediately, sometimes 2–3 times in a row on the same turn.
Environment / what's been ruled out:
Reproduces identically in VS Code's integrated terminal, VS Code's Claude Code extension, and a fully standalone cmd.exe/PowerShell window outside VS Code.
Reproduces on multiple Wi-Fi networks (tested by switching networks entirely).
Reproduces after full logout/login of the Claude Code session.
A genuine, confirmed system issue was found and fixed during troubleshooting — Windows time sync (w32time) was desynced, running purely off the local CMOS clock (w32tm /query /status showed Leap Indicator: 3 (not synchronized), Source: Local CMOS Clock). This was fixed via manual NTP resync (w32tm /config /manualpeerlist:"time.windows.com,0x1" ... /update + w32tm /resync /force, confirmed Leap Indicator: 0 afterward) — the error persisted unchanged after this fix.
Reproduces after a full clean reinstall (npm uninstall -g @anthropic-ai/claude-code → npm cache clean --force → npm install -g @anthropic-ai/claude-code), confirmed via npm list -g and claude --version (2.1.226).
HTTP_PROXY/HTTPS_PROXY environment variables confirmed empty (no proxy involved).
No active incident on status.anthropic.com / status.claude.com at time of occurrence
Claude Model
Sonnet (default)
Is this a regression?
I don't know
Last Working Version
N/A / not determined
Claude Code Version
2.1.226
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
VS Code integrated terminal
Additional Information
Extensively troubleshot before filing: confirmed not a proxy issue (HTTP_PROXY/HTTPS_PROXY empty), not network-specific (reproduced across multiple Wi-Fi networks), not an auth/session issue (reproduced after full logout/login), not an install corruption (reproduced after full npm uninstall → cache clean → reinstall). One genuine local issue was found and fixed during troubleshooting — Windows time sync (w32time) was desynced (Leap Indicator: 3, Source: Local CMOS Clock) — but fixing it (confirmed Leap Indicator: 0 post-fix) did not resolve the Claude Code error. Failure consistently follows tool calls returning ~40+ lines of output; smaller outputs appear stable. No related repository or minimal standalone reproduction repo available — this was observed during real project work, not a synthetic test case.
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗