TWISTEdBRACKETS

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:

  1. Claude Code installed - Download from claude.ai/code if you haven't already
  2. A DeepSeek API key - Sign up at platform.deepseek.com (free tier available)
  3. 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.

  1. Navigate to API Keys in the dashboard
  2. Click Create API Key
  3. Give it a descriptive name like "Claude Code Integration"
  4. Copy the key (you won't be able to see it again)
  5. 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:

bash
~/Library/Application Support/Claude Code/config.json

Linux:

bash
~/.config/claude-code/config.json

Windows:

bash
%APPDATA%\Claude Code\config.json

Open 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:

json
{  "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 baseURL is 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:

Set the DEEPSEEK_API_KEY environment variable:

macOS/Linux:

bash
export DEEPSEEK_API_KEY="your-api-key-here"

Add this to your ~/.bashrc, ~/.zshrc, or equivalent to make it permanent.

Windows (PowerShell):

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:

json
"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:

  1. Start a new chat in Claude Code
  2. Check the model selector shows "DeepSeek V4 Pro" or "DeepSeek V4 Flash"
  3. Ask it a simple coding question
  4. 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 baseURL is 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-chat for DeepSeek V4 Pro
  • Use deepseek-coder for 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) or echo $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:

json
{  "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:

json
{  "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:

json
{  "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

Questions? Issues? Drop them in the comments below. I'll help you get set up.

Share this article: