[BUG] VS Code extension: /v1/messages fails with ConnectionRefused while other API calls in the same process succeed

Status Open
Reported on v2.1.217
Maintainer reply None cached
Activity 1 comment · opened Jul 22, 2026

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?

The Claude Code VS Code extension consistently fails to send chat messages, showing "API Error: Unable to connect to API (ConnectionRefused)". This happens specifically on the /v1/messages endpoint (the actual chat completion call), while other Anthropic API calls succeed in the same process and session — including GET https://api.anthropic.com/v1/mcp_servers (succeeds, "Fetched 2 servers") and MCP proxy connections to mcp-proxy.anthropic.com for Gmail/Google Calendar connectors (connect successfully). Only /v1/messages (source=generate_session_title and source=sdk) fails, retried 11 times, always ConnectionRefused.

What Should Happen?

Chat messages sent through the VS Code extension should reach the API and return a response, the same way they do when running the identical claude.exe binary from a standalone terminal.

Error Messages/Logs

2026-07-22T02:43:45.461Z [ERROR] API error (attempt 1/11): undefined Connection error.
...
2026-07-22T02:46:43.459Z [ERROR] Connection error details: code=ConnectionRefused, message=Unable to connect. Is the computer able to access the url?
2026-07-22T02:46:43.459Z [ERROR] API connection_error after retries: Connection error.

Preceding sequence logged on every launch, right before the failing requests:
CA certs: Config fallback - globalEnv keys: , settingsEnv keys: none
[init] configureGlobalMTLS starting
[init] configureGlobalMTLS complete
[init] configureGlobalAgents starting
CA certs: stores=bundled,system, extraCertsPath=undefined
CA certs: Loaded 120 bundled root certificates
CA certs: Dropped 11 expired certificate(s) from system store
CA certs: Loaded 70 system CA certificates
mTLS: Creating HTTPS agent with custom certificates
[init] configureGlobalAgents complete

Steps to Reproduce

  1. Install Claude Code VS Code extension (anthropic.claude-code) on Windows 11, v2.1.217.
  2. Sign in normally.
  3. Open the Claude Code panel, start a session, send any message (e.g. "where are we?").
  4. Observe "API Error: Unable to connect to API (ConnectionRefused)" after retries.

Confirmed NOT caused by the local environment:

  • ping api.anthropic.com -t: 70/70 received, 0% loss, 16-55ms latency.
  • Invoke-WebRequest POST to https://api.anthropic.com/v1/messages (fake API key) returns a proper 401 Unauthorized — proving HTTPS connectivity to this exact endpoint works.
  • Ruled out: Windows Defender Firewall (app allowed, Private+Public), third-party antivirus (none installed), system/VS Code proxy settings (both empty), stale claude.exe processes (killed via taskkill, issue persisted), PATH misconfiguration (fixed, issue persisted), a broken custom MCP server entry in .claude.json (removed, issue persisted), full extension uninstall/reinstall + re-auth, full router + PC restart.
  • The identical binary (...\anthropic.claude-code-2.1.217-win32-x64\resources\native-binary\claude.exe) succeeded twice when run directly from a standalone PowerShell window, but failed consistently both in the VS Code sidebar panel and in VS Code's integrated terminal — suggesting intermittent rather than fully deterministic failure.

Claude Model

Sonnet (default)

Is this a regression?

Yes, this worked in a previous version

Last Working Version

No

Claude Code Version

2.1.217

Platform

Claude Pro Subscription

Operating System

Windows

Terminal/Shell

VS CODE, Windows Teminal

Additional Information

This exact symptom (VS Code extension fails to reach the API while terminal claude works fine) has been reported multiple times before, but prior reports were closed as stale/duplicate without an actual fix landing:

  • #17709 (macOS, zero API requests ever sent — closed as not planned, no fix)
  • #51732 (Windows 11, "Query closed before response received" — closed as duplicate of #49522)
  • Referenced from that thread: #49522, #50616, #55562 — same Windows pattern, recurring since April 2026

This report includes additional diagnostic depth not present in those threads: confirmation via raw HTTPS request that the endpoint itself is reachable (401 response), confirmation that other Anthropic API calls succeed in the same failing process, and a full list of locally-ruled-out causes (firewall, antivirus, proxy, DNS, router). Given the repeat pattern across many users and versions with the closing reason always being staleness rather than resolution, this appears to be a persistent unaddressed bug in how the extension establishes its connection for the actual message-send call, most likely related to the custom mTLS/HTTPS agent initialization visible in the logs.

Two potential duplicates were flagged when filing (#17709, #51732), both locked/closed without resolution — referenced above rather than commented on directly.

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗