Skip to content

[BUG] Claude Code fails to reconnect after network change (ECONNRESET) — requires process restart #23744

Description

@KindenKuo

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

Claude Code fails to reconnect after network change (ECONNRESET) — requires process restart

Bug Description

Claude Code becomes unable to connect to the API after switching between networks (e.g., office Wi-Fi → home Wi-Fi), returning ECONNRESET errors on every attempt. The only workaround is to kill the process (pkill -f claude) and restart it. Without this, even waiting through all 10 retry attempts fails.

Steps to Reproduce

  1. Start Claude Code on one network (e.g., office Wi-Fi / Ethernet)
  2. Switch to a different network (e.g., go home and connect to home Wi-Fi)
  3. Try to use Claude Code (e.g., run /init)

Expected Behavior

Claude Code should detect the network change and establish a new connection to api.anthropic.com.

Actual Behavior

⎿  Unable to connect to API (ECONNRESET)
   Retrying in 7 seconds… (attempt 5/10)

All 10 retry attempts fail with ECONNRESET. The error persists until the Claude Code process is fully killed and restarted.

Diagnosis

The issue appears to be stale HTTP/2 connection pooling. After a network change, the old socket is dead but Claude Code keeps trying to reuse it.

Evidence that the network itself is fine:

  • curl -v https://api.anthropic.com — works (HTTP 404 as expected, TLS OK)
  • node -e "const https = require('https'); https.get('https://api.anthropic.com', res => console.log(res.statusCode))" — works (returns 404)
  • DNS resolution works, no proxy configured, no firewall blocking
  • openssl s_client fails with errno=54 (connection reset), suggesting something at the socket/TLS layer

Killing all Claude processes and restarting immediately resolves the issue, confirming it's a stale connection problem rather than a system-level network issue.

Workaround

pkill -f claude
# Then restart Claude Code

Suggested Fix

  • Detect ECONNRESET during retries and force-close the existing connection pool before retrying, rather than reusing the same dead socket.
  • Optionally, listen for OS-level network change events (e.g., macOS SCNetworkReachability) to proactively reset connections.

Environment

  • OS: macOS 26.2
  • Claude Code version: v2.1.34
  • Network: switching between different Wi-Fi networks
  • Node.js: system default

What Should Happen?

Claude should work properly

Error Messages/Logs

⎿  Unable to connect to API (ECONNRESET)

Steps to Reproduce

Start Claude Code on one network (e.g., office Wi-Fi / Ethernet)
Switch to a different network (e.g., go home and connect to home Wi-Fi)
Try to use Claude Code (e.g., run /init)

Claude Model

Opus

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

Claude Code version: v2.1.34

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already exists

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions