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.

August 9, 2026
DeepSeekClaude CodeAnthropic APIV4Coding AgentIntegration

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 prefixDeepSeek 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

1

Step 1: Install Claude Code

2

Requires Node.js 18+. Windows users need Git for Windows.

3
npm install -g @anthropic-ai/claude-code
claude --version   # verify
4

Step 2: Set the environment variables

5

Use the block above. Get your API key from the DeepSeek Platform.

6

Step 3: Run it

7
cd /path/to/my-project
claude

Env Var Reference

VariablePurposeDeepSeek recommendation
ANTHROPIC_BASE_URLAPI endpointhttps://api.deepseek.com/anthropic
ANTHROPIC_AUTH_TOKENAuth (DeepSeek key)Your DeepSeek API key
ANTHROPIC_MODELDefault modeldeepseek-v4-pro[1m]
ANTHROPIC_DEFAULT_OPUS_MODELOpus-tier modeldeepseek-v4-pro[1m]
ANTHROPIC_DEFAULT_SONNET_MODELSonnet-tier modeldeepseek-v4-pro[1m]
ANTHROPIC_DEFAULT_HAIKU_MODELHaiku-tier modeldeepseek-v4-flash
CLAUDE_CODE_SUBAGENT_MODELSubagent modeldeepseek-v4-flash
CLAUDE_CODE_EFFORT_LEVELReasoning effortmax
CLAUDE_CODE_AUTO_COMPACT_WINDOWContext compaction threshold786432

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-opusdeepseek-v4-pro
  • Model names starting with claude-haiku or claude-sonnetdeepseek-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.