Set up Claude Code
Claude Code is Anthropic's official terminal AI coding tool. You can use it through 树新在线 as a relay.
Install
bash
npm install -g @anthropic-ai/claude-codeOption 1: Environment variables (recommended)
Add the following to ~/.zshrc or ~/.bashrc:
bash
export ANTHROPIC_BASE_URL="https://api.treenew.online"
export ANTHROPIC_AUTH_TOKEN="sk-your-token"After saving, run source ~/.zshrc (or reopen the terminal) to apply.
Mind the variable name
It is ANTHROPIC_AUTH_TOKEN, not ANTHROPIC_API_KEY. Use the former for relay scenarios.
Option 2: settings.json
Edit ~/.claude/settings.json (create it if it doesn't exist):
json
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.treenew.online",
"ANTHROPIC_AUTH_TOKEN": "sk-your-token"
}
}This applies to all terminal sessions without editing your shell config.
Specify a model (optional)
bash
export ANTHROPIC_MODEL="claude-sonnet-5"Or switch inside Claude Code with the /model command. Available model names are as shown in the console's “Model Square”.
Verify
bash
claudeAsk any question; a normal reply means the setup succeeded.
Troubleshooting
- 401 error: the token is invalid or expired — re-check
ANTHROPIC_AUTH_TOKEN - Model not found: the token's group does not include the Claude series — check the token's group in the console
- Config not applied: when both an environment variable and settings.json exist, the environment variable takes precedence; make sure no stale value remains (
echo $ANTHROPIC_BASE_URL)