⎿ API Error: Unable to connect to API...
Status Open
Reported on v2.1.119
Maintainer reply None cached
Activity 11 comments · opened Apr 25, 2026
Bug Description
⎿ API Error: Unable to connect to API (ConnectionRefused)
Environment Info
- Platform: darwin
- Terminal: Apple_Terminal
- Version: 2.1.119
- Feedback ID: 426b888e-b151-4d45-b48e-855c908bcfd4
Errors
[{"error":"Error: Connection error.\n at makeRequest (/$bunfs/root/src/entrypoints/cli.js:50:4056)\n at processTicksAndRejections (native:7:39)","timestamp":"2026-04-25T19:15:10.908Z"},{"error":"SyntaxError: JSON Parse error: Unexpected identifier \"API\"\n at <parse> (:0)\n at parse (unknown)\n at SHq (/$bunfs/root/src/entrypoints/cli.js:174:10030)\n at O (/$bunfs/root/src/entrypoints/cli.js:134:19235)\n at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:176:1502)\n at XqH (/$bunfs/root/src/entrypoints/cli.js:6422:476)\n at processTicksAndRejections (native:7:39)","timestamp":"2026-04-25T19:15:10.909Z"},{"error":"Error: Connection error.\n at makeRequest (/$bunfs/root/src/entrypoints/cli.js:50:4056)\n at processTicksAndRejections (native:7:39)","timestamp":"2026-04-25T19:15:16.993Z"},{"error":"Error: Request was aborted.\n at kX8 (/$bunfs/root/src/entrypoints/cli.js:5379:8020)\n at $ (/$bunfs/root/src/entrypoints/cli.js:261:16485)\n at abort (unknown)\n at HT (/$bunfs/root/src/entrypoints/cli.js:9168:7587)\n at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:9128:4775)\n at Y (/$bunfs/root/src/entrypoints/cli.js:2624:3568)\n at J (/$bunfs/root/src/entrypoints/cli.js:2624:3898)\n at _A1 (/$bunfs/root/src/entrypoints/cli.js:498:1976)\n at dispatch (/$bunfs/root/src/entrypoints/cli.js:498:2652)\n at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:484:111880)","timestamp":"2026-04-25T19:16:55.993Z"},{"error":"Error: Request was aborted.\n at kX8 (/$bunfs/root/src/entrypoints/cli.js:5379:8020)\n at $ (/$bunfs/root/src/entrypoints/cli.js:261:16485)\n at abort (unknown)\n at HT (/$bunfs/root/src/entrypoints/cli.js:9168:7587)\n at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:9128:4775)\n at Y (/$bunfs/root/src/entrypoints/cli.js:2624:3568)\n at J (/$bunfs/root/src/entrypoints/cli.js:2624:3898)\n at _A1 (/$bunfs/root/src/entrypoints/cli.js:498:1976)\n at dispatch (/$bunfs/root/src/entrypoints/cli.js:498:2652)\n at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:484:111880)","timestamp":"2026-04-25T19:16:56.959Z"},{"error":"Error: Connection error.\n at makeRequest (/$bunfs/root/src/entrypoints/cli.js:50:4056)\n at processTicksAndRejections (native:7:39)","timestamp":"2026-04-25T19:18:14.393Z"},{"error":"Error: Connection error.\n at makeRequest (/$bunfs/root/src/entrypoints/cli.js:50:4056)\n at processTicksAndRejections (native:7:39)","timestamp":"2026-04-25T19:19:59.490Z"},{"error":"Error: Connection error.\n at makeRequest (/$bunfs/root/src/entrypoints/cli.js:50:4056)\n at processTicksAndRejections (native:7:39)","timestamp":"2026-04-25T19:23:29.320Z"},{"error":"Error: Connection error.\n at makeRequest (/$bunfs/root/src/entrypoints/cli.js:50:4056)\n at processTicksAndRejections (native:7:39)","timestamp":"2026-04-25T19:23:41.855Z"},{"error":"Error: ECONNREFUSED\n at from (/$bunfs/root/src/entrypoints/cli.js:111:7862)\n at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:119:12876)\n at emitError (node:events:43:23)\n at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:118:1149)\n at emitError (node:events:43:23)\n at <anonymous> (node:_http_client:253:22)\n at processTicksAndRejections (native:7:39)\n at request (/$bunfs/root/src/entrypoints/cli.js:121:2467)\n at processTicksAndRejections (native:7:39)","timestamp":"2026-04-25T19:23:44.328Z"},{"error":"Error: Request was aborted.\n at kX8 (/$bunfs/root/src/entrypoints/cli.js:5379:8020)\n at $ (/$bunfs/root/src/entrypoints/cli.js:261:16485)\n at abort (unknown)\n at HT (/$bunfs/root/src/entrypoints/cli.js:9168:7587)\n at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:9128:4775)\n at Y (/$bunfs/root/src/entrypoints/cli.js:2624:3568)\n at J (/$bunfs/root/src/entrypoints/cli.js:2624:3898)\n at _A1 (/$bunfs/root/src/entrypoints/cli.js:498:1976)\n at dispatch (/$bunfs/root/src/entrypoints/cli.js:498:2652)\n at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:484:111880)","timestamp":"…
Note: Content was truncated.
11 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
Unable to Connect ti Claude code. Blank Scrren for last 30 minutes. Loss of produictive hrs.
+1 — same symptom on May 5, 2026 (UTC).
Environment:
Observations:
Unable to connect to API (ConnectionRefused)retry loopThis issue has been open since April 25, 2026 — would appreciate any update from the team. The recurring pattern across #16331, #17541, #33355, #53346, #56017, #56140 suggests an unresolved root cause rather than per-incident network problems.
Also experiencing this issue, an update would be appreciated.
Reproducing this on macOS 26.5 with Claude Code v2.1.143 — still unresolved on later versions. Adding diagnostic data in case it helps identify a fix.
Environment
~/.local/bin/claude→~/.local/share/claude/versions/2.1.143)Symptoms
Identical to OP —
Unable to connect to API (ConnectionRefused/ECONNRESET)on every prompt submission, with retry loop. Authentication itself succeeds ("Welcome back" displayed,oauthAccountpopulated, Keychain entry written), but the moment a prompt is sent, the connection fails.Diagnostic: no outbound packets are emitted
macOS
SFA-rootNetworking.jsondiagnostic report (~/Library/Logs/DiagnosticReports/) during the failing session:Zero successes, zero failures — meaning Claude Code's HTTPS layer is not emitting outbound packets at all. This is consistent with the diagnosis in the original report that Bun's HTTP client is failing before the connection is established.
Meanwhile, the network path is fully healthy from the same shell:
What I ruled out (none resolved the issue)
curltoapi.anthropic.comsucceeds, TLS handshake OKHTTP_PROXY,HTTPS_PROXY,ANTHROPIC_*,CLAUDE_*setsocketfilterfw --getappblockedreportsclaudeas permitted; firewall global state checked, no blocking rules--addand--unblockapp~/.claude.jsonoauthAccountpopulated correctly; macOS KeychainClaude Code-credentialsentry exists and refreshes on/loginpolicy-limits.json— removed and regenerated, no effectclaude-mem, no change~/.claude.json, no changesettings.json— replaced with minimal config ({"permissions": {"defaultMode": "auto"}}), no changeversions/2.1.141directly, same errorbun upgradefrom v1.3.8 → v1.3.14, no change@anthropic-ai/claude-codeper the binary's own warning, no change~/.claude/,~/.claude.json, Keychain credential, reauthenticated, same errordscacheutil -flushcache+killall -HUP mDNSResponder, no changetccutil reset SystemPolicyAllFiles, no changeSide note: related local-loopback failure
In my case the retry loop also coincided with a
Connection refusedto127.0.0.1:37777(theclaude-memworker socket), but disablingclaude-memand killing all worker/chroma processes did not fix the upstreamapi.anthropic.comconnectivity. The two appear to share a root cause in how Bun's networking interacts with macOS Tahoe 26.x.Reproduction
100% reproducible on every prompt submission, immediately after a clean install. Auth flow completes, then the very first
hellotriggers the retry loop.Happy to attach
~/.claude/debug/contents,lsof -p <claude_pid>output, or run any further diagnostic commands the maintainers want.---
Related reports (same root cause, different macOS Tahoe builds):
<html><head></head><body><h2>Follow-up: Further diagnostic findings on macOS 26.5</h2>
<p>After extensive additional debugging, I can confirm the root cause is in the <strong>bundled Bun runtime's HTTP layer</strong>, specifically when handling connections to <code>api.anthropic.com</code>. Here's what I found:</p>
<h3>Key isolation test: bundled Bun vs system Bun</h3>
<pre><code class="language-bash"># System Bun (1.4.0-canary.1+ad68af805) — 10 consecutive POSTs to api.anthropic.com
$ for i in {1..10}; do
bun -e "fetch('https://api.anthropic.com/v1/messages', {method: 'POST'}).then(r => console.log('Status:', r.status)).catch(e => console.log('FAIL:', e.message))"
done
Attempt 1: Status: 401
Attempt 2: FAIL: Unable to connect. Is the computer able to access the url?
Attempt 3: Status: 401
Attempt 4: Status: 401
Attempt 5: Status: 401
Attempt 6: Status: 401
Attempt 7: Status: 401
Attempt 8: Status: 401
Attempt 9: Status: 401
Attempt 10: Status: 401
</code></pre>
<p>System Bun succeeds ~90% of the time (1 intermittent failure out of 10). But:</p>
<pre><code class="language-bash"># Claude Code (bundled Bun) — every single call fails
$ claude -p "hello"
API Error: Unable to connect to API (ECONNRESET)
</code></pre>
<p>Same machine, same network, same moment. <strong>System Bun mostly works, bundled Bun never works.</strong> The bundled Bun appears to be on an older version and/or has different network configuration.</p>
<h3>Domain-specific failure</h3>
<p>Bun's failure is <strong>specific to <code>api.anthropic.com</code></strong> — other Anthropic domains work fine:</p>
<pre><code class="language-bash">$ bun -e "fetch('https://example.com').then(r => console.log(r.status))"
Status: 200
$ bun -e "fetch('https://statsig.anthropic.com').then(r => console.log(r.status))"
Status: 530 # Reaches Cloudflare, gets an error — but connection succeeds
$ bun -e "fetch('https://console.anthropic.com').then(r => console.log(r.status))"
Status: 200
$ bun -e "fetch('https://api.anthropic.com/v1/messages', {method: 'POST'}).then(r => console.log(r.status))"
Error: Unable to connect. Is the computer able to access the url? # When it fails
</code></pre>
<p>This matches OP's observation about <code>mcp-proxy.anthropic.com</code> working — the failure is targeted at <code>api.anthropic.com</code> specifically, not Bun networking in general.</p>
<h3>Likely related: stale HTTP/2 connection pool (see #23744)</h3>
<p>The intermittent nature of system Bun failures (1/10) suggests <strong>stale connection pooling</strong>: Bun's HTTP/2 client may be reusing a half-dead socket. Since Claude Code is a long-running process making many sequential API calls, it almost always hits this stale-socket condition, while one-shot Bun invocations from CLI mostly succeed (fresh connection per process).</p>
<p>This aligns with #23744's diagnosis: <em>"the old socket is dead but Claude Code keeps trying to reuse it."</em></p>
<h3>Things that did NOT help</h3>
Attempt | Result
-- | --
sudo networksetup -setv6off Wi-Fi (disable IPv6, per #20240) | No change
/etc/hosts IPv4 override for api.anthropic.com | No change
sudo dscacheutil -flushcache && killall -HUP mDNSResponder | No change
bun upgrade --canary to 1.4.0-canary (system Bun) | System Bun improved to 90% success; Claude Code unchanged (uses bundled Bun)
Killing all Claude / Chrome native host / claude-mem processes | Eliminates a separate ConnectionRefused issue but bundled-Bun ECONNRESET persists
Full clean reinstall via npx claude-mem@latest install, npm uninstall/install, removed ~/.claude/, ~/.claude.json, Keychain credentials | No change
claude -p "hello" (print mode, per #25229) | Also fails with ECONNRESET
<h3>Note on <code>chrome-native-host</code> ghost process</h3>
<p>A separate (likely unrelated) issue I uncovered during diagnosis: when Remote Control is used heavily via the mobile app, <code>Claude.app</code>'s <code>Helpers/chrome-native-host</code> process can be left running indefinitely with a stale socket at <code>/private/tmp/claude-mcp-browser-bridge-<user>/</code>. While this process is alive, Claude Code in the terminal reports <code>ConnectionRefused</code> (not ECONNRESET) — a different error code, but the user-facing symptom (retry loop) looks identical. Killing the orphaned process and removing the socket directory cleared <code>ConnectionRefused</code>, leaving only the underlying ECONNRESET to deal with. Filing separately would clutter this thread, but flagging here in case it correlates.</p>
<h3>Suggested next step for maintainers</h3>
<p>Could you confirm what Bun version is bundled in current Claude Code releases (v2.1.140+)? If it's significantly older than 1.4.x, an upgrade may resolve the intermittent connection pool issue. Alternatively, the underlying HTTP client could be configured to disable HTTP/2 connection reuse for <code>api.anthropic.com</code> as a temporary mitigation — at the cost of some performance, this would sidestep the stale-socket condition entirely.</p>
<p>Happy to capture additional diagnostics (<code>strace</code>/<code>dtrace</code>, <code>tcpdump</code>, debug logs) if specific traces would help.</p></body></html>
I uninstalled the claude-mem and superpower, then the error disappear. I dont know the reason but you could try it.
Is there any solution onto this?
I now solved the issue. There was an environment variable for the Anthropic api key, which was wrong.
/doctorbrought this up.@Ninerian what was the variable? Please share some details about this.
happening with me with subscription, api key won;t work in my case
I had the same error and was able to resolve it this morning, so I wanted to share my scenario in case it helps anyone.
I have been using headroom to help mitigate some of the token costs for Claude Code locally. Headroom encourages you to run a local proxy and point your Anthropic base URL to that proxy (like
.claude/settings.local.json:3: "ANTHROPIC_BASE_URL": "http://127.0.0.1:8787").For myself, I had been running the proxy for a long time and forgot about it. I restarted my computer, which killed the proxy, making my Anthropic base URL pointer invalid. My solution was to just spin up Headroom again. The other solution was to remove the environment variable,
ANTHROPIC_BASE_URL, which would allow for requests to go to the default anthropic base URL.---
A couple of notes on testing/diagnosing..
cd /tpm && claude. If this works, then you know something is wrong with your local workspace environment (<path-to-project>/.claude).claude --debug. This will output the logs to a file, which you can review and diagnose further. When I was troubleshooting, I fed these logs to Claude in the web browser, which helped me understand what was going on