Integrating Claude Code
Applicable role: Developer Last updated: 2026-07-15
Claude Code is a CLI coding agent from Anthropic that can perform tasks such as writing, debugging, and refactoring code in your terminal. By modifying environment variables, you can point Claude Code's requests at the platform API.
Prerequisites
- Claude Code is installed (
npm install -g @anthropic-ai/claude-code) - An API Key has been created in the platform console
- The Base URL has been confirmed (see the "API Keys" page in the console)
Configuration
Claude Code controls its API connection through three environment variables:
| Environment Variable | Purpose | Example |
|---|---|---|
ANTHROPIC_BASE_URL |
Target address for requests | https://your-domain.com |
ANTHROPIC_AUTH_TOKEN |
API Key | sk-xxxxxxxx |
ANTHROPIC_MODEL |
Default model to use (optional) | claude-sonnet-4-6 |
Method 1: Configure via settings.json (recommended)
Edit ~/.claude/settings.json (Windows path: C:\Users\<用户名>\.claude\settings.json) and add the following:
{
"env": {
"ANTHROPIC_BASE_URL": "YOUR_API_BASE_URL",
"ANTHROPIC_AUTH_TOKEN": "YOUR_API_KEY"
}
}Restart Claude Code after saving for the changes to take effect. The advantage of this approach is that the configuration is persistent — you don't need to set it again every time you open a terminal.
Method 2: Via shell environment variables
Add the following to ~/.zshrc (macOS) or ~/.bashrc (Linux):
export ANTHROPIC_BASE_URL="YOUR_API_BASE_URL"
export ANTHROPIC_AUTH_TOKEN="YOUR_API_KEY"After saving, run source ~/.zshrc to apply the configuration.
Windows PowerShell:
$env:ANTHROPIC_BASE_URL="YOUR_API_BASE_URL"
$env:ANTHROPIC_AUTH_TOKEN="YOUR_API_KEY"Method 3: Temporary use (single session)
Set the variables directly in the terminal; they apply only to the current session:
ANTHROPIC_BASE_URL="YOUR_API_BASE_URL" ANTHROPIC_AUTH_TOKEN="YOUR_API_KEY" claudeSpecifying a default model (optional)
If you want Claude Code to use a specific model on the platform by default, you can set additional model-related variables:
{
"env": {
"ANTHROPIC_BASE_URL": "YOUR_API_BASE_URL",
"ANTHROPIC_AUTH_TOKEN": "YOUR_API_KEY",
"ANTHROPIC_MODEL": "claude-sonnet-4-6",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-4-6",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-haiku-3-5"
}
}Setting both
ANTHROPIC_DEFAULT_SONNET_MODELandANTHROPIC_DEFAULT_HAIKU_MODELprevents Claude Code's background tasks (such as context summarization) from erroring out on an unavailable default model.
Verifying the configuration
Check whether the environment variables took effect
# macOS / Linux
echo $ANTHROPIC_BASE_URL
echo $ANTHROPIC_AUTH_TOKEN
# Windows PowerShell
echo $env:ANTHROPIC_BASE_URL
echo $env:ANTHROPIC_AUTH_TOKENTest by launching Claude Code
Go to any project directory, run claude, and send a simple message (such as "Hello") to confirm that you receive a normal response.
If you get a response, the configuration is successful. If you get an error, check the following:
- Whether the Base URL is correct (note whether it needs a
/v1or other path suffix — follow the address provided by the platform) - Whether the API Key is correct and has a positive balance
- Whether the network can reach the Base URL (you can test connectivity with
curl)
FAQ
Q: I've configured it, but it still connects to Anthropic's official service. What should I do?
A: Check whether environment variables are set in multiple places (for example, both .zshrc and settings.json exist but have different values). settings.json takes higher priority. Also make sure the terminal has been restarted or the config file has been re-sourced.
Q: Does Claude Code's /model switch command still work?
A: Yes. After switching, Claude Code sends the new model name to your configured Base URL, and as long as the platform supports that model it will work normally.
Q: Why is token consumption higher than expected? A: Claude Code runs in agent mode, and each reasoning step resends the full context. A single complex task can consume hundreds of thousands of tokens. We recommend monitoring your usage on the "Usage History" page in the console.
Q: How do I use it on Windows?
A: Method 1 (settings.json) works on Windows as well, with the path C:\Users\<用户名>\.claude\settings.json. Method 2 requires setting environment variables in PowerShell using the $env: syntax.
