Skip to main content
🎓 Claude Code Masterclass Learn AI-assisted development on Udemy — plus the companion book on Leanpub & Amazon. Start Learning
Fixing ECONNRESET and agent crash loop errors in Claude Code
AI

Claude Code Errors: Fix ECONNRESET and Agent Crash Loops

Claude Code errors explained and fixed: ECONNRESET, Response stalled mid-stream, and Agent process failed to restart after 5 consecutive crashes.

LB
Luca Berton
· 8 min read

This is a practical Claude Code troubleshooting guide: the connection-reset family of errors (ECONNRESET, Response stalled mid-stream) and the agent crash loop (Agent process failed to restart after 5 consecutive crashes). Pick the section that matches what you saw.

If you are mid-session in Claude Code and suddenly hit ECONNRESET — or the related API Error: Response stalled mid-stream. The response above may be incomplete — it means the TCP connection between your client and api.anthropic.com was closed by the other side before the request finished. The error is a network signal, not a code bug in your project. That distinction matters, because it tells you where to look first: the transport layer, not your source code. Both messages come from the same family of failure — the link dropped while data was still in flight.

First, the reassuring part. As of this writing, the Claude status page shows Claude API and Claude Code as operational. Several incidents did occur and were resolved on July 22–23, 2026, so a brief retry after an incident window usually clears itself. If the status page is green and you are still seeing resets, the cause is almost always on your side of the network.

What ECONNRESET actually means

ECONNRESET is a POSIX socket error: connection reset by peer. In plain terms, the remote host (or something sitting between you and it — a proxy, VPN, or firewall) tore down the TCP connection without a clean close. Claude Code was mid-stream, expecting more bytes, and got a reset packet instead. Anthropic specifically calls out VPNs, firewalls, and network restrictions as common culprits, and notes that some networks silently terminate idle, non-streaming connections.

Fix it in this order

Try the steps top to bottom. Most resets resolve at step 1 or 2.

1. Restart Claude Code

Close Claude Code completely, reopen it, and retry. A transient service blip or a stale local socket is the cheapest thing to rule out first.

2. Drop the VPN / proxy, or change networks

Turn off any VPN or proxy, or switch to a different network or hotspot. This is the single most common fix for ECONNRESET with Claude Code. If you are on a corporate VPN, try a phone hotspot to confirm the tunnel is the issue.

3. Run the built-in doctor

claude doctor

Or run /doctor from inside Claude Code. It checks your local environment, auth, and connectivity and reports what is misconfigured.

4. Test raw connectivity with curl

curl -v https://api.anthropic.com

A response like 404, 405, or an authentication error is good — it proves the server is reachable and TLS is working. A TLS failure, timeout, or another connection reset points squarely at your network, proxy, antivirus, or firewall. The -v flag shows the exact TLS handshake step where things break, which is the fastest way to localize the fault.

5. Update Claude Code, then restart the terminal

Update to the newest available version, then fully restart the terminal. Stale CLI builds occasionally hold broken connection state or ship fixes for transport handling.

6. Stream long requests

For long API requests, use streaming or reduce the request duration. Anthropic notes that some networks terminate idle, non-streaming connections, so a long generation with no bytes on the wire can get killed by an intermediate proxy. Streaming keeps the connection alive with steady traffic.

API Error: Response stalled mid-stream

ECONNRESET is the abrupt version of this failure. The Response stalled mid-stream message is the gentler cousin: the connection was held open, but bytes stopped arriving before the response completed, so Claude Code reports the output as potentially incomplete. Same root causes — a VPN, proxy, firewall, or unstable network silently cutting or throttling the stream — just surfaced at a different point in the request lifecycle.

What to do when you see it:

  • Retry the request. If the stall was transient, a fresh connection usually completes. This is the same “restart and retry” first step as ECONNRESET.
  • Drop the VPN/proxy or switch networks. A re-signing or throttling proxy is the most common reason a stream stalls partway instead of failing outright.
  • Enable streaming and keep requests shorter. Mid-stream stalls are more likely on long, non-streaming generations where an intermediate proxy times out the idle connection. Streaming keeps bytes flowing; splitting a large task into smaller turns reduces how long any single connection stays open.
  • Run claude doctor and the curl -v https://api.anthropic.com check from the steps above to confirm the transport path is healthy.

If the message says the response may be incomplete, treat the last block of output as suspect and re-run the task — the model may have lost part of its answer when the stream broke.

Agent process failed to restart after 5 consecutive crashes

This is a different failure class from the network errors above. The connection resets are about the link to the API; this message is about Claude Code’s own process stability. It appears when the agent (or a background subagent) crashes five times in a row and the supervisor gives up trying to relaunch it. Your code is not the cause — something in the runtime environment is crashing the process on startup or shortly after.

The usual suspects, in order of frequency:

  • A hook, MCP server, or plugin that throws on startup. A PostToolUse/PreToolUse hook that exits non-zero, a misconfigured MCP server, or a plugin loaded via settings.json can crash the agent before it settles. This is the single most common trigger for a repeated crash loop.
  • Corrupted session/state or settings. A partially-written session file, a malformed settings.json, or a broken ~/.claude.json can make every launch fail.
  • OOM / resource exhaustion. On memory-constrained machines or large repos, the process can be killed by the OS (or by systemd/cgroup limits) before it stabilizes — especially when many subagents run in parallel.
  • A native/memory bug in a specific build. Rare, but real: a given CLI version can have a crash on certain platforms.

What to do, in order

  1. Restart in safe mode. Run claude --safe-mode. This disables all plugins, MCP servers, and hooks for that session. If the agent now starts cleanly, you have confirmed the fault is in a customization — a hook, MCP server, or plugin. That narrows the hunt enormously.
  2. Run the diagnostics. claude doctor (or /doctor inside Claude Code) checks your installation, settings, extensions, and context usage, and proposes fixes it can apply after you confirm. Run /mcp to check MCP server status — a crashed or misconfigured server shows up here.
  3. Isolate the bad customization. From safe mode, re-enable components one at a time: add back an MCP server, then a hook, then a plugin. The one that brings the crash back is your culprit. Fix or remove it in settings.json (user or project) or your MCP config.
  4. Free memory and compact context. Use /compact regularly to shrink context, close Claude Code between major tasks, and add large build/artifact directories to .gitignore so they are not scanned. If memory stays high, run /heapdump to write a memory breakdown (the -diagnostics.json file) and inspect it.
  5. Resume, don’t start cold. Restarting does not lose your conversation. Run claude --resume in the same directory to pick the session back up, or /clear the earlier conversation if it is no longer needed and the state is what is crashing the relaunch.
  6. Update, or roll back. Update to the newest Claude Code version (claude update) and fully restart the terminal. If the crashes started right after an update, downgrade to the previous version while you wait for the fix — a specific build can have a platform-specific crash.

On a corporate machine, an endpoint agent, EDR/antivirus, or a container cgroup memory cap is often what kills the process. Check the OS logs (journalctl, the macOS Console, or Windows Event Viewer) for an OOM kill or a terminated-process entry at the exact time of each crash.

Corporate networks

On a locked-down corporate network, ask IT to allow outbound HTTPS traffic to api.anthropic.com on port 443. No exceptions, no MITM proxy inspection on that host — a TLS-inspecting proxy that re-signs certificates is a frequent source of resets.

FAQ

Is ECONNRESET a bug in my code? No. It is a transport-layer error indicating the connection was reset before the API call completed. Your application code is not the cause.

The status page says operational but I still get resets. Why? The reset is almost always local — a VPN, proxy, firewall, or unstable network on your side. The steps above target exactly those causes.

What does a “good” curl response look like? 404, 405, or an auth error all mean you reached the server successfully. Only a TLS failure or connection reset signals a network/proxy problem.

Why does streaming help? Some networks drop idle, non-streaming connections. Streaming sends bytes continuously, keeping the connection from looking idle to intermediate proxies.

What is “Response stalled mid-stream”? The same family of failure as ECONNRESET, but the connection was held open while bytes stopped arriving, so Claude Code flags the output as possibly incomplete. Retry, drop the VPN/proxy, and keep generations short and streamed.

“Agent process failed to restart after 5 consecutive crashes” — what now? That is a process-stability fault, not a network one. Start claude --safe-mode; if it launches cleanly, a hook, MCP server, or plugin is the culprit. Run /doctor and /mcp, then re-enable customizations one at a time to isolate the bad one. Memory exhaustion (check journalctl/Event Viewer for an OOM kill) and a bad CLI build are the other common causes.

Key takeaways

  • ECONNRESET is a network fault, not a code bug — check the transport layer first.
  • Response stalled mid-stream is the same failure family; retry and treat the last output block as suspect.
  • Agent process failed to restart after 5 consecutive crashes is a process-stability fault — launch claude --safe-mode; if it works, a hook/MCP server/plugin is crashing it.
  • Restart Claude Code, then drop the VPN/proxy before anything else.
  • curl -v https://api.anthropic.com is your fastest diagnostic: any HTTP status = reachable, TLS reset = network fault.
  • On corporate networks, allow outbound 443 to api.anthropic.com and avoid TLS-inspecting proxies.
#Claude Code #Troubleshooting #API #DevOps #Networking #Agents
Share:
AI Integration & GPU Platforms

Need help with AI Integration & GPU Platforms?

Need help deploying AI/ML platforms? Get expert consulting on OpenShift AI, GPU orchestration, and MLOps.

Learn more about AI Integration & GPU Platforms

Want to operate this yourself, in production?

Take the free AI Platform Engineer Readiness Scorecard to see which skills transfer — then build a production-shaped AI platform in the 4-week Bootcamp.

Take the Scorecard →
Luca Berton — AI & Cloud Advisor, Docker Captain

Luca Berton

AI & Cloud Advisor · Docker Captain · KubeCon Speaker

15+ years in enterprise infrastructure. Author of 8 technical books, creator of Ansible Pilot (1M+ YouTube views, 648K site users). Former Red Hat engineer. Speaker at KubeCon EU 2026 and Red Hat Summit 2026.

Free 30-min AI & Cloud consultation

Book Now