Claude Code in Mainland China
Run Claude Code without a VPN in China by pointing it at DeepSeek's Anthropic-compatible endpoint.
Trade-off
You'll be running DeepSeek models, not real Claude — comparable coding ability but not identical to Opus/Sonnet. This method is documented by DeepSeek; Anthropic neither supports nor blocks it.
Why this works
Claude Code defaults to api.anthropic.com, which is unreachable from mainland China. DeepSeek exposes an Anthropic-compatible endpoint (api.deepseek.com/anthropic) accessible inside China. Swap the base URL and you're done.
Step 1 — Install Node & Claude Code
# Install Node via Homebrew
brew install node
# Switch npm to a China mirror (avoids timeouts)
npm config set registry https://registry.npmmirror.com
# Install Claude Code
npm install -g @anthropic-ai/claude-codeTIP
Do not use the curl … claude.ai/install.sh script — claude.ai is blocked. The npm route works reliably.
Step 2 — Get a DeepSeek API Key
- Go to platform.deepseek.com, register and log in.
- Add credit (pay-as-you-go, inexpensive).
- Create a key on the API Keys page — it looks like
sk-xxxxxxxx.
Step 3 — Configure environment variables
Append the block below to ~/.zshrc, replacing the placeholder with your key:
# Claude Code → DeepSeek V4 (mainland China, no VPN)
export ANTHROPIC_BASE_URL="https://api.deepseek.com/anthropic"
export ANTHROPIC_AUTH_TOKEN="sk-your-deepseek-key"
export ANTHROPIC_MODEL="deepseek-v4-pro" # main model (opus tier)
export ANTHROPIC_SMALL_FAST_MODEL="deepseek-v4-flash" # background tasks (haiku tier)Then reload:
source ~/.zshrcStep 4 — Run
cd your-project
claudeClaude Code will skip Anthropic's OAuth and connect to the DeepSeek endpoint directly.
Troubleshooting
| Issue | Fix |
|---|---|
| Changes ignored | Run source ~/.zshrc or open a new terminal after every edit |
| Verify setup | echo $ANTHROPIC_BASE_URL should print the DeepSeek URL |
| Back to real Claude | Comment out the four export lines and reload (VPN + Anthropic account still required) |
Model aliases
Use deepseek-v4-pro / deepseek-v4-flash. The legacy aliases deepseek-chat and deepseek-reasoner retire after 2026-07-24.
Alternative endpoints
| Provider | ANTHROPIC_BASE_URL |
|---|---|
| DeepSeek | https://api.deepseek.com/anthropic |
| Zhipu GLM | https://open.bigmodel.cn/api/anthropic |
| Moonshot Kimi | https://api.moonshot.cn/anthropic |

