I wanted to try Claude Code with DeepSeek models — but without breaking my working Anthropic setup. Most guides say “just export it”; that route also connects your normal claude to DeepSeek. Here is the way that touches your setup not at all and works on macOS / Linux / Windows.
The Problem
Scenario: you want to use Claude Code on the same machine with both Anthropic's models (daily work) and DeepSeek's models (trial/alternative).
The catch: if you define the environment variables DeepSeek needs permanently with export, your normal claude command goes to DeepSeek too. So while gaining one model you lose your working setup. That's not what you want.
The Solution: An Isolated Wrapper
We'll define a wrapper that makes the environment variables valid only for the lifetime of a single command. The result:
- claude → works with the Anthropic API as before
- claude-ds → works with the DeepSeek API
- No configuration file is touched
The solution is given below for both macOS / Linux (zsh) and Windows (PowerShell).
Prerequisites
- Claude Code installed — npm install -g @anthropic-ai/claude-code ✅
- DeepSeek API Key — get it from platform.deepseek.com/api_keys
Setup — macOS / Linux (zsh)
Step 1: Add the function to your ~/.zshrc file
What is ~/.zshrc? ~/.zshrc (tilde + slash + zshrc) is the personal configuration file for the Z shell (zsh), the default shell on macOS and Linux. Every time a new terminal window or tab opens, zsh reads this file automatically and runs the commands in it. The ~ character stands for the current user's home directory (/Users/your-username/). The aliases, functions, PATH definitions and environment variables you write in this file become permanently available in all terminal sessions.
# ──────────────────────────────────────────────
# DeepSeek-backed Claude Code wrapper
# Does not affect the normal "claude" command.
# Usage: claude-ds
# ──────────────────────────────────────────────
claude-ds() {
ANTHROPIC_BASE_URL="https://api.deepseek.com/anthropic" \
ANTHROPIC_AUTH_TOKEN="sk-your-deepseek-api-key" \
ANTHROPIC_MODEL="deepseek-v4-pro" \
ANTHROPIC_DEFAULT_OPUS_MODEL="deepseek-v4-pro" \
ANTHROPIC_DEFAULT_SONNET_MODEL="deepseek-v4-pro" \
ANTHROPIC_DEFAULT_HAIKU_MODEL="deepseek-v4-flash" \
CLAUDE_CODE_SUBAGENT_MODEL="deepseek-v4-flash" \
CLAUDE_CODE_EFFORT_LEVEL="max" \
claude "$@"
}⚠️ Replace the sk-your-deepseek-api-key part with your own API key.
Step 2: Activate the change
source ~/.zshrcStep 3: Start using it
# Go to the project directory
cd ~/my-project
# Start Claude Code with DeepSeek
claude-dsSetup — Windows (PowerShell)
Windows has no .zshrc; its counterpart is the PowerShell profile ($PROFILE). The logic is exactly the same: we define a claude-ds function and make the environment variables valid only for the duration of that command.
Step 1: What is $PROFILE and how do you open it?
What is $PROFILE? $PROFILE is the personal startup script that PowerShell reads automatically every time it opens — in other words, the Windows counterpart of ~/.zshrc on macOS/Linux. The functions and aliases you write in it become available in all PowerShell sessions. The file is usually found under Documents\PowerShell\Microsoft.PowerShell_profile.ps1 and may not exist on first use.
To edit the profile (creating it if it doesn't exist):
# Create the profile file if it doesn't exist
if (!(Test-Path $PROFILE)) { New-Item -ItemType File -Path $PROFILE -Force }
# Open it for editing
notepad $PROFILEStep 2: Add the function to the profile
⚠️ Replace the sk-your-deepseek-api-key part with your own API key.
🔍 Why try / finally? In zsh, writing a command as KEY=value confines the variables to that command only. In PowerShell, a variable you assign with $env: stays for the whole session. So on Windows we provide the isolation by hand, by deleting the variables in the finally block — that way, when claude-ds finishes, the normal claude goes to Anthropic again. If you skip it, claude goes to DeepSeek too in that session; exactly what we are avoiding.
Step 3: Reload the profile
. $PROFILEIf you get a “running scripts is disabled” error, run this once: Set-ExecutionPolicy -Scope CurrentUser RemoteSigned
Step 4: Start using it
cd $HOME\my-project
claude-dsHow Does It Work?
Whether it's a zsh function or a PowerShell function, the idea is the same: make the environment variables valid only for the lifetime of the claude-ds command. These variables:
- Are valid only for that command and its child processes
- Don't leak into the shell session (automatic in zsh; via finally in PowerShell)
- Don't affect other terminal tabs
- Don't touch configuration files like .claude.json or settings.json
Environment Variables Reference
- ANTHROPIC_BASE_URL = https://api.deepseek.com/anthropic — DeepSeek's Anthropic-compatible API endpoint
- ANTHROPIC_AUTH_TOKEN = sk-... — your DeepSeek API key
- ANTHROPIC_MODEL = deepseek-v4-pro — Main model
- ANTHROPIC_DEFAULT_OPUS_MODEL = deepseek-v4-pro — Model for Opus requests
- ANTHROPIC_DEFAULT_SONNET_MODEL = deepseek-v4-pro — Model for Sonnet requests
- ANTHROPIC_DEFAULT_HAIKU_MODEL = deepseek-v4-flash — Model for Haiku requests (lightweight)
- CLAUDE_CODE_SUBAGENT_MODEL = deepseek-v4-pro — Model for sub-agents
- CLAUDE_CODE_EFFORT_LEVEL = max — Maximum effort level
Alternative Methods (Why I Don't Recommend Them)
Permanent definition with export ❌
# DON'T DO THIS — it breaks the normal claude too
export ANTHROPIC_BASE_URL="https://api.deepseek.com/anthropic"All your claude calls go to DeepSeek; to go back you have to delete the env vars one by one. You bring back the problem you started with.
Per-project .env file ⚠️
Claude Code reads the .env file in the project directory. It works if you'll use DeepSeek in only a specific project, but:
- It's confusing when switching between projects
- There's a risk of committing .env by accident (it contains the API key)
A separate wrapper script ✅
# ~/.local/bin/claude-ds
#!/bin/zsh
export ANTHROPIC_BASE_URL="https://api.deepseek.com/anthropic"
# ... other env vars
exec claude "$@"This works too, but it isn't as practical as a shell/PowerShell function — an extra file, extra PATH hassle.
Web Search with DeepSeek in Claude Code
The DeepSeek API natively supports the Web Search feature inside Claude Code. If the model decides the question needs a web search, it calls the Web Search tool through the DeepSeek API and summarizes the results.
⚠️ Web Search creates extra LLM API requests, which means extra token cost.
Model Mapping
DeepSeek maps Claude model names automatically:
- claude-opus-* → deepseek-v4-pro
- claude-sonnet-* → deepseek-v4-pro
- claude-haiku-* → deepseek-v4-flash
ℹ️ This list is DeepSeek's automatic mapping. If you set variables such as ANTHROPIC_DEFAULT_SONNET_MODEL explicitly in the function, you override these defaults — for example, in this guide we deliberately route Sonnet requests to deepseek-v4-pro.
Conclusion
With a single function — zsh or PowerShell — you've brought DeepSeek alongside your working setup without touching it at all. claude is on Anthropic, claude-ds is on DeepSeek; you switch between the two in a second.
The real point isn't “which model is better”, it's who holds the control. You decide which job runs on which model — measure, compare, keep what suits you. Your setup stays right where it was; there's nothing to break.
This guide was prepared based on the DeepSeek API documentation.