claude-code
claude-code copied to clipboard
[BUG] API Error (Request timed out) in Remote SSH Dev Container on Linux Host
Environment
- Platform (select one):
- [x] Anthropic API
- [ ] AWS Bedrock
- [ ] Google Vertex AI
- [ ] Other:
- Claude CLI version: 1.0.17 (Claude Code)
- Operating System: Ubuntu 24.04
- Terminal: Wezterm
Bug Description
The Claude CLI consistently fails with API Error (Request timed out.) when used inside a dev container hosted on a remote Linux machine (Ubuntu 24.04). The connection is established via the VS Code Remote-SSH extension. The issue appears after one or two successful API calls, making the CLI unusable for subsequent requests. This behavior is specific to the remote Linux environment and is not reproducible when the same dev container is run locally on Docker Desktop for macOS.
Steps to Reproduce
- On a local machine, use VS Code with the Remote-SSH extension to connect to a Linux host (Ubuntu 24.04).
- On the Linux host, clone the repository:
git clone https://github.com/kenfdev/study-claude-code.git - In VS Code, open the cloned folder using the "Open Folder in Container" command, which utilizes the
.devcontainerconfiguration in the repository. - Once the dev container is built and running, open a terminal and start with
claude --dangerously-skip-permissions - Give Claude Code instructions and start a task
Expected Behavior
Claude Code should execute successfully and return responses from the API
Actual Behavior
The first one or two tasks succeed. However, subsequent commands fail, displaying the following error message and retry attempts:
API Error (Request timed out.) · Retrying in 1 seconds… (attempt 1/10)
The command ultimately fails after all retry attempts are exhausted.
Additional Context
Troubleshooting Information:
- Host Environment: The remote host is running Ubuntu 24.04.
- Firewall & Proxy: I have confirmed that the Linux host is not running a local firewall (
ufwis inactive) and is not configured to use a proxy. - Local Mac Comparison: The issue is not reproducible when running the exact same dev container configuration on Docker Desktop for Mac. All commands succeed without timeouts.
- Debug Logs: Running with
ANTHROPIC_LOG=debug DEBUG=1shows the request being sent but provides no specific error before the timeout.
Log Snippet of a Failing Request(I don't think this information is useful though):
JSON
[log_1a57d1] sending request {
"method": "post",
"url": "https://api.anthropic.com/v1/messages?beta=true",
"options": {
"method": "post",
"path": "/v1/messages?beta=true",
"body": {
"model": "claude-sonnet-4-20250514",
"messages": "[Array]",
"temperature": 1,
"system": "[Array]",
"tools": "[Array]",
"tool_choice": null,
"metadata": "[Object]",
"max_tokens": 21333,
"thinking": "[Object]"
},
"timeout": 60000,
"stream": false
},
"headers": {
"accept": "application/json",
"anthropic-beta": "claude-code-20250219,oauth-2025-04-20,interleaved-thinking-2025-05-14",
"anthropic-dangerous-direct-browser-access": "true",
"anthropic-version": "2023-06-01",
"authorization": "***",
"content-type": "application/json",
"user-agent": "claude-cli/1.0.17 (external, cli)",
"x-app": "cli",
"x-stainless-arch": "x64"
}
}
Perhaps the following Issue may be related, but not completely https://github.com/anthropics/claude-code/issues/1536
FYI, I'm seeing more or less the same thing, with some differences:
- I'm using a docker container on a remote host; I am not using VSCode.
- I am using a claude max account, create a week ago, almost completely unused
- Claude code answers about one to three requests, such as "are you there?" and then times out when I ask "are you online"
- Checking account usage with
curl -X POST https://api.anthropic.com/v1/messages ... etc.gives{"type":"error","error":{"type":"invalid_request_error","message":"Your credit balance is too low to access the Anthropic API. Please go to Plans & Billing to upgrade or purchase credits."}}... which is unexpected since this is a brand-new, unused max account.
However, the API key I used for curl -x POST might not be the same one that claude code is using. I'm somewhat confused about which keys get used for what. The initialization of claude code is automatic; I assume it uses the same keys as before, but maybe not. The authorization process does not indicate what keys are getting employed.
Having the same issue, with just an SSH connection to my linux. I tried multiple variantions of authentication (Pro account, API-based), and it still has the same issue.
I encountered the same issue when using a VSCode Devcontainer and was able to resolve it.
The root cause of this error is that the system tries to prioritize connecting to the API using an IPv6 address (AAAA record), even though IPv6 is actually unavailable.
For Docker, you’ll need to disable IPv6 according to the method appropriate for each distro.
For Devcontainers, try adding the following settings to your .devcontainer/devcontainer.json file:
"runArgs": [
"--sysctl", "net.ipv6.conf.all.disable_ipv6=1",
"--sysctl", "net.ipv6.conf.default.disable_ipv6=1"
],
Hope this helps!
@masuidrive Thank you! Your solution works for me on WSL2 with Ubuntu 24.04.
I disabled IPv6 by adding the following settings to /etc/sysctl.d/99-sysctl.conf and running sysctl -p.
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
The ipv6 suggestion fixes nothing at all, for me. Even stopping all containers, upgrading to today's current version 1.0.40 it still times out. FYI, the settings can be double-checked with
cat /proc/sys/net/ipv6/conf/all/disable_ipv6
cat /proc/sys/net/ipv6/conf/<your container net device>/disable_ipv6
and you can even toggle at runtime:
echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6
echo 0 > ...
What does fix it for me is to go through TOR, as described in #1536 and others reported that using a VPN also works.
Same here. Disabling ipv6 didn't change anything for my environment. Thanks for the advice though @masuidrive :)
@linas I've read your comment about TOR, but since I'm heavily using MCP, I really wish this problem gets solved in a more fundamental way...
For now, I've switched to remote SSH devcontainers with WSL. Everything's working perfectly.
I am simply accessing my linux over SSH using the WSL Ubuntu shell, no VSCode.
Disabling ipv6 fixed it as suggested above fixed it
This can't be that complicated of an issue to fix, cmon guys...
ipv6 doesn't fix thi issue
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.