How to use Claude Code with DeepSeek V4
DeepSeek offers an Anthropic-compatible API, so Claude Code can run on DeepSeek V4 models for a fraction of the token cost. Here's the setup from DeepSeek's documentation, what to watch out for, and a simpler option if you'd rather skip the environment variables.
Updated 14 September 2026
Short version: set ANTHROPIC_BASE_URL to https://api.deepseek.com/anthropic, put your DeepSeek key in ANTHROPIC_AUTH_TOKEN, set the model variables to DeepSeek model IDs, then run claude.
Why run Claude Code on DeepSeek?
Claude Code is one of the most capable agent harnesses around, but agentic sessions use a lot of tokens: every file read, command and retry goes back to the model. DeepSeek V4 is strong at coding, has a context window of roughly a million tokens, and costs far less per token. Pairing the two gives you Claude Code's terminal workflow at DeepSeek prices.
Step 1: Get a DeepSeek API key
Sign in at platform.deepseek.com, create an API key and add some credit. Keep the key somewhere safe; you'll paste it in Step 3.
Step 2: Install Claude Code
Claude Code needs Node.js 18 or newer (and Git for Windows on Windows).
npm install -g @anthropic-ai/claude-code
Step 3: Point Claude Code at DeepSeek
These are the environment variables from DeepSeek's Claude Code integration docs. On macOS or Linux:
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
export CLAUDE_CODE_AUTO_COMPACT_WINDOW=786432
Windows (PowerShell)
$env:ANTHROPIC_BASE_URL="https://api.deepseek.com/anthropic"
$env:ANTHROPIC_AUTH_TOKEN="<your DeepSeek API key>"
$env:ANTHROPIC_MODEL="deepseek-flash[1m]"
$env:ANTHROPIC_DEFAULT_OPUS_MODEL="deepseek-flash[1m]"
$env:ANTHROPIC_DEFAULT_SONNET_MODEL="deepseek-flash[1m]"
$env:ANTHROPIC_DEFAULT_HAIKU_MODEL="deepseek-flash"
$env:CLAUDE_CODE_SUBAGENT_MODEL="deepseek-flash"
$env:CLAUDE_CODE_EFFORT_LEVEL="max"
$env:CLAUDE_CODE_AUTO_COMPACT_WINDOW="786432"
What each variable does
ANTHROPIC_BASE_URLsends Claude Code's requests to DeepSeek instead of Anthropic.ANTHROPIC_AUTH_TOKENis your DeepSeek API key.ANTHROPIC_MODELand theDEFAULT_*_MODELvariables choose which DeepSeek model answers when Claude Code asks for its main, Opus, Sonnet or Haiku model.CLAUDE_CODE_SUBAGENT_MODELis the model used by subagents.CLAUDE_CODE_AUTO_COMPACT_WINDOWtells Claude Code when to compact the conversation, sized for DeepSeek's long context.
Step 4: Start Claude Code
cd your-project
claude
To avoid retyping the variables, save the export lines in a file such as ~/.claude-deepseek.sh and run source ~/.claude-deepseek.sh in any terminal where you want Claude Code on DeepSeek. Keep that file private, because it contains your key.
Choosing V4 Pro or V4.1 Flash
DeepSeek's example uses deepseek-flash (currently DeepSeek V4.1 Flash) everywhere. That's the cheapest setup and fine for most edits. DeepSeek's docs note that Claude Opus model names map to deepseek-v4-pro, and Sonnet and Haiku names map to deepseek-flash. For harder refactors, set ANTHROPIC_MODEL to deepseek-v4-pro[1m]. Model IDs change from time to time, so check DeepSeek's docs for the current list.
Caveats
- Claude Code is built for Claude. Its prompts and tools are tuned for Anthropic's models, so some behaviour may differ on DeepSeek.
- Web search costs extra. DeepSeek's docs note that web searches add model token costs for summarising the results.
- Watch your usage. Check the DeepSeek console during your first sessions to see what a typical task costs.
- Your code goes to DeepSeek. Requests are sent to DeepSeek's API, not Anthropic's.
The no-setup alternative: a harness built for DeepSeek
If you want DeepSeek as a coding agent but don't need Claude Code specifically, Gritcode is built for DeepSeek from the start. You download it, paste your key in Settings (it goes into your OS keyring) and pick a model. There are no environment variables and no Node.js.
| Claude Code + DeepSeek | Gritcode | |
|---|---|---|
| Setup | npm install plus 9 environment variables | Download, paste your key |
| Interface | Terminal | Native desktop app with editor and file tree |
| Built for | Claude models | DeepSeek V4, with context management tuned for it |
| Run your app | Via agent commands | ▶ Play button, no tokens used |
| Free option | No | Yes, Kilo Free with no key |
| Open source | No | Yes, GPLv3 |
More detail: Gritcode vs Claude Code · Gritcode as a DeepSeek desktop app
FAQ
Can Claude Code use DeepSeek models?
Yes. DeepSeek provides an Anthropic-compatible endpoint at https://api.deepseek.com/anthropic. Point ANTHROPIC_BASE_URL at it, use your DeepSeek API key as ANTHROPIC_AUTH_TOKEN, and set the model variables to DeepSeek model IDs.
Which DeepSeek model should I use with Claude Code?
DeepSeek's example configuration uses deepseek-flash for everything, which is the cheapest option. For harder work, switch the main model to deepseek-v4-pro.
Is Claude Code with DeepSeek cheaper than with Claude?
DeepSeek's per-token prices are much lower than Claude's, so the same session usually costs far less. Your actual savings depend on how you use it.
Is there a GUI alternative to Claude Code for DeepSeek?
Yes. Gritcode is a free, open-source native desktop coding agent built for DeepSeek V4. You paste your key in Settings, with no environment variables to manage.
Skip the setup.
Gritcode: DeepSeek V4 in a native app. Free, open source, 3.5 MB.