claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[BUG]

Open lincbal4 opened this issue 9 months ago • 30 comments

Here's the updated bug report with the Claude CLI version:

Environment

  • Platform (select one):
    • [x] Anthropic API
    • [ ] AWS Bedrock
    • [ ] Google Vertex AI
    • [ ] Other:
  • Claude Code version: 0.2.56
  • Operating System: Windows 11 with Ubuntu WSL
  • Terminal: VS Code with Ubuntu (WSL) terminal

Bug Description

Persistent "API Error: Connection error" when using Claude Code CLI in WSL terminal through VS Code. This issue has recently increased in frequency - previously it occurred rarely or not at all.

Steps to Reproduce

  1. Open VS Code and select Ubuntu (WSL) terminal from dropdown
  2. Run any Claude Code command (e.g., asking a question)
  3. Observe "API Error: Connection error" message
  4. Notice automatic retry attempts also fail with the same error

Expected Behavior

Claude Code should connect to the Anthropic API and process commands successfully.

Actual Behavior

Commands fail with "API Error: Connection error" message, followed by retry attempts that also fail:

⎿  API Error: Connection error.
⎿  API Error (Connection error.) · Retrying in 1 seconds… (attempt 1/10)

Additional Context

  • All required domains (registry.npmjs.org, api.anthropic.com, sentry.io, statsig.anthropic.com, statsig.com) are accessible from WSL as verified by curl tests
  • Network connectivity to all domains confirmed working
  • API key appears to be set (authentication would be a different error message)
  • Issue occurs specifically in VS Code's WSL terminal environment
  • Problem has increased in frequency recently, suggesting a possible change in environment or API behavior

lincbal4 avatar Mar 29 '25 18:03 lincbal4

Additional Context (Update)

After further investigation, I've discovered that the "API Error: Connection error" is being caused by Cloudflare's security measures. A verbose curl test to claude.ai revealed:

HTTP/2 403
cf-mitigated: challenge
server: cloudflare

This shows that Cloudflare is presenting a browser challenge ("Just a moment..." page) instead of allowing direct API access. This explains why Claude Code CLI is unable to complete requests - it doesn't have the capability to solve these Cloudflare challenges like a browser can.

Key observations:

  • The issue is specifically related to how Cloudflare is treating requests from WSL/terminal environments
  • This likely explains why the problem has recently increased in frequency (Cloudflare security policies may have been updated)
  • The curl test successfully connects to the server but receives a 403 Forbidden response with Cloudflare's challenge page
  • All required domains are reachable from my network, confirming this is not a network/firewall issue on my end

This appears to be an issue that would need to be addressed in Claude Code itself, possibly by implementing browser-like headers or other techniques to properly handle Cloudflare challenges.

Is this an issue Claude Code needs to fix on their end?

lincbal4 avatar Mar 29 '25 18:03 lincbal4

Thanks @lincbal4 . I've been experiencing this issue non stop for the last couple of days (0.2.57 (Claude Code), though i think it started a version or 2 before). Mine occurs from any terminal (I run Claude Code almost exclusively from iTerm)

smaccoun avatar Apr 01 '25 16:04 smaccoun

Additional Context (Update)

After further investigation, I've discovered that the "API Error: Connection error" is being caused by Cloudflare's security measures. A verbose curl test to claude.ai revealed:

HTTP/2 403
cf-mitigated: challenge
server: cloudflare

This shows that Cloudflare is presenting a browser challenge ("Just a moment..." page) instead of allowing direct API access. This explains why Claude Code CLI is unable to complete requests - it doesn't have the capability to solve these Cloudflare challenges like a browser can.

Key observations:

  • The issue is specifically related to how Cloudflare is treating requests from WSL/terminal environments
  • This likely explains why the problem has recently increased in frequency (Cloudflare security policies may have been updated)
  • The curl test successfully connects to the server but receives a 403 Forbidden response with Cloudflare's challenge page
  • All required domains are reachable from my network, confirming this is not a network/firewall issue on my end

This appears to be an issue that would need to be addressed in Claude Code itself, possibly by implementing browser-like headers or other techniques to properly handle Cloudflare challenges.

Is this an issue Claude Code needs to fix on their end?

I'm currently experiencing the same thing, Cloudflare's JavaScript challenge is kicking in

DonGuillotine avatar Apr 26 '25 17:04 DonGuillotine

This error started for me this morning and has lasted about 3 hours so far. Is there a resolution yet?

brentwpeterson avatar Apr 30 '25 21:04 brentwpeterson

Same here, same thing - curl -v https://claude.ai gets me a Cloudflare challenge..

DaveKnell avatar May 01 '25 05:05 DaveKnell

Same here if I use mobile hotspot. VPN solved it for me now ¯_(ツ)_/¯

philipkrueger avatar May 04 '25 15:05 philipkrueger

I am having the same issue, curl -v https://claude.ai from WSL results in a challange. This is new behavior over the last week.

BrandonLewis avatar May 05 '25 20:05 BrandonLewis

I seem to be running into this right now as well. Seeing the same "HTTP/2 403". Pretty stuck at this point!

EDIT: I tried turning off the VPN software on my laptop, and that resolved the issue.

btbt avatar May 18 '25 02:05 btbt

I have the same problem, and it seems to have something to do with the limitations or restrictions when we reach the limits of the max plan.

When I start something in a fresh 5h time range, then everything works good. But after some heavy use, I got very often this API error. The only thing which works is to wait for a while (hour or more) and then it works again.

In Claude code, I don't have any warnings about that I reached my limit or the context is low. Everything seems to be fine, but only I get a lot of API errors with up to 10 attempts.

For me, it has nothing to do with a VPN or a bad internet connection.

claude --version 1.0.3 (Claude Code)

Image

udiedrichsen avatar May 24 '25 05:05 udiedrichsen

same here same error how to fix it ?

1.0.6 (Claude Code)

It is unusable. Spend money for that and i cannot use it. Rubbish :(

michalss avatar Jun 01 '25 18:06 michalss

I have the same error, though am interested to hear whether anyone else was able to resolve by switching from the api to the max plan looking at the comment from @udiedrichsen I'm on the api at the moment, but would consider the max plan if it would resolve..

rfow avatar Jun 02 '25 14:06 rfow

I have the same error, though am interested to hear whether anyone else was able to resolve by switching from the api to the max plan looking at the comment from @udiedrichsen I'm on the api at the moment, but would consider the max plan if it would resolve..

I am on the Max plan, and it happens mostly for me when I reach my limit (besides this plan).

udiedrichsen avatar Jun 02 '25 17:06 udiedrichsen

Yes exactly @udiedrichsen - I think once you reach the limit it might switch over to the api (as per https://support.anthropic.com/en/articles/11145838-using-claude-code-with-your-max-plan) and that's why you dont see it typically. Perhaps I'm just hoping! Would be interested to see whether anyone else sees the same on the max plan or whether this is limited to when cc is using the api.

rfow avatar Jun 03 '25 05:06 rfow

Yes exactly @udiedrichsen - I think once you reach the limit it might switch over to the api (as per https://support.anthropic.com/en/articles/11145838-using-claude-code-with-your-max-plan) and that's why you dont see it typically. Perhaps I'm just hoping! Would be interested to see whether anyone else sees the same on the max plan or whether this is limited to when cc is using the api.

Yes, and I'm on the big Max plan, and it's pretty hard to reach it, so it's not a big deal from my point of view. If you switch to Sonnet you avoid this problem.

udiedrichsen avatar Jun 03 '25 05:06 udiedrichsen

I'm on 20x Max and have been encountering this issue intermittently for the past 36-ish hours. Model selection auto and Sonnet both run into this. I've attempted to reproduce with the curl command as stated above, but have been unsuccessful. The true sporadic nature of this leads me to believe this is on the Anthropic side.

MPIsaac-Syn avatar Jun 03 '25 12:06 MPIsaac-Syn

Claude max user here and this is very, very annoying.

digitalflexibilit avatar Jun 06 '25 16:06 digitalflexibilit

I was excited to try Claude Code and even invested in the API, but unfortunately I haven’t been able to get it working due to this very error. I went as far as setting up a MITM proxy to diagnose the issue (since the default Claude Code logs are not very helpful), and that's how I discovered that I am consistently hitting a 403 wall with Cloudflare.

It appears this may be caused by a misconfiguration — Cloudflare’s API Shield is designed specifically to prevent browser-based challenges for API endpoints. I would strongly encourage the team to look into this, as it seems like a straightforward fix.

It’s disappointing to see such a basic issue affect paying customers for months without resolution. This has made my first experience with Anthropic quite negative. I was thinking about investing into Max, but the very thought that anytime I can be left without access and my hundred bucks as well scares me.

vnetserg avatar Jun 07 '25 17:06 vnetserg

I have the same issue with WSL, I found the cause it's because of Comodo firewall blocking DNS and ARP for WSL. As soon as I disable the firewall entirely, Claude Code works just fine and there is no more API Error.

Edit: The rules are to be added in application for Windows Operating System, add and allow all IP Claude Code is trying to connect on port 443

Vani010 avatar Jun 08 '25 18:06 Vani010

I'm encountering the same "API Error (Connection error.)" issue. In my case, it only happens when Claude Code attempts to generate or edit a longer piece of code using the "Write", "Edit", or "MultiEdit" tools. This has unfortunately made Claude Code nearly unusable for me.

GeorgeMLP avatar Jun 14 '25 22:06 GeorgeMLP

This is pretty terrible UX. This should at least tell us what is going on, rather than just erroring, even if it is just the usage limit kicking in.

Sothatsit avatar Jun 16 '25 01:06 Sothatsit

Same issue in mac with claude pro plan. I noticed that it sometimes works when I stop docker. Is there a solution for this?

jishnu-mohan avatar Jun 18 '25 10:06 jishnu-mohan

After testing for hours, just confirmed that the same problem caused by the Cloudflare Shield when connecting to "console.anthropic.com" [Claude Code version 1.0.30]. Seems no solution right now. Why this happens when the CLI tools produced by Anthropics itself using it's own API. Seems unreasonable. (Well, claude.ai agrees with me when I try to investigated what's going on)

Image

edcth avatar Jun 19 '25 18:06 edcth

Having the same issue

Kaloszer avatar Jun 23 '25 08:06 Kaloszer

I have the same issue, but it seems after removing references to larger files in my CLAUDE.md file, the issue happens only sporadic, wehereas before the API Error occured often.

rogeru avatar Jun 23 '25 18:06 rogeru

Image same issue here, just bought subscription a day ago. can we do something about this already?

Amirulmuuminin avatar Jun 29 '25 01:06 Amirulmuuminin

Is the Cloudflare Shield issue expected? Why has there been no response for so long? It seems to me that this is a problem the official team can easily solve. Also, I found that this issue only occurs on the console, not the API. Once I successfully log in, Cloudflare Shield never triggers again, which indicates that the problem is specific to the console domain.

SamPeng87 avatar Jun 30 '25 04:06 SamPeng87

Is the Cloudflare Shield issue expected? Why has there been no response for so long? It seems to me that this is a problem the official team can easily solve. Also, I found that this issue only occurs on the console, not the API. Once I successfully log in, Cloudflare Shield never triggers again, which indicates that the problem is specific to the console domain.

i resolve this issue by reinstalling docker desktop, in my case the error is not caused by the claude team, its something related to docker networking. at first, i try to uninstall docker and all related to it but it fail. then i installed docker again and it worked.

im using wsl in windows and if you can't run sudo apt update in your terminal, than it's related to your network not claude error. try reinstall docker if that's the case

Amirulmuuminin avatar Jun 30 '25 12:06 Amirulmuuminin

Is the Cloudflare Shield issue expected? Why has there been no response for so long? It seems to me that this is a problem the official team can easily solve. Also, I found that this issue only occurs on the console, not the API. Once I successfully log in, Cloudflare Shield never triggers again, which indicates that the problem is specific to the console domain.

I resolved this issue by reinstalling Docker Desktop. In my case, the error was not caused by the Claude team; it was something related to Docker networking. At first, I tried to uninstall Docker and everything related to it, but it failed. Then I installed Docker again, and it worked.

I'm using WSL on Windows, and if you can't run sudo apt update in your terminal, then it's related to your network, not a Claude error. Try reinstalling Docker if that's the case.

Hi, thanks for your solution, but that's not my case. I am using macOS.

SamPeng87 avatar Jun 30 '25 13:06 SamPeng87

https://github.com/anthropics/claude-code/issues/653#issuecomment-3018929302

Just reinstalling docker desktop fixed my issue, thank you :)

jishnu-mohan avatar Jun 30 '25 14:06 jishnu-mohan

Is the Cloudflare Shield issue expected? Why has there been no response for so long? It seems to me that this is a problem the official team can easily solve. Also, I found that this issue only occurs on the console, not the API. Once I successfully log in, Cloudflare Shield never triggers again, which indicates that the problem is specific to the console domain.

I resolved this issue by reinstalling Docker Desktop. In my case, the error was not caused by the Claude team; it was something related to Docker networking. At first, I tried to uninstall Docker and everything related to it, but it failed. Then I installed Docker again, and it worked. I'm using WSL on Windows, and if you can't run sudo apt update in your terminal, then it's related to your network, not a Claude error. Try reinstalling Docker if that's the case.

Hi, thanks for your solution, but that's not my case. I am using macOS.

If you have docker desktop installed, it may be running in background even if you quit it

Run this in terminal: killall "Docker Desktop"

And then try claude code, if that works.. then just reinstall your docker desktop.. hope it helps

jishnu-mohan avatar Jun 30 '25 14:06 jishnu-mohan