[BUG] ConnectionRefused on /v1/messages streaming while simple API requests succeed (Windows, Bun)
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?
<html>
<body>
<!--StartFragment--><h2 class="text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold" data-sourcepos="13:1-13:20;362-381">Environment Info</h2>
<ul class="[li_&]:mb-0 [li_&]:mt-1 [li_&]:gap-1 [&:not(:last-child)_ul]:pb-1 [&:not(:last-child)_ol]:pb-1 list-disc flex flex-col gap-1 pl-8 mb-3" data-sourcepos="14:1-18:73;382-599">
<li class="font-claude-response-body whitespace-normal break-words pl-2" data-sourcepos="14:1-14:33;382-414"><strong>Platform:</strong> Windows 11 (x64)</li>
<li class="font-claude-response-body whitespace-normal break-words pl-2" data-sourcepos="15:1-15:57;415-471"><strong>Terminal:</strong> PowerShell / VS Code integrated terminal</li>
<li class="font-claude-response-body whitespace-normal break-words pl-2" data-sourcepos="16:1-16:23;472-494"><strong>Version:</strong> 2.1.207</li>
<li class="font-claude-response-body whitespace-normal break-words pl-2" data-sourcepos="17:1-17:32;495-526"><strong>ISP:</strong> ACT Fibernet (India)</li>
<li class="font-claude-response-body whitespace-normal break-words pl-2" data-sourcepos="18:1-18:73;527-599"><strong>Install method:</strong> Both native installer and npm global — same result</li>
</ul>
<h2 class="text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold" data-sourcepos="20:1-20:16;601-616">What's Wrong</h2>
<p class="font-claude-response-body break-words whitespace-normal" data-sourcepos="22:1-22:115;618-732">Claude Code fails with <code class="bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]">Unable to connect to API (ConnectionRefused)</code> on every prompt. All 11 retry attempts fail.</p>
<p class="font-claude-response-body break-words whitespace-normal" data-sourcepos="24:1-24:183;734-916"><strong>Critical finding from debug logs:</strong> Simple GET requests to <code class="bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]">api.anthropic.com</code> <strong>succeed</strong> during the same session, while streaming POST requests to <code class="bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]">/v1/messages</code> <strong>always fail</strong>.</p>
<p class="font-claude-response-body break-words whitespace-normal" data-sourcepos="26:1-26:38;918-955">From <code class="bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]">~/.claude/debug/<session>.txt</code>:</p>
<div role="group" aria-label="Code" tabindex="0" data-sourcepos="28:1-33:4;957-1379" class="relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100"><div class="sticky opacity-0 group-hover/copy:opacity-100 group-focus-within/copy:opacity-100 top-2 py-2 h-12 w-0 float-right"><div class="absolute right-0 h-8 px-2 items-center inline-flex z-10"></div></div><div class="overflow-x-auto"><pre class="code-block__code !my-0 !rounded-lg !text-sm !leading-relaxed p-3.5" style="color: rgb(234, 236, 240); background: transparent; font-family: var(--font-mono);"><code style="color: rgb(234, 236, 240); background: transparent; font-family: var(--font-mono); white-space: pre-wrap;"><span><span>2026-07-12T01:09:17.976Z [DEBUG] [claudeai-mcp] Fetching from https://api.anthropic.com/v1/mcp_servers → SUCCESS (fetched 1 server)
</span></span><span>2026-07-12T01:09:18.224Z [DEBUG] [Bootstrap] Fetch ok → SUCCESS
</span><span>2026-07-12T01:09:31.658Z [ERROR] API error (attempt 1/11): undefined Connection error. ← /v1/messages FAILS
</span><span>2026-07-12T01:12:23.633Z [ERROR] Connection error details: code=ConnectionRefused, message=Unable to connect.</span></code></pre></div></div>
<p class="font-claude-response-body break-words whitespace-normal" data-sourcepos="35:1-35:159;1381-1539">This proves the network path to <code class="bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]">api.anthropic.com</code> is healthy. The failure is specific to the streaming <code class="bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]">/v1/messages</code> endpoint, likely in Bun's HTTP client.</p>
Network Diagnostics (all pass)
| Test | Result |
|------|--------|
| nslookup api.anthropic.com | Resolves to 160.79.104.10 (IPv4) + 2607:6bc0::10 (IPv6) |
| Test-NetConnection api.anthropic.com -Port 443 | TcpTestSucceeded: True |
| node -e "https.get('https://api.anthropic.com', ...)" | Status: 404 ✅ |
| curl https://api.anthropic.com/v1/messages | 405 Method Not Allowed ✅ (API responded) |
| Windows Firewall | 3 outbound Allow rules for Claude |
| Cloudflare WARP | Same failure with WARP enabled |
Actual Behavior
Every /v1/messages request fails with ConnectionRefused while other API requests (MCP server fetch, bootstrap) in the same session succeed.
What I've Tried (all failed)
Cleared ~/.claude and re-authenticated with claude login
Reinstalled via native installer (irm https://claude.ai/install.ps1 | iex)
Reinstalled via npm (npm install -g @anthropic-ai/claude-code@latest)
Disabled IPv6 on network adapter
Added hosts file entry forcing IPv4
Enabled Cloudflare WARP (1.1.1.1)
Tried WSL2 (Ubuntu) — same failure
Killed all Claude processes to eliminate lock contention
Disabled Windows Defender real-time protection
Unset all proxy env vars (HTTPS_PROXY, HTTP_PROXY, ALL_PROXY)
Removed stale native binary at ~/.local/bin/claude.exe
What Should Happen?
Claude code CLI should be able to connect with anthropic APIs
Error Messages/Logs
2026-07-12T01:09:17.976Z [DEBUG] [claudeai-mcp] Fetching from https://api.anthropic.com/v1/mcp_servers → SUCCESS (fetched 1 server)
2026-07-12T01:09:18.224Z [DEBUG] [Bootstrap] Fetch ok → SUCCESS
2026-07-12T01:09:31.658Z [ERROR] API error (attempt 1/11): undefined Connection error. ← /v1/messages FAILS
2026-07-12T01:12:23.633Z [ERROR] Connection error details: code=ConnectionRefused, message=Unable to connect.
Steps to Reproduce
Steps to Reproduce
- Install Claude Code on Windows 11 (native installer or npm)
- Run claude in PowerShell or VS Code terminal
- Type any prompt
- Observe: Unable to connect to API (ConnectionRefused) with retry loop
- Check debug log at ~/.claude/debug/ — simple GETs succeed, streaming POSTs fail
Claude Model
Not sure / Multiple models
Is this a regression?
Yes, this worked in a previous version
Last Working Version
not sure
Claude Code Version
2.1.207 (Claude Code)
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
PowerShell
Additional Information
<img width="1204" height="499" alt="Image" src="https://github.com/user-attachments/assets/d132dda6-5ae0-49fa-9dbc-7fbfb2a4c327" />
Additional Context
- Claude Desktop app Code tab sometimes works (uses Electron/Chromium networking) but also crashes with "bridged Claude Code process stopped responding" since it spawns the same Bun CLI underneath.
- The issue is intermittent — npm install worked initially, then stopped.
- Debug log also shows: Lock acquisition took longer than expected and install check: claude command at C:\Users\tushar\.local\bin\claude.exe missing or broken.
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗