Claude Code · In China
How to Use Claude Code in China
Using Claude Code in China, the difficulty is not installation but network, payment, and accounts. This page explains, in order: how to install it, how to connect to an API that is directly reachable from China, how to troubleshoot when it's installed but won't work, and how to choose between a Claude subscription (Pro / Max) and an API relay.
Last checked
3 Obstacles to Using Claude Code in China
| Obstacle | Symptom | Solution |
|---|---|---|
| Network | Cannot connect to the Anthropic endpoint; requests time out | Set ANTHROPIC_BASE_URL to an endpoint that is directly reachable from China |
| Payment | Both the Claude subscription and the Anthropic API require an overseas credit card | Use an API service that accepts payment methods in China and offers a prepaid balance |
| Account | Claude account registration and region restrictions | Use API key access; no Claude account login is needed |
Installation (npm and China Registry)
1. Install Node.js 22 or higher
Run node -v to check your version.
2. (Optional) Switch to a China npm registry
If npm downloads are slow, you can switch registries first.
Terminalnpm config set registry https://registry.npmmirror.com3. Install Claude Code
After a global install, run claude --version to verify.
Terminalnpm install -g @anthropic-ai/claude-code
If you see command not found, the npm global directory is most likely not in your PATH. Run npm config get prefix, add the bin directory under the printed path to your PATH, then reopen your terminal.
Connect to an API Available in China
Create an API key in the AICodeWith console, then add it to ~/.claude/settings.json. Reopen your terminal, run claude, and type /status to confirm the API endpoint is api.aicodewith.ai.
{
"env": {
"ANTHROPIC_AUTH_TOKEN": "你的_API_KEY",
"ANTHROPIC_API_KEY": "",
"ANTHROPIC_BASE_URL": "https://api.aicodewith.ai"
}
}Troubleshooting: When It Doesn't Work
- Run /status and confirm the endpoint is api.aicodewith.ai, not the Anthropic default endpoint.
- In a new terminal, run echo $ANTHROPIC_API_KEY. If there is an old value, remove it from ~/.zshrc or ~/.bashrc; ANTHROPIC_API_KEY should be left empty.
- If the first run is stuck at the login screen: add "hasCompletedOnboarding": true to ~/.claude.json.
- Request timeout: temporarily disable your local proxy or VPN and try again. The network in China can connect directly.
- If you get 401 / 429 / overloaded: see the error guide.
Plan Comparison (Claude Subscription vs API Relay)
| Claude Subscription (Pro / Max) | API Relay (AICodeWith) | |
|---|---|---|
| Payment | Overseas credit card, fixed monthly price | Payment methods in China; prepaid balance, pay-as-you-go |
| Network | You need to handle it yourself | Directly reachable from China |
| Account | Requires a Claude account | Only an API key is needed |
| Quota | 5-hour and weekly limits | Charged against your prepaid balance; rate and concurrency limits apply |
| Best for | Heavy daily use with no network or payment issues | China networks, fluctuating usage, teams managing separate API keys |
FAQ
Can Claude Code be used directly in China?
Yes. Installation itself has no restrictions. Once you switch the endpoint to an API that is directly reachable from China (for example, api.aicodewith.ai), you can use it directly.
Do I need a proxy?
No proxy is needed after connecting to AICodeWith. If a local proxy is running and requests time out, turn it off and try again.
What if I don't have an overseas credit card?
AICodeWith accepts payment methods in China for top-ups. The prepaid balance is charged per use, remains valid for 12 months, and is not reset monthly.
What should I do if installation fails or I get command not found?
First make sure your Node.js version is 22 or higher. If npm downloads are slow, switch to a China registry. command not found means the npm global bin directory is not in your PATH; add it, then reopen your terminal.
Ready to try it?
Billing is per token from a prepaid balance. Rate and concurrency limits apply, and you can set daily, monthly or total spend caps on each API key.
Related
AICodeWith is an independent third-party API service with no affiliation to Anthropic or OpenAI. Claude, Claude Code, Codex, and other names belong to their respective owners. Prices are based on real-time data on the model page; rate and concurrency limits apply; refunds are subject to a 10% handling fee. See the refund policy for details.