Claude Code
Claude Code is Anthropic's official AI coding terminal tool for interactive programming directly from the command line. Its standout feature is deep integration with git / the file system / the shell, enabling autonomous multi-step execution (analyze requirements → write code → run tests → fix bugs). Official VS Code / JetBrains plugins are also available.
Who it's for: developers who prefer terminal-based workflows; anyone doing agentic coding tasks (not just plain Q&A); those who manage code with git and want the AI to commit on its own.
This tutorial: point Claude Code at the claude-api.org relay to enjoy the native Claude 4.7 series experience without an Anthropic subscription.
Anthropic's official terminal / IDE plugin. Use it with the Claude Official (Claude Code only) Channel to call native Claude models directly.
Recommended Channel
Claude Official (Claude Code only) (1.4x) — high-quality upstream with the best stability, optimized exclusively for the Claude Code CLI, and only accepts the official claude-cli/X.Y.Z client.
To call Claude from other clients such as Cline / Cursor / opencode, please choose
Claude Official (any client)(2.0x) orBudget Claude(0.5x, with relatively less stable quality).
Installation
Requires Node.js 18+.
npm install -g @anthropic-ai/claude-codeVS Code / JetBrains users can also install the official IDE extension; the configuration is the same.
Configuration
Option 1: Environment variables (recommended)
# 加到 ~/.zshrc 或 ~/.bashrc
export ANTHROPIC_BASE_URL="https://claude-api.org"
export ANTHROPIC_AUTH_TOKEN="sk-你的key"
export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC="1" # 可选:禁用遥测/网搜# 加到 $PROFILE
$env:ANTHROPIC_BASE_URL = "https://claude-api.org"
$env:ANTHROPIC_AUTH_TOKEN = "sk-你的key"
$env:CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC = "1"ANTHROPIC_BASE_URL="https://claude-api.org" \
ANTHROPIC_AUTH_TOKEN="sk-你的key" \
claudeOption 2: Write to ~/.claude/settings.json
{
"env": {
"ANTHROPIC_BASE_URL": "https://claude-api.org/",
"ANTHROPIC_AUTH_TOKEN": "sk-你的key",
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
}
}Don't commit settings.json
The ANTHROPIC_AUTH_TOKEN inside it is the access credential to your Balance — if leaked, others can drain your wallet. Be sure to exclude this file with .gitignore.
Verification
claudeOnce you've entered Claude Code's interactive mode, send a Hello. If you get a normal reply back, you're all set.
You can also verify with curl:
curl -sS https://claude-api.org/v1/messages \
-H "x-api-key: sk-你的key" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "claude-sonnet-4-6",
"max_tokens": 32,
"messages": [{"role": "user", "content": "ping"}]
}'Advanced
One-click install script
Paste this into your terminal:
curl -fsSL https://claude-api.org/install.sh | bash -s -- "sk-你的key"The script automatically writes the environment variables into your shell rc file; just reopen your terminal.
Model selection
Add --model at startup:
claude --model claude-opus-4-7 # 旗舰,慢但强
claude --model claude-sonnet-4-6 # 主力,平衡(推荐)
claude --model claude-haiku-4-5-20251001 # 便宜快You can also switch with /model during an interactive session.
Context window
Opus 4.7 / Sonnet 4.6 default to a 200K context; adding --model claude-opus-4-7[1m] at startup expands it to 1M (priced at a 2x surcharge on input tokens).
FAQ
401 Unauthorized
- The Key picked up an extra space when copied → recopy and paste it
- The Key was deleted / regenerated by you → go to the dashboard → API Keys and create it again
- The Key is bound to an OpenAI-platform Channel → for Claude Code it must be the
Claude Official (Claude Code only)orClaude Sonnet DiscountChannel
429 Rate Limit
The system is throttling to protect itself. What to do:
- Wait 1–2 minutes for it to recover automatically
- Triggering it frequently → spread out your usage (19:00–23:00 is peak)
Connection refused / ECONNREFUSED
ANTHROPIC_BASE_URLis wrong (it must behttps://claude-api.org, notapi.anthropic.com)- A local VPN / proxy is intercepting it → try
unset HTTP_PROXYor whitelistclaude-api.orgin your VPN software
The call keeps streaming but produces no output
This is usually a timeout on intermediary equipment that domestic carriers apply to long-lived SSE connections. Temporary workaround:
export ANTHROPIC_NO_STREAM=1 # 关闭流式Or upgrade your local npm package to ≥ 1.0.x (which has built-in stream-interruption retry).
For more, see the FAQ.
