[BUG] Connection Refused error despite successful curl to API endpoint (macOS)
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?
Claude Code fails with Unable to connect to API (ConnectionRefused) on every request, despite the API being reachable via curl. This started suddenly — was working fine yesterday with no network or firewall changes on my end.
Environment Info
Platform: macOS (darwin)
Claude Code Version: 2.1.4
Terminal: default macOS terminal
Installation method: Standalone installer (curl -fsSL https://claude.ai/install.sh | sh)
Plan: Claude Max (Opus 4.5)
Steps to Reproduce
Launch claude
Enter any prompt (e.g., "hello")
Immediately get Unable to connect to API (ConnectionRefused) with retries
What I've Tried
Full uninstall and reinstall (standalone installer)
Removed all config/cache directories (~/.claude, ~/.local/share/claude, ~/.config/claude-code, ~/Library/Application Support/claude, ~/Library/Caches/claude)
claude login (re-authenticated successfully)
Disabled IPv6 (networksetup -setv6off Wi-Fi)
Deactivated Anaconda environment
Cleared proxy/SSL environment variables
Verified firewall is off
Checked for Gatekeeper quarantine (none)
Network Verification
curl works fine:
curl -v https://api.anthropic.com/v1/messages
Returns HTTP/2 405 (expected for GET request), confirming:
DNS resolution works (160.79.104.10)
TLS 1.3 handshake succeeds
API endpoint is reachable
Debug Log
Auth succeeds, but every makeRequest call fails:
2026-01-11T20:34:44.810Z [DEBUG] [API:auth] OAuth token check complete
2026-01-11T20:34:44.953Z [ERROR] Error streaming, falling back to non-streaming mode: Connection error.
2026-01-11T20:35:45.954Z [ERROR] Error: Error: Connection error.
at makeRequest (/$bunfs/root/claude:858:4548)
at processTicksAndRejections (native:7:39)
Full debug log available at ~/.claude/debug/2b5c93af-2f08-4c3b-833c-82676dc9d85f.txt
Notes
This appears to be an issue with Bun's HTTP client specifically, since system-level curl succeeds. Similar to #16331, which was also macOS + ConnectionRefused with working network connectivity.
What Should Happen?
Claude Code should connect to the API and respond to prompts normally. API requests should succeed since the endpoint is reachable (verified via curl).
Error Messages/Logs
Unable to connect to API (ConnectionRefused)
Retrying in 7 seconds… (attempt 5/10)
Debug log excerpt:
2026-01-11T20:34:44.810Z [DEBUG] [API:auth] OAuth token check complete
2026-01-11T20:34:44.953Z [ERROR] Error streaming, falling back to non-streaming mode: Connection error.
2026-01-11T20:35:45.954Z [ERROR] Error: Error: Connection error.
at makeRequest (/$bunfs/root/claude:858:4548)
at processTicksAndRejections (native:7:39)
curl works fine:
$ curl -v https://api.anthropic.com/v1/messages
Returns HTTP/2 405 (expected), TLS 1.3 handshake succeeds, DNS resolves to 160.79.104.10
Tried: full reinstall, cleared ~/.claude + ~/.local/share/claude, re-authenticated, disabled IPv6, deactivated conda, firewall off, no proxy vars set. Auth succeeds but all makeRequest calls fail with Connection error.
Steps to Reproduce
- Install Claude Code via standalone installer:
curl -fsSL https://claude.ai/install.sh | sh - Authenticate with
claude login(succeeds, shows Claude Max subscription) - Run
claude - Enter any prompt (e.g., "hello")
- Error appears: "Unable to connect to API (ConnectionRefused)" with retries up to 10 attempts
Note: This is not file-specific — it fails on any prompt immediately. Network connectivity is confirmed working via curl to the same API endpoint. Issue started suddenly with no system/network changes. Similar to #16331.
Claude Model
Opus
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
2.1.4
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
_No response_
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗