Connection Reset by Peer Error — Fix (2026)
The Error
Error: read ECONNRESET
code: 'ECONNRESET'
syscall: 'read'
at TLSWrap.onStreamRead (node:internal/stream_base_commons:217:20)
request to https://api.anthropic.com/v1/messages failed
This error occurs when the remote server or a network device forcibly closes the TCP connection during data transfer. The connection was established but then dropped.
The Fix
- Retry the request — this is usually transient:
claude "your prompt" || claude "your prompt"
- Configure the SDK with automatic retries:
import anthropic
client = anthropic.Anthropic(max_retries=3)
- Check your network connection:
curl -v https://api.anthropic.com 2>&1 | tail -5
ping -c 3 api.anthropic.com
- If on WiFi, try a wired connection or different network.
Why This Happens
ECONNRESET means the remote end sent a TCP RST packet, terminating the connection abruptly. Common causes: network instability (WiFi drops), load balancer timeout (the request took too long to process), firewall connection tracking table overflow, or VPN tunnel instability. This is a transport-level error, not an API error.
If That Doesn’t Work
- Disable HTTP keep-alive which can cause stale connection resets:
export ANTHROPIC_DISABLE_KEEPALIVE=1
- Increase TCP keepalive interval:
# macOS
sudo sysctl -w net.inet.tcp.keepidle=60000
- Check if your VPN is dropping long-lived connections and switch to split tunneling.
Prevention
Add this to your CLAUDE.md:
# Network Resilience
- Always configure max_retries >= 3 for API clients.
- Use wired connections for long-running Claude Code sessions.
- If behind VPN, enable split tunneling for api.anthropic.com.
- ECONNRESET is transient — retry before investigating.
Related Error Messages
This fix also applies if you see these related error messages:
ETIMEDOUT: connection timed outRequestTimeout: request took longer than 120000msESOCKETTIMEDOUTERR_TLS_CERT_ALTNAME_INVALIDUNABLE_TO_VERIFY_LEAF_SIGNATURE
Frequently Asked Questions
What is the default timeout for Claude Code API requests?
The default timeout is 120 seconds (120000ms). For complex operations involving large codebases or multi-file edits, this may be insufficient. Increase it with claude config set api_timeout 300000 for a 5-minute timeout.
Can network latency cause timeouts?
Yes. Corporate proxies, VPNs, and DNS filtering services add round-trip latency. Measure your baseline latency with curl -o /dev/null -s -w '%{time_total}' https://api.anthropic.com/v1/messages. If it exceeds 5 seconds, route API traffic outside the proxy.
Do timeouts consume API credits?
Partially. If the server began processing your request before the client timed out, the input tokens are consumed even though you never received a response. Long timeouts reduce wasted credits by allowing the response to complete.
What TLS version does Claude Code require?
Claude Code requires TLS 1.2 or later. The Anthropic API endpoints do not support TLS 1.0 or 1.1. If your network or proxy forces an older TLS version, the connection fails during the handshake.
Related Guides
Configure MCP → Build your server config with our MCP Config Generator.
Try it: Paste your error into our Error Diagnostic for an instant fix.
- Peer Dependency Conflict npm Error
- Fix WebSocket Connection Failures
- Fix Claude Code MCP Server Connection
- Claude Code MCP Server Connection
Implementation Details
When working with this in Claude Code, pay attention to these practical details:
Project configuration. Add specific instructions to your CLAUDE.md file describing how your project handles this area. Include file paths, naming conventions, and any patterns that differ from common defaults. Claude Code reads CLAUDE.md at the start of every session and uses it to guide all operations.
Testing the setup. After configuration, verify everything works by running a simple test task. Ask Claude Code to perform a read-only operation first (like listing files or reading a config) before moving to write operations. This confirms that permissions, paths, and tools are all correctly configured.
Monitoring and iteration. Track your results over several sessions. If Claude Code consistently makes the same mistake, the fix is usually a more specific CLAUDE.md instruction. If it makes different mistakes each time, the issue is likely in the project setup or toolchain configuration.
Troubleshooting Checklist
When something does not work as expected, check these items in order:
- CLAUDE.md exists at the project root — run
ls -la CLAUDE.mdto verify - Node.js version is 18+ — run
node --versionto check - API key is set — run
echo $ANTHROPIC_API_KEY | head -c 10to verify (shows first 10 characters only) - Disk space is available — run
df -h .to check - Network can reach the API — run
curl -s -o /dev/null -w "%{http_code}" https://api.anthropic.com(should return 401 without auth, meaning the server is reachable) - No conflicting processes — run
ps aux | grep claude | grep -v grepto check for stale sessions