DeepSeek V4 with Claude Code: Full Setup Guide
Run Claude Code on DeepSeek V4 models. Configure ANTHROPIC_BASE_URL, model mapping (opus→v4-pro, sonnet/haiku→v4-flash), subagent models, web search, and cost savings.
Claude Code is Anthropic's terminal coding agent — but it doesn't have to run on Anthropic models. DeepSeek's API is Anthropic-compatible, so you can point Claude Code at DeepSeek V4 with a few environment variables. The result: Claude Code's harness and UX at DeepSeek pricing.
This is the official, DeepSeek-documented setup (see the DeepSeek Agent Integrations guide).
How the Model Mapping Works
Claude Code passes Claude model names; DeepSeek maps them to its own models:
| Claude model prefix | DeepSeek model |
|---|---|
claude-opus-* | deepseek-v4-pro |
claude-sonnet-* | deepseek-v4-flash |
claude-haiku-* | deepseek-v4-flash |
You can also set explicit models with the env vars below — e.g. pin Opus-tier work to deepseek-v4-pro[1m] (the 1M-context variant) and subagents to deepseek-v4-flash for cost.
Option 1: Migrate an Existing Claude Code Install
If you already have Claude Code, just set these environment variables:
export ANTHROPIC_BASE_URL=https://api.deepseek.com/anthropic
export ANTHROPIC_AUTH_TOKEN=<your DeepSeek API Key>
export ANTHROPIC_MODEL=deepseek-v4-pro[1m]
export ANTHROPIC_DEFAULT_OPUS_MODEL=deepseek-v4-pro[1m]
export ANTHROPIC_DEFAULT_SONNET_MODEL=deepseek-v4-pro[1m]
export ANTHROPIC_DEFAULT_HAIKU_MODEL=deepseek-v4-flash
export CLAUDE_CODE_SUBAGENT_MODEL=deepseek-v4-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=""
$env:ANTHROPIC_MODEL="deepseek-v4-pro[1m]"
$env:ANTHROPIC_DEFAULT_OPUS_MODEL="deepseek-v4-pro[1m]"
$env:ANTHROPIC_DEFAULT_SONNET_MODEL="deepseek-v4-pro[1m]"
$env:ANTHROPIC_DEFAULT_HAIKU_MODEL="deepseek-v4-flash"
$env:CLAUDE_CODE_SUBAGENT_MODEL="deepseek-v4-flash"
$env:CLAUDE_CODE_EFFORT_LEVEL="max"
$env:CLAUDE_CODE_AUTO_COMPACT_WINDOW="786432"
Then run claude in your project directory.
Option 2: Install from Scratch
Step 1: Install Claude Code
Requires Node.js 18+. Windows users need Git for Windows.
npm install -g @anthropic-ai/claude-code
claude --version # verify
Step 2: Set the environment variables
Use the block above. Get your API key from the DeepSeek Platform.
Step 3: Run it
cd /path/to/my-project
claude
Env Var Reference
| Variable | Purpose | DeepSeek recommendation |
|---|---|---|
ANTHROPIC_BASE_URL | API endpoint | https://api.deepseek.com/anthropic |
ANTHROPIC_AUTH_TOKEN | Auth (DeepSeek key) | Your DeepSeek API key |
ANTHROPIC_MODEL | Default model | deepseek-v4-pro[1m] |
ANTHROPIC_DEFAULT_OPUS_MODEL | Opus-tier model | deepseek-v4-pro[1m] |
ANTHROPIC_DEFAULT_SONNET_MODEL | Sonnet-tier model | deepseek-v4-pro[1m] |
ANTHROPIC_DEFAULT_HAIKU_MODEL | Haiku-tier model | deepseek-v4-flash |
CLAUDE_CODE_SUBAGENT_MODEL | Subagent model | deepseek-v4-flash |
CLAUDE_CODE_EFFORT_LEVEL | Reasoning effort | max |
CLAUDE_CODE_AUTO_COMPACT_WINDOW | Context compaction threshold | 786432 |
Web Search in Claude Code
DeepSeek's API natively supports Claude Code's Web Search tool. When Claude Code determines a query needs web search, it invokes the tool and DeepSeek performs the search — summarizing retrieved content via additional LLM requests. Note: those summary requests incur additional token cost.
Example trigger:
Help me search for the best Rust tutorials
Claude Code invokes the Web Search tool; DeepSeek executes it through its API.
Claude Desktop App
The same mapping works in Claude Desktop developer mode. Claude Desktop's model-name restrictions are bypassed by pointing base_url and api_key at DeepSeek:
- Model names starting with
claude-opus→deepseek-v4-pro - Model names starting with
claude-haikuorclaude-sonnet→deepseek-v4-flash
Cost Considerations
DeepSeek V4 is priced far below Anthropic models — the V4 pricing is a fraction of Opus/Sonnet per-token cost. The [1m] suffix selects the 1M-context variant, giving Claude Code the long context window it needs for big codebases. Routing subagents to deepseek-v4-flash keeps parallel task costs near-zero.
For more on when to route which work to DeepSeek vs frontier models, see DeepSeek V4 Flash vs Pro and Cost Optimization Patterns.
Related Pages
- DeepSeek OpenAI-Compatible API — SDK integration and dual-format details
- Tool Calls with Thinking — tool-call + reasoning patterns
- DeepSeek for Coding — model comparison for coding
- OpenCode Guide (Blog) — the OpenCode alternative
Related Articles
DeepSeek Thinking Mode: Enable, Read & Compare
Complete guide to DeepSeek's thinking mode. How to enable thinking, read reasoning_content tokens, choose between high/max effort, and understand how visible reasoning differs from Claude's invisible extended thinking and GPT's CoT prompting.
Gemini Managed Agents: Build Autonomous Agents with the Interactions API
Build production agents with Gemini Managed Agents. Antigravity agent, 3.6 Flash default, environment hooks, budget controls, scheduled triggers, and the Environments API.
Gemini Function Calling: Tool Integration & Multi-Tool Patterns
Master Gemini's function calling for tool integration. Design effective function declarations, orchestrate multiple tools, handle errors, and minimize unnecessary function calls.