Using Claude Code with DeepSeek — cut AI coding costs without sacrificing quality
Claude Code is one of the most capable AI coding agents available today — but it defaults to Anthropic’s hosted models, and those tokens add up fast. If you want the same agentic coding workflow at a fraction of the cost, DeepSeek’s Anthropic-compatible API lets you swap the underlying model with a single configuration change.
This post walks you through exactly how to set that up and explains why it works.
Why swap the model?
Switching from Anthropic to DeepSeek is mainly about cost, performance, control, and evolving capabilities. DeepSeek models are typically cheaper, fast, and now competitive even in long-context handling with newer versions. Anthropic models still lead in reliability, nuanced reasoning, and strong safety alignment.
The decision ultimately depends on whether you prioritize efficiency and flexibility or consistency and guardrails.
DeepSeek has released frontier-class models (deepseek-v4-flash, deepseek-v4-pro, and others) that benchmark competitively with Claude Sonnet and Opus across coding tasks, at a dramatically lower token price. Crucially, DeepSeek exposes an Anthropic-compatible API endpoint at https://api.deepseek.com/anthropic — meaning it speaks the exact same protocol that Claude Code already uses. No custom plugin, no SDK fork; just a URL and a key swap.
How the Anthropic-compatible endpoint works
DeepSeek’s API surface has two flavours:
- OpenAI-compatible — the default at
https://api.deepseek.com/v1, useful for any OpenAI SDK client. - Anthropic-compatible — at
https://api.deepseek.com/anthropic, which mirrors the Anthropic Messages API (/v1/messages).
Claude Code communicates using the Anthropic SDK under the hood. When you set ANTHROPIC_BASE_URL to the DeepSeek endpoint, all requests are transparently routed there. The model names are resolved through two environment variables that Claude Code reads at startup:
| Environment variable | Purpose |
|---|---|
ANTHROPIC_BASE_URL |
Override the API base URL (points to DeepSeek) |
ANTHROPIC_AUTH_TOKEN |
Your DeepSeek API key (replaces Anthropic key) |
ANTHROPIC_DEFAULT_SONNET_MODEL |
The model name to use when sonnet is selected |
ANTHROPIC_DEFAULT_OPUS_MODEL |
The model name to use when opus is selected |
This indirection lets Claude Code keep its familiar model names (sonnet, opus) while the actual inference runs on DeepSeek hardware.
Setting up the configuration
Step 1 — Get a DeepSeek API key
Sign up at platform.deepseek.com and generate an API key from the dashboard. It looks like sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.
Step 2 — Create (or update) your Claude Code settings file
Claude Code reads project-level configuration from a CLAUDE.md or from a claude.json settings file. The snippet below is the minimal configuration needed to redirect all requests to DeepSeek:
{
"env": {
"ANTHROPIC_DEFAULT_SONNET_MODEL": "deepseek-v4-flash",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "deepseek-v4-pro",
"ANTHROPIC_BASE_URL": "https://api.deepseek.com/anthropic",
"ANTHROPIC_AUTH_TOKEN": "sk-xxxxxxxxxxxxxxxxx"
},
"model": "sonnet",
"availableModels": [
"sonnet",
"opus"
]
}
A few notes on the model names:
deepseek-v4-flash— DeepSeek’s fast, cost-efficient model optimised for coding and everyday tasks. This maps well tosonnet.deepseek-v4-pro— The high-capability variant with stronger multi-step reasoning. Use this as theopusequivalent for complex architectural or debugging tasks.
💡 Tip: Keep
ANTHROPIC_AUTH_TOKENout of version control. If you are on a team, use an environment variable in your shell profile (~/.zshrcor~/.bashrc) rather than hard-coding it in the settings file.
Step 3 — Export your API key (recommended)
Add the following to your shell profile so you don’t have to embed the key in the JSON config:
# ~/.zshrc or ~/.bashrc
export ANTHROPIC_AUTH_TOKEN="sk-xxxxxxxxxxxxxxxxx"
export ANTHROPIC_BASE_URL="https://api.deepseek.com/anthropic"
export ANTHROPIC_DEFAULT_SONNET_MODEL="deepseek-v4-flash"
export ANTHROPIC_DEFAULT_OPUS_MODEL="deepseek-v4-pro"
When these environment variables are set, you can omit the env block from the JSON config entirely.
Step 4 — Verify the connection
Launch Claude Code from your project directory and run a quick sanity check:
claude --version # confirm Claude Code is installed
claude "say hello" # should reply via DeepSeek, not Anthropic
If the response comes back and no Anthropic API error appears, the routing is working correctly.
Model selection guide
| Task type | Recommended model | Claude Code alias |
|---|---|---|
| Boilerplate, refactoring, test writing | deepseek-v4-flash |
sonnet |
| Architecture design, complex debugging | deepseek-v4-pro |
opus |
| Large context analysis (> 64k tokens) | deepseek-v4-flash |
sonnet |
Switch between them inside Claude Code with /model sonnet or /model opus as usual.
Known limitations
- Tool use / function calling: DeepSeek’s Anthropic-compatible endpoint supports tool use, but there may be subtle behavioural differences in multi-step tool chains. Test your workflows before relying on them in production.
- Vision inputs: Image attachments are not supported on the Anthropic-compatible endpoint; use DeepSeek’s OpenAI-compatible endpoint if you need vision.
- Rate limits: DeepSeek’s rate limits differ from Anthropic’s. Check the DeepSeek platform dashboard for your tier’s limits before running long agentic sessions.
Conclusion
Swapping Claude Code’s backend to DeepSeek takes under five minutes and requires no code changes — just a handful of environment variables. You keep the same agentic interface, the same slash commands, and the same workflow, while cutting costs dramatically on everyday coding tasks.
Get a DeepSeek API key at platform.deepseek.com, drop the config snippet into your project, and run your first session.
References: