How to Use DeepSeek with Claude Code: Break Free from Anthropic Models
Published
16 June 2026
Claude Code is one of the best AI coding assistants available. The interface is clean, the agent capabilities are powerful, and the workflow just feels right. But here's something most developers don't realise: you're not locked into using Anthropic's models.
Claude Code supports custom model endpoints, which means you can point it at any OpenAI-compatible API. Including DeepSeek.
Why would you want to do this? The cost difference is staggering. While Claude Opus 4.7 costs $5 input / $25 output per million tokens, DeepSeek V4 Pro costs $1.74 / $3.48, and DeepSeek V4 Flash costs just $0.14 / $0.28.
That's 85% to 98% cheaper for near-identical coding performance.
Let me show you how to set it up.
What You'll Need
Before we start, make sure you have:
- Claude Code installed - Download from claude.ai/code if you haven't already
- A DeepSeek API key - Sign up at platform.deepseek.com (free tier available)
- 5 minutes - This is genuinely quick to set up
Understanding the Setup
Claude Code uses a configuration file to define which models it can access. By default, it points to Anthropic's API endpoints. We're going to add DeepSeek as an additional provider, giving you the choice of which model to use for each task.
You'll still have access to Anthropic's models when you need them, but you can route most of your work through DeepSeek to save costs.
Step 1: Get Your DeepSeek API Key
First, head to platform.deepseek.com and create an account.
- Navigate to API Keys in the dashboard
- Click Create API Key
- Give it a descriptive name like "Claude Code Integration"
- Copy the key (you won't be able to see it again)
- Store it somewhere safe - you'll need it in a moment
The free tier gives you enough credits to test thoroughly. When you're ready to scale, DeepSeek's pricing is pay-as-you-go with no minimums.
Step 2: Locate Claude Code's Configuration File
Claude Code stores its configuration in different locations depending on your operating system:
macOS:
~/Library/Application Support/Claude Code/config.jsonLinux:
~/.config/claude-code/config.jsonWindows:
%APPDATA%\Claude Code\config.jsonOpen this file in your favourite text editor. If it doesn't exist yet, you may need to run Claude Code once to generate it.
Step 3: Add DeepSeek as a Custom Provider
Now we're going to add DeepSeek to your configuration. Here's the configuration structure you need to add:
{ "providers": [ { "name": "Anthropic", "baseURL": "https://api.anthropic.com/v1", "apiKey": "${ANTHROPIC_API_KEY}", "models": [ { "id": "claude-opus-4.7", "name": "Claude Opus 4.7", "contextWindow": 200000 }, { "id": "claude-sonnet-4.5", "name": "Claude Sonnet 4.5", "contextWindow": 200000 } ] }, { "name": "DeepSeek", "baseURL": "https://api.deepseek.com/v1", "apiKey": "${DEEPSEEK_API_KEY}", "models": [ { "id": "deepseek-chat", "name": "DeepSeek V4 Pro", "contextWindow": 128000, "supportsStreaming": true }, { "id": "deepseek-coder", "name": "DeepSeek V4 Flash", "contextWindow": 128000, "supportsStreaming": true } ] } ], "defaultProvider": "DeepSeek", "defaultModel": "deepseek-chat"}Important notes:
- Replace
${DEEPSEEK_API_KEY}with your actual API key, or set it as an environment variable - The
baseURLis OpenAI-compatible, which is why Claude Code can talk to it - I've set DeepSeek as the default provider, but you can change this to "Anthropic" if you prefer
Step 4: Set Your API Key
You have two options for providing your API key:
Option A: Environment Variable (Recommended)
Set the DEEPSEEK_API_KEY environment variable:
macOS/Linux:
export DEEPSEEK_API_KEY="your-api-key-here"Add this to your ~/.bashrc, ~/.zshrc, or equivalent to make it permanent.
Windows (PowerShell):
$env:DEEPSEEK_API_KEY="your-api-key-here"For permanent setup, add it through System Properties > Environment Variables.
Option B: Direct in Config (Less Secure)
Replace ${DEEPSEEK_API_KEY} directly in the config file:
"apiKey": "sk-your-actual-deepseek-api-key-here"This works, but storing API keys in plain text configuration files is less secure. Use environment variables when possible.
Step 5: Restart Claude Code
Close Claude Code completely and reopen it. The new configuration should be loaded automatically.
Step 6: Select Your Model
When you start a new chat or coding session in Claude Code, you should now see DeepSeek models in the model selector dropdown.
Look for:
- DeepSeek V4 Pro (deepseek-chat) - Best for complex reasoning and multi-step tasks
- DeepSeek V4 Flash (deepseek-coder) - Best for routine coding, blazing fast, ultra-cheap
Select the model you want to use, and you're done!
Choosing Between Models
Here's my recommendation for which model to use when:
Use DeepSeek V4 Flash (deepseek-coder) for:
- Code completions and suggestions
- Refactoring existing code
- Writing tests
- Documentation generation
- Quick bug fixes
- Anything repetitive or well-defined
Cost: $0.14 input / $0.28 output per million tokens
Use DeepSeek V4 Pro (deepseek-chat) for:
- Architectural decisions
- Complex debugging
- Multi-file refactors
- Algorithm design
- Code review with context
- When you need deeper reasoning
Cost: $1.74 input / $3.48 output per million tokens
Use Claude Opus when:
- You need absolute top-tier reasoning
- Working on security-critical code
- The task is genuinely hard and worth the premium
- You've tried DeepSeek and it's not quite there
Cost: $5 input / $25 output per million tokens
For 85% of my coding work, DeepSeek V4 Flash is more than capable. For the challenging 10%, I use DeepSeek V4 Pro. For the absolute hardest 5%, I fall back to Claude Opus.
This strategy keeps my monthly AI coding costs under $15 instead of $150+.
Verifying It's Working
To confirm DeepSeek is being used:
- Start a new chat in Claude Code
- Check the model selector shows "DeepSeek V4 Pro" or "DeepSeek V4 Flash"
- Ask it a simple coding question
- Check your DeepSeek dashboard at platform.deepseek.com/usage to see the API calls
If you see activity in your DeepSeek dashboard, it's working!
Troubleshooting Common Issues
"Failed to connect to provider"
Problem: Claude Code can't reach the DeepSeek API.
Solutions:
- Check your API key is correct
- Verify the
baseURLis exactly:https://api.deepseek.com/v1 - Make sure you have an active internet connection
- Check if your firewall or corporate proxy is blocking the connection
"Invalid model ID"
Problem: The model identifier doesn't match what DeepSeek expects.
Solutions:
- Use
deepseek-chatfor DeepSeek V4 Pro - Use
deepseek-coderfor DeepSeek V4 Flash - Don't use legacy model names like
deepseek-v3(deprecated July 2026)
"API key not found"
Problem: The environment variable isn't set correctly.
Solutions:
- Restart your terminal after setting the environment variable
- Verify with:
echo $DEEPSEEK_API_KEY(macOS/Linux) orecho $env:DEEPSEEK_API_KEY(Windows) - Try using the direct API key in the config temporarily to isolate the issue
Models not appearing in selector
Problem: DeepSeek models don't show up in Claude Code's model picker.
Solutions:
- Completely quit Claude Code (not just close the window)
- Verify the JSON syntax in your config file is valid (use jsonlint.com)
- Check the config file location is correct for your OS
- Look for error messages in Claude Code's developer console (Help > Toggle Developer Tools)
Advanced Configuration
Multiple DeepSeek Models
You can add more model variants if you want finer control:
{ "id": "deepseek-chat", "name": "DeepSeek V4 Pro (Thinking Mode)", "contextWindow": 128000, "supportsStreaming": true, "temperature": 0.7},{ "id": "deepseek-chat", "name": "DeepSeek V4 Pro (Precise)", "contextWindow": 128000, "supportsStreaming": true, "temperature": 0.1}This gives you the same model with different temperature settings for different use cases.
Fallback Configuration
Set up automatic fallback to Anthropic if DeepSeek is unavailable:
{ "providers": [...], "defaultProvider": "DeepSeek", "fallbackProvider": "Anthropic", "fallbackOn": ["rate_limit", "server_error"]}Note: This feature may vary depending on your Claude Code version. Check the documentation for your specific version.
Cost Tracking
Add a request logging middleware to track exactly how much you're spending:
{ "logging": { "enabled": true, "logRequests": true, "logTokens": true, "outputPath": "~/claude-code-usage.log" }}Parse this log file monthly to understand your usage patterns and optimise further.
Real-World Performance Comparison
I've been running DeepSeek with Claude Code for the past three weeks. Here's what I've found:
Code completion quality: Virtually identical to Claude Sonnet. I honestly can't tell the difference in a blind test for routine completions.
Complex refactoring: DeepSeek V4 Pro handles 90% of what Claude Opus does. The remaining 10% usually involves very specific architectural patterns or security-critical decisions.
Speed: DeepSeek V4 Flash is noticeably faster than Claude models. Responses feel near-instantaneous.
Cost: My bill went from $127 in May (all Anthropic) to $18 in June (mostly DeepSeek). Same amount of coding, 86% cost reduction.
Reliability: DeepSeek has been solid. I've hit rate limits once during a bulk refactor, but that's it.
Why This Matters
Claude Code is an excellent tool, but it shouldn't lock you into a single model provider. By using DeepSeek for the majority of your work, you:
- Cut costs by 85-95% without changing your workflow
- Keep Claude Opus available for the tasks that truly need it
- Maintain flexibility to switch providers as the market evolves
- Avoid vendor lock-in and pricing changes
The AI model landscape moves fast. OpenAI, Anthropic, Google, and others will continue raising prices as VC funding pressures mount. Having the flexibility to switch providers without changing tools is valuable.
Getting Started Today
You now have everything you need to start using DeepSeek with Claude Code. The setup takes less than five minutes, and the cost savings start immediately.
Here's my challenge: Try DeepSeek V4 Flash for everything today. Just one day. See if you can tell the difference.
I bet you can't for 85% of tasks. And that 85% is currently costing you 20 times more than it should.
Time to fix that.
Additional Resources
- DeepSeek API Documentation
- Claude Code Configuration Reference
- Why Are You Paying So Much for AI Coding Tools? - Full breakdown of AI model costs and alternatives
- DeepSeek Model Benchmarks - Performance comparisons
Questions? Issues? Drop them in the comments below. I'll help you get set up.
Similar articles

Why Are You Paying So Much for AI Coding Tools?
I switched to DeepSeek and now run massive builds for a few dollars instead of hundreds or thousands. The alternatives are 85-95% cheaper with near-identical performance. So why are you still paying premium prices for AI coding tools?
30 June 2026

A Development Harness for Building Software with AI Agents
Raw models are not agents. Skills chained into a spec-driven pipeline turn an AI coding assistant into something you can actually ship with and keep shipping as requirements change.
29 June 2026

Is the CMS Dead?
In a Claude Code world, the CMS admin panel is starting to look like middleware. If an agent can edit your content files directly, do you still need the database, plugins, and publishing layer sitting in between?
29 June 2026

AI Testing: Approaches That Actually Work
Testing AI isn't like testing traditional software. Outputs are non-deterministic, edge cases are infinite, and "correct" is often subjective. But you still need a plan. Let's talk about some of the different approaches.
8 Apr 2026
