[BUG] Interactive mode fails with ECONNRESET while -p (print) mode works fine
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?
Interactive mode fails with ECONNRESET while -p (print) mode works fine
Environment
- Claude Code version: 2.1.39 (also reproduced on 2.1.34)
- OS: macOS (Apple Silicon)
- Node: v20.12.2
- Bun: (bundled with Claude Code)
- Auth method: OAuth (Claude Pro subscription)
Description
Interactive mode consistently fails with Unable to connect to API (ECONNRESET) on every attempt. Print mode (claude -p) works perfectly every time, from any directory. This has been verified across two Claude Code versions (2.1.34 and 2.1.39).
Steps to Reproduce
- Authenticate via
claude login(succeeds) - Run
claude -p "hi"→ works, returns response - Run
claude(interactive mode), type anything → fails with ECONNRESET after a few seconds
❯ hello
⎿ Unable to connect to API (ECONNRESET)
Retrying in 20 seconds… (attempt 6/10)
Key Diagnostic Findings
Network is not the issue
curltoapi.anthropic.comworks (TLS, streaming, authenticated — all fine)bun -e "fetch('https://api.anthropic.com/v1/messages'...)"works, including streaming viaReadableStream- All relevant Anthropic endpoints resolve and respond (
api.anthropic.com,statsig.anthropic.com,console.anthropic.com)
Auth is not the issue
- OAuth token is present in macOS Keychain under
Claude Code-credentials - Token has valid scopes:
user:inference,user:mcp_servers,user:profile,user:sessions:claude_code - Token is not expired
- MCP server connections authenticate and connect successfully during interactive startup (Craft and Vercel MCP servers connect fine in the same session that fails to send messages)
-pmode works with the same token
Debug log comparison
Both -p and interactive mode show identical auth logging:
[API:request] Creating client, ANTHROPIC_CUSTOM_HEADERS present: false, has Authorization header: false
[API:auth] OAuth token check starting
[API:auth] OAuth token check complete
In -p mode, the request succeeds. In interactive mode, it immediately fails:
[ERROR] API error (attempt 1/11): undefined Connection error.
The only observable difference in the logs is the billing header:
-pmode:cc_entrypoint=sdk-cli- Interactive mode:
cc_entrypoint=cli
Telemetry also fails
The 1P event logging also fails with ECONNRESET in interactive mode, suggesting it's not limited to the messages API endpoint:
[ERROR] 1P event logging: 33 events failed to export (code=ECONNRESET, The socket connection was closed unexpectedly.)
Not directory-specific
Fails from /tmp, ~, ~/Code, ~/Desktop — all directories. The -p mode works from all of these.
What I've ruled out
- ❌ DNS issues (all endpoints resolve)
- ❌ TLS issues (TLSv1.3 handshake completes)
- ❌ Router/ISP blocking (curl streaming test works)
- ❌ Proxy settings (no HTTP_PROXY/HTTPS_PROXY set)
- ❌ Bun networking (standalone Bun fetch + streaming works)
- ❌ Stale API key in env (removed, confirmed clean)
- ❌ Zombie processes / file lock contention (killed all, no change)
- ❌ MCP server interference (no local MCP config; cloud MCP servers actually connect fine)
- ❌ Hooks (disabled all hooks, no change)
- ❌ Version-specific regression (same on 2.1.34 and 2.1.39)
- ❌ macOS firewall (not enabled)
Expected Behavior
Interactive mode should connect to the API the same way -p mode does.
Workaround
claude -p "prompt" works reliably as a non-interactive alternative.
What Should Happen?
Interactive mode should connect to the API the same way -p mode does.
Error Messages/Logs
Steps to Reproduce
- Authenticate via
claude login(succeeds) - Run
claude -p "hi"→ works, returns response - Run
claude(interactive mode), type anything → fails with ECONNRESET after a few seconds
Claude Model
Not sure / Multiple models
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.39 (Claude Code)
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
This report was created by Claude. I spent two hours debugging with it earlier (via web). Super frustrating to have Claude just stop working.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗