Using Claude Code from China: 5-Minute Setup with CCSub Relay
Step-by-step guide to using Claude Code in China without VPN. Sign up for CCSub, create an API key, and configure environment variables. Works on macOS, Windows, Linux, and the VS Code extension.
Claude Code is Anthropic's official AI coding CLI. The capability is excellent, but direct connections from China are unreliable. Routing through CCSub gives you full Claude Code functionality on Chinese networks with no VPN required. New to the concept? Start with what a Claude API proxy is and why you'd use one.
Why a relay?
Claude Code defaults to api.anthropic.com. From inside China:
- Connections drop or time out frequently
- The official subscription requires a non-Chinese credit card
- Even when you can pay, the FX rate is unfavorable
Routing through CCSub, you get:
- Direct in-China connectivity — no extra latency, no VPN
- ¥1 = $1 USD of API balance — roughly 14% of the official rate
- Full-strength models — Opus 4.6 / Sonnet 4.6 / Haiku 4.5, no quality reductions
Step 1: Sign up for CCSub
Open the CCSub registration page and create an account with your email.
Step 2: Top up your balance
Open "Billing / Subscription" and pay with WeChat Pay, Alipay, or USDT. The minimum top-up is ¥20, and the balance never expires.
Step 3: Create an API key
Open "API Keys" and click "Create Key". The default group is fine; each group's rate and description are shown on the API Keys page.
Copy the sk- prefixed key.
Step 4: Configure Claude Code
macOS / Linux
Open a terminal and run:
export ANTHROPIC_BASE_URL="https://www.ccsub.net"
export ANTHROPIC_AUTH_TOKEN="sk-your-key"
Don't add /v1 or a trailing slash. To persist, append both lines to ~/.zshrc or ~/.bashrc.
For Windows persistence, settings.json precedence, the VS Code extension and error fixes, the Claude Code setup guide is kept up to date with each Claude Code release.
Windows
In CMD (current window only):
set ANTHROPIC_BASE_URL=https://www.ccsub.net
set ANTHROPIC_AUTH_TOKEN=sk-your-key
To make it permanent, write user environment variables from PowerShell; see the Claude Code setup guide.
settings.json
If you would rather not touch system variables, edit ~/.claude/settings.json. It takes precedence over your shell:
{
"env": {
"ANTHROPIC_BASE_URL": "https://www.ccsub.net",
"ANTHROPIC_AUTH_TOKEN": "sk-your-key"
}
}
The VS Code extension checks credentials before it reads this file, so set claudeCode.environmentVariables in your VS Code user settings instead; see the setup guide.
One-click via CC-Switch
Install CC-Switch. Then create a key on the CCSub API Keys page and click "Import CCS" in the "key created" dialog; the relay is configured automatically (the full key is shown only once, in that dialog). To add the provider by hand, see the CC Switch guide. Codex is configured differently; see the Codex CLI guide.
Step 5: Run claude
After configuring, just run claude in your terminal:
claude "write me a React login component"
FAQ
Q: I get 401 Invalid API Key
The key is missing or wrong. See fixing 401 Invalid API Key in Claude Code. If it never connects, see Connection error.
Q: I see "Not logged in"
Add "hasCompletedOnboarding": true to ~/.claude.json, or use CC-Switch to write the config for you.
Q: A single conversation burns through a lot of credit
Long context inflates cost. Use /clear between unrelated tasks to reset the context window.
Q: Which models are supported?
Model IDs are listed on the models page; switch with /model inside Claude Code. A mistyped ID returns 404; see model not found.
Sign up to get started → CCSub
Related setup guides and fixes
- Claude CodeHow to use Claude Code with a custom Anthropic API endpoint
- CC SwitchHow to add CCSub to CC Switch (preset or custom provider)
- Codex CLIHow to use Codex CLI with a custom OpenAI-compatible endpoint
- Error fixFix Claude Code "API Error: 401 Invalid or disabled API key"
- Error fixFix Claude Code "API Error: Connection error" (Unable to connect to API)
- Error fixFix "There's an issue with the selected model" (404 model not found) in Claude Code
Related Posts
Claude API Proxy: The Complete 2026 Guide (What It Is, Why Use One, How to Set It Up)
A Claude API proxy gives you a single Anthropic-compatible endpoint for Claude Code, Cursor, and Codex — with region access, cost control, and automatic failover. This guide explains what a Claude API proxy is, the self-hosted vs managed options, and a 5-minute setup with CCSub.
Graphify for Claude Code: turning a codebase into a knowledge graph with /graphify, and which steps cost tokens
Graphify is an open-source code knowledge graph tool. Type /graphify in Claude Code, Codex, Cursor or another coding agent and it maps the whole project into a graph the agent can query instead of searching file by file. How to install it (the package is graphifyy), the everyday commands, how to make Claude Code check the graph first, whether a third-party API needs extra setup, and which steps spend tokens.
claude-mem for Claude Code: how the new installer works, and the extra step for third-party APIs
claude-mem is an open-source memory plugin for Claude Code that records what each session did and brings it into the next one. How the new installer's memory-provider choice works, how to make it follow a third-party Anthropic-compatible API, how many extra tokens it uses, and the language, privacy and troubleshooting settings worth knowing.