How to run Claude Code on DeepSeek models with environment variables
DeepSeek offers an endpoint that accepts requests in the Anthropic API format. In Claude Code, changing only the base URL and model names makes DeepSeek models do the work instead of Claude. Usage is billed to your DeepSeek API account, so it suits running lighter tasks cheaply.
- Get an API key from the DeepSeek Platform.
- Set the environment variables in your terminal. These are the values from DeepSeek's official guide.
export ANTHROPIC_BASE_URL=https://api.deepseek.com/anthropic
export ANTHROPIC_AUTH_TOKEN=<your DeepSeek API key>
export ANTHROPIC_MODEL=deepseek-flash[1m]
export ANTHROPIC_DEFAULT_OPUS_MODEL=deepseek-flash[1m]
export ANTHROPIC_DEFAULT_SONNET_MODEL=deepseek-flash[1m]
export ANTHROPIC_DEFAULT_HAIKU_MODEL=deepseek-flash
export CLAUDE_CODE_SUBAGENT_MODEL=deepseek-flash
export CLAUDE_CODE_EFFORT_LEVEL=max
- Go to your project folder and run
claude.
The [1m] suffix after a model name tells Claude Code to treat it with a 1 million token context window. CLAUDE_CODE_EFFORT_LEVEL overrides --effort and /effort.
If you leave out the model variables, DeepSeek still accepts names that start with claude: names starting with claude-opus map to deepseek-v4-pro (billed at the V4 Pro price), and claude-sonnet or claude-haiku names map to deepseek-flash. Unknown names that don't start with claude return a 400 error. Filling in every model variable as above lets you know which model runs and what it will cost.
The setup applies as long as the variables stay in your shell. To go back to Claude, open a new terminal or unset them. In Windows PowerShell, set the same values in the form $env:ANTHROPIC_BASE_URL="https://api.deepseek.com/anthropic".
Sources
Get notified when a new tip lands
Tip alerts only go out in the app. Install it and turn notifications on.