Switch Claude Code to use custom model providers (DeepSeek, GLM, Qwen, OpenAI-compatible endpoints).
Claude Code reads config from multiple sources (in priority order):
~/.claude/config.json~/.claude/settings.jsonUser must provide:
https://api.deepseek.com/anthropic)deepseek-v4-flash, glm-5)Set user-level environment variables (persist across restarts):
powershell
[Environment]::SetEnvironmentVariable("ANTHROPIC_API_KEY", "<api_key>", "User")
[Environment]::SetEnvironmentVariable("ANTHROPIC_BASE_URL", "<base_url>", "User")
[Environment]::SetEnvironmentVariable("ANTHROPIC_MODEL", "<model>", "User")
Clear conflicting variables:
powershell
[Environment]::SetEnvironmentVariable("ANTHROPIC_AUTH_TOKEN", "", "User")
Edit ~/.claude/config.json:
json
{
"env": {
"ANTHROPIC_API_KEY": "<api_key>",
"ANTHROPIC_BASE_URL": "<base_url>",
"ANTHROPIC_MODEL": "<model>"
}
}
Edit ~/.claude/settings.json, add/update:
json
{
"model": "<model>",
"env": {
"ANTHROPIC_BASE_URL": "<base_url>",
"ANTHROPIC_API_KEY": "<api_key>"
}
}
Test the configuration:
bash
claude --print "hi, what model are you?"
ANTHROPIC_AUTH_TOKEN and ANTHROPIC_API_KEY set → Clear ANTHROPIC_AUTH_TOKENconfig.json for stale ANTHROPIC_MODEL valueProviderbase_urlModelsDeepSeekhttps://api.deepseek.com/anthropic``deepseek-v4-flash, deepseek-v4-proGLM (阿里云)https://coding.dashscope.aliyuncs.com/apps/anthropic``glm-5QwenSame as GLMqwen-*
Use the bundled script for automated configuration:
bash
python scripts/configure_model.py --base-url <url> --model <name> --api-key <key>