Claude Code “Can't reach the API server”“Connection refused”:网络、代理与 TLS 证书错误(Unable to connect)的原因与解决方法
在公司电脑上或通过 VPN 使用 Claude Code 时,出现 “Can't reach the API server”、“Connection refused”、“SSL certificate verification failed” 或 “fetch failed” 而连不上——这些都是网络错误,意味着请求根本没到达 Anthropic 服务器(api.anthropic.com),与认证(401/403)、服务器过载(529/500)和速率限制(429)不同。v2.1.227 之前,同样的错误显示为 “Unable to connect to API (ECONNREFUSED)”。本文说明现行每条消息的含义、首次设置时以 “Unable to connect to Anthropic services” 退出的情况、代理改动响应时出现的 “Streaming response ended before any complete data was received” 警告,以及代理设置(HTTPS_PROXY、NODE_EXTRA_CA_CERTS、绝不使用 NODE_TLS_REJECT_UNAUTHORIZED=0)、防火墙放行域名与排查工作流——全部基于官方的错误参考。