[BUG] Persistent "Unable to connect to API (ConnectionRefused)" on macOS

Open 💬 0 comments Opened Jul 12, 2026 by HenryQuanNZ

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?

Environment

Platform: macOS
Claude Code Version: 2.1.207 (issue also occurred on the version prior to reinstall)
Plan: Claude Pro
Installation method: Standalone installer (curl -fsSL https://claude.ai/install.sh | sh)
Terminal: Apple Terminal (also tested via Cursor's integrated terminal)

Bug Description

Claude Code fails on every prompt with:

API Error: Unable to connect to API (ConnectionRefused)

This occurs in a retry loop (up to 10 attempts) and then fails entirely, making Claude Code unusable.

Steps Already Taken (all ruled out as causes)

Logged out and re-logged in — issue persisted
Cleared local state and reinstalled (rm -rf ~/.claude && claude) — issue temporarily resolved, then recurred within the same day
Full reinstall via standalone installer — issue persisted
Checked system proxy settings (networksetup -getwebproxy Wi-Fi, networksetup -getsecurewebproxy Wi-Fi) — proxy disabled, confirmed OFF
Checked for VPN/proxy processes (ps aux | grep -i clash/v2ray/surge/shadowrocket/shadowsocks) — no processes found
Checked environment variables (env | grep -i proxy) — no proxy variables set
Checked macOS Application Firewall — temporarily disabled firewall entirely to test — issue persisted
Verified network connectivity directly via curl (IPv6):

curl -6 -v https://api.anthropic.com/v1/messages

Result: TLS handshake succeeded, valid certificate, HTTP/2 405 (Method Not Allowed) returned as expected — confirms network layer is fully functional

  1. Verified network connectivity directly via curl (IPv4):

curl -4 -v https://api.anthropic.com/v1/messages

Result: Same as above — successful TLS handshake and valid HTTP/2 response — confirms network layer is fully functional

  1. Checked Anthropic status page (status.claude.com) — all components (Claude API, Claude Code, claude.ai) reported "Operational" at time of failure

Key Diagnostic Finding

curl reliably connects to api.anthropic.com over both IPv4 and IPv6 with a valid TLS handshake and expected HTTP response, while the Claude Code CLI consistently fails with ConnectionRefused on the same network, same machine, same time. This strongly suggests the issue is isolated to Claude Code's own HTTP client (Bun runtime), not the network, DNS, firewall, or proxy — consistent with other reports (e.g. issues #17541, #56242) describing the same "curl succeeds, Claude Code fails" pattern on macOS.

Impact

Issue is intermittent but recurring — recovers temporarily after clearing ~/.claude and reinstalling, then returns within hours/days
Actively disrupts paid subscription usage (Claude Pro)
Currently attempting to switch from the standalone (Bun-based) installer to the npm-based installation as a workaround

Request

Given the network layer has been exhaustively verified as functional (proxy, VPN, firewall, DNS, TLS, IPv4/IPv6 all ruled out), requesting investigation into why the Claude Code CLI's HTTP client behaves differently from curl on the same machine/network, and whether a fix or more robust retry/fallback logic is planned.

What Should Happen?

work as expected

Error Messages/Logs

Steps to Reproduce

Claude Code fails on every prompt with:

API Error: Unable to connect to API (ConnectionRefused)

This occurs in a retry loop (up to 10 attempts) and then fails entirely, making Claude Code unusable.

Claude Model

None

Is this a regression?

Yes, this worked in a previous version

Last Working Version

_No response_

Claude Code Version

Claude Code v2.1.207

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

_No response_

View original on GitHub ↗