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

ObstacleSymptomSolution
NetworkCannot connect to the Anthropic endpoint; requests time outSet ANTHROPIC_BASE_URL to an endpoint that is directly reachable from China
PaymentBoth the Claude subscription and the Anthropic API require an overseas credit cardUse an API service that accepts payment methods in China and offers a prepaid balance
AccountClaude account registration and region restrictionsUse API key access; no Claude account login is needed

Installation (npm and China Registry)

  1. 1. Install Node.js 22 or higher

    Run node -v to check your version.

  2. 2. (Optional) Switch to a China npm registry

    If npm downloads are slow, you can switch registries first.

    Terminal
    npm config set registry https://registry.npmmirror.com
  3. 3. Install Claude Code

    After a global install, run claude --version to verify.

    Terminal
    npm 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.

~/.claude/settings.json
{
  "env": {
    "ANTHROPIC_AUTH_TOKEN": "你的_API_KEY",
    "ANTHROPIC_API_KEY": "",
    "ANTHROPIC_BASE_URL": "https://api.aicodewith.ai"
  }
}

Claude Code Relay GuideGet API Key

Troubleshooting: When It Doesn't Work

  1. Run /status and confirm the endpoint is api.aicodewith.ai, not the Anthropic default endpoint.
  2. 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.
  3. If the first run is stuck at the login screen: add "hasCompletedOnboarding": true to ~/.claude.json.
  4. Request timeout: temporarily disable your local proxy or VPN and try again. The network in China can connect directly.
  5. If you get 401 / 429 / overloaded: see the error guide.

Claude Code Common Errors and FixesSupported Regions

Plan Comparison (Claude Subscription vs API Relay)

Claude Subscription (Pro / Max)API Relay (AICodeWith)
PaymentOverseas credit card, fixed monthly pricePayment methods in China; prepaid balance, pay-as-you-go
NetworkYou need to handle it yourselfDirectly reachable from China
AccountRequires a Claude accountOnly an API key is needed
Quota5-hour and weekly limitsCharged against your prepaid balance; rate and concurrency limits apply
Best forHeavy daily use with no network or payment issuesChina networks, fluctuating usage, teams managing separate API keys

Claude Code Usage LimitsTop-Up and Plans

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.