Skip to content

ECONNRESET kills session — needs auto-retry/reconnect #24614

@wonderstone843

Description

@wonderstone843

Problem

When an ECONNRESET error occurs (API connection forcibly closed by server), Claude Code enters a completely unrecoverable state. The session freezes with 0 thinking tokens and no output. Pressing Ctrl+O to re-trigger shows 0 tokens indefinitely — the connection is dead but the CLI doesn't detect or recover from it.

The only fix is to kill the session entirely and start a new conversation, losing all in-flight context.

Expected Behavior

Claude Code should automatically retry the API request with exponential backoff when it encounters ECONNRESET or similar transient network errors. This is standard practice for API clients.

Suggested behavior:

  • Detect ECONNRESET, ETIMEDOUT, ECONNREFUSED, and similar transient TCP errors
  • Retry with exponential backoff (e.g., 1s → 2s → 4s → 8s, max 3-5 attempts)
  • Display a message like "Connection lost, retrying (attempt 2/5)..."
  • If all retries fail, surface a clear error and let the user manually retry instead of silently hanging forever

Current Behavior

  • Connection drops → session freezes
  • Shows 0 thinking tokens
  • Ctrl+O re-triggers but hangs at 0 tokens again (same dead connection)
  • Ctrl+C is the only escape, and the session context is lost
  • User must restart Claude Code and manually re-establish context

Impact

  • Complete loss of conversation context on every network hiccup
  • Particularly disruptive during long multi-step tasks
  • No way to configure retry behavior (no env var, no setting)
  • Users with unstable connections or during API load spikes are hit repeatedly

Environment

  • macOS (Darwin 25.2.0)
  • Claude Code CLI (latest)

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already exists

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions