How to Use DeepSeek-V3.1 in Claude Code
How to Use DeepSeek-V3.1 in Claude Code
Claude Code is a lightweight coding assistant that normally connects to Anthropic’s Claude models. Thanks to DeepSeek’s Anthropic-compatible API, you can also run Claude Code on top of DeepSeek V3.1 with just a few environment variables.
This guide walks you through installation, configuration, and usage.
1. Install Claude Code
Claude Code can be installed in two ways:
Option A (curl installer):
curl -fsSL https://claude.ai/install.sh | bash
Option B (npm):
npm install -g @anthropic-ai/claude-code
2. Configure for DeepSeek V3.1
Claude Code relies on Anthropic API variables. To redirect it to DeepSeek’s Anthropic-compatible endpoint, set these environment variables:
# Point to DeepSeek's Anthropic-compatible endpoint
export ANTHROPIC_BASE_URL="https://api.deepseek.com/anthropic"
# Your DeepSeek API Key
export ANTHROPIC_AUTH_TOKEN="YOUR_DEEPSEEK_API_KEY"
# Use DeepSeek V3.1 as the main model
export ANTHROPIC_MODEL="deepseek-chat"
# Use DeepSeek V3.1 also as the small/fast model
export ANTHROPIC_SMALL_FAST_MODEL="deepseek-chat"
Notes:
- deepseek-chat = DeepSeek V3.1 (non-reasoning mode)
- deepseek-reasoner = DeepSeek V3.1 reasoning mode (supports detailed “thinking” traces, but limited tool use)
If you want the reasoning model, replace deepseek-chat
with deepseek-reasoner
.
3. One-Click Startup Script
To simplify usage, you can create a shell script called start-claude-deepseek.sh
:
#!/bin/bash
# DeepSeek V3.1 with Claude Code
export ANTHROPIC_BASE_URL="https://api.deepseek.com/anthropic"
export ANTHROPIC_AUTH_TOKEN="YOUR_DEEPSEEK_API_KEY"
export ANTHROPIC_MODEL="deepseek-chat"
export ANTHROPIC_SMALL_FAST_MODEL="deepseek-chat"
# Launch Claude Code
claude "$@"
Make it executable:
chmod +x start-claude-deepseek.sh
Now run Claude Code with:
./start-claude-deepseek.sh
4. Usage
Navigate into your project folder and run the script:
cd your-project
../start-claude-deepseek.sh
From here, Claude Code behaves exactly the same—except now it’s powered by DeepSeek V3.1.
5. Troubleshooting
- Invalid token error → check that
ANTHROPIC_AUTH_TOKEN
is set to your real DeepSeek API key. - No response → confirm the
ANTHROPIC_BASE_URL
is correct (https://api.deepseek.com/anthropic
). - Tool/function calling → supported in
deepseek-chat
;deepseek-reasoner
may fall back todeepseek-chat
.
✅ You’re now ready to use Claude Code with DeepSeek V3.1 as your AI coding assistant.