Claude Code DeepSeek Configuration
Claude Code is an AI coding assistant from Anthropic that runs in the terminal, supporting third-party compatible APIs via environment variables to connect to models such as DeepSeek.
This article describes how to use Claude Code together with DeepSeek to get powerful AI-assisted programming at a lower cost.
Key points:
- Claude Code controls the browser through ANTHROPIC_BASE_URL Environment variables point to a DeepSeek-compatible interface.
- DeepSeek provides an API compatible with Anthropic's, at the path
https://api.deepseek.com/anthropic。 - Through a set of environment variables, models at different tiers (Opus / Sonnet / Haiku) can be mapped to corresponding DeepSeek models.
- Once configured, simply run in the project directory
claudethe command to use it.
In short:Claude Code + DeepSeek = terminal AI programming assistant + cost-effective large model
- Claude Code: provides a complete terminal AI programming experience, supporting code generation, refactoring, debugging, explanation, and more.
- DeepSeek API: provides an Anthropic-compatible interface, supporting calls to the DeepSeek model family.
- Environment variable bridging: connects the two through standard environment variables, without modifying any Claude Code source code.
Prerequisites
If Claude Code is already installed, you can skip this step.
- Installed Node.js version 18 or above.
- Windows users also need to install Git for Windows(provides a bash environment).
- Registered an account at DeepSeek Platform and created an API Key.
Run the following command in the command line to install Claude Code:
curl -fsSL https://claude.ai/install.sh | bash
After installation, run the following command to verify; if the version number is output normally, installation succeeded:
claude --version
If you run into permission issues, Linux / macOS users can prepend to the command
sudo。If there is login verification, you can find it in the user directory at .claude.json:
{
"hasCompletedOnboarding": true
}

After saving, restart the terminal, then run:
claude
This time the "Log in to claude.ai" window / prompt won't pop up again.
Get a DeepSeek API Key
Go to DeepSeek Platform After logging in, create an API Key and store it safely; you'll need it when configuring environment variables.

An API Key carries account operation privileges, so do not commit it to a repository or share it with others. It's recommended to manage it with your OS's secret management tools or an environment variable file (such as
.env) and add the relevant files to.gitignore。
Configure Environment Variables
Claude Code connects to the DeepSeek API through the following environment variables, whose meanings are as follows:
| Environment Variables | Description |
|---|---|
ANTHROPIC_BASE_URL |
Points to the interface address where DeepSeek is compatible with the Anthropic protocol |
ANTHROPIC_AUTH_TOKEN |
Your DeepSeek API Key |
ANTHROPIC_MODEL |
The model used by default |
ANTHROPIC_DEFAULT_OPUS_MODEL |
Maps the model used for the Opus tier (complex reasoning tasks) |
ANTHROPIC_DEFAULT_SONNET_MODEL |
Maps the model used for the Sonnet tier (everyday programming tasks) |
ANTHROPIC_DEFAULT_HAIKU_MODEL |
Maps the model used for the Haiku tier (fast, lightweight tasks) |
CLAUDE_CODE_SUBAGENT_MODEL |
The model used by subtask agents (a faster model is recommended) |
CLAUDE_CODE_EFFORT_LEVEL |
Thinking depth, optional low / medium / max |
Linux / macOS
Run the following command in the terminal (replace <你的 DeepSeek API Key> with your actual Key):
export ANTHROPIC_BASE_URL=https://api.deepseek.com/anthropic
export ANTHROPIC_AUTH_TOKEN=<你的 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
the above
exportThe command only takes effect in the current terminal session.To make it permanent, you can append the above commands to the end of
~/.bashrc(Bash) or~/.zshrc(Zsh) file, then runsource ~/.bashrcto make it take effect immediately.
Windows(PowerShell)
Run the following command in PowerShell:
$env:ANTHROPIC_BASE_URL="https://api.deepseek.com/anthropic"
$env:ANTHROPIC_AUTH_TOKEN="<你的 DeepSeek API Key>"
$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"
PowerShell's
$env:assignments only take effect for the current session. To make them permanent, add the corresponding user environment variables in "System Properties → Environment Variables", or write the above commands into your PowerShell Profile file ($PROFILE)。
Verify it took effect
Once configured, start Claude Code and run the /status command to verify:
$ cd 你的项目目录
$ claude
/status
If configured correctly, you'll see output similar to the following:
Base URL: https://api.deepseek.com/anthropic
Model: deepseek-v4-pro[1m]
Small fast model: deepseek-v4-flash
Seeing this information means the configuration succeeded; Claude Code is now using DeepSeek V4 for inference.
If you don't see the above information, check item by item: whether the environment variables are set correctly, whether the API Key is valid, and whether variable names have typos.
Get started
Go to your project directory and run claude the command to start Claude Code:
cd /path/to/my-project
claude
After a successful start, the terminal enters Claude Code's interactive interface, where you can describe your programming needs in natural language, for example:

# Let Claude Code explain the current project structure
> 帮我梳理一下这个项目的目录结构和主要模块的作用
# Generate code
> 给 user.go 新增一个根据邮箱查询用户的方法,并补充单元测试
# Debugging issues
> 运行 npm test 后报错,帮我分析原因并修复
Reference configuration
Complete environment variables
| Environment Variables | Value | Required | Description |
|---|---|---|---|
| ANTHROPIC_BASE_URL | https://api.deepseek.com/anthropic | Is | API endpoint address, pointing to DeepSeek's Anthropic-compatible interface |
| ANTHROPIC_AUTH_TOKEN | sk-your-api-key | Is | DeepSeek API Key, used for authentication |
| ANTHROPIC_MODEL | deepseek-v4-pro[1m] | Is | Main model name; [1m] indicates a 1M context window |
| ANTHROPIC_SMALL_FAST_MODEL | deepseek-v4-flash | Is | Fast model used by subagents |
Model name quick reference
| Model name | Capability | Context window | Applicable scenarios |
|---|---|---|---|
| deepseek-v4-pro[1m] | Strongest reasoning | 1M tokens | Complex architecture design, in-depth code review, difficult debugging |
| deepseek-v4-flash | Fast reasoning | 1M tokens | Batch file generation, simple CRUD, documentation writing |
Shell config file path quick reference
| Shell | Configuration file paths | Activation command |
|---|---|---|
| zsh (default on macOS) | ~/.zshrc | source ~/.zshrc |
| bash (default on Linux) | ~/.bashrc | source ~/.bashrc |
| PowerShell (Windows) | System environment variable settings | Restart PowerShell |
Claude Code config file quick reference
| file | Path | Purpose |
|---|---|---|
| CLAUDE.md | Project root directory | Project-level conventions, telling the AI the tech stack, code style, and constraints |
| .claudeignore | Project root directory | Ignore rules, preventing the AI from reading or modifying specified files |
| settings.json | ~/.claude/settings.json | Global settings, including MCP servers, permissions, etc. |
Model selection recommendations
Different DeepSeek models balance performance and cost differently; here are recommended configurations for common scenarios:
| Scenario | Recommended model | Description |
|---|---|---|
| Complex architecture design, in-depth code refactoring | deepseek-v4-pro[1m] |
Strong reasoning ability, suitable for tasks requiring global understanding |
| Everyday feature development, code completion | deepseek-v4-pro[1m] |
Good overall performance, covering most programming scenarios |
| Quick Q&A, simple changes, subtasks | deepseek-v4-flash |
Fast response, low cost, suitable for high-frequency lightweight tasks |