How to Switch Claude Code to DeepSeek for Faster, Cheaper AI Coding

This step‑by‑step guide shows how to configure Claude Code to use DeepSeek’s Anthropic‑compatible API, replace the default model, optimize costs with mixed model strategies, secure your API key, and troubleshoot common connection issues, enabling a seamless, cost‑effective AI development workflow.

Wukong Talks Architecture
Wukong Talks Architecture
Wukong Talks Architecture
How to Switch Claude Code to DeepSeek for Faster, Cheaper AI Coding

Introduction

Claude Code is a powerful AI coding assistant that originally supports only Anthropic’s official models. By editing its configuration, you can point it to DeepSeek’s API, gaining more model choices and a better price‑performance ratio.

Step 1 – Create the Configuration File

In your home directory create a ~/.claude folder (if it does not exist) and add a settings.json file with the following JSON. Replace sk-XXX with your own DeepSeek API key.

{
  "env": {
    "ANTHROPIC_AUTH_TOKEN": "sk-YourAPIKey",
    "ANTHROPIC_BASE_URL": "https://api.deepseek.com/anthropic",
    "ANTHROPIC_MODEL": "deepseek-reasoner",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "deepseek-reasoner",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "deepseek-reasoner",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "deepseek-reasoner",
    "CLAUDE_CODE_SUBAGENT_MODEL": "deepseek-reasoner",
    "CLAUDE_CODE_MAX_OUTPUT_TOKENS": "32000"
  },
  "permissions": {"allow": [], "deny": []},
  "alwaysThinkingEnabled": false
}

Parameter Details

ANTHROPIC_AUTH_TOKEN

: DeepSeek API key (keep secret). ANTHROPIC_BASE_URL: API endpoint – the core compatibility point. ANTHROPIC_MODEL: Default model to use. ANTHROPIC_DEFAULT_OPUS_MODEL: Model for complex tasks such as architecture design. ANTHROPIC_DEFAULT_SONNET_MODEL: Balanced model for everyday coding. ANTHROPIC_DEFAULT_HAIKU_MODEL: Lightweight model for simple queries. CLAUDE_CODE_SUBAGENT_MODEL: Model used by sub‑agents for automated subtasks. CLAUDE_CODE_MAX_OUTPUT_TOKENS: Maximum token output (up to 32K).

Model Selection Strategy

deepseek-reasoner

: Reasoning‑enhanced model, ideal for complex logic and architecture design. deepseek-chat: Standard chat model, cost‑effective for routine coding.

Design principle: use the cheaper deepseek-chat for everyday work and switch to deepseek-reasoner only when high‑quality reasoning is required.

Step 2 – Verify the Integration

Restart Claude Code after saving the file. You should see a confirmation that DeepSeek is connected.

Claude Code successfully connected to DeepSeek
Claude Code successfully connected to DeepSeek

The interface shows that Claude Code can now send requests to DeepSeek.

Step 3 – Optional Cost Optimization

If you mainly perform routine coding, change the default model to deepseek-chat to reduce expenses by roughly 70% while keeping quality for simple tasks.

{
  "env": {
    "ANTHROPIC_AUTH_TOKEN": "sk-xxx",
    "ANTHROPIC_BASE_URL": "https://api.deepseek.com/anthropic",
    "ANTHROPIC_MODEL": "deepseek-chat",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "deepseek-reasoner",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "deepseek-chat",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "deepseek-chat",
    "CLAUDE_CODE_SUBAGENT_MODEL": "deepseek-chat",
    "CLAUDE_CODE_MAX_OUTPUT_TOKENS": "32000"
  },
  "permissions": {"allow": [], "deny": []},
  "alwaysThinkingEnabled": false
}

Routine coding: use deepseek-chat – cost down ~70%.

Complex reasoning: automatically switch to deepseek-reasoner for quality.

Sub‑agent tasks: use the economical model to lower overall spend.

Step 4 – Test Sub‑Agent Permissions

Enter the following prompt in Claude:

让 code-reviewer 修复 auth.js 中的硬编码密钥问题

The response shows that the code‑reviewer sub‑agent lacks edit/write permission, so it cannot modify auth.js.

Important Considerations

1. API Key Security

Never commit the configuration file containing the API key to a public repository.

Add the .claude folder to .gitignore.

Rotate the API key regularly to reduce leakage risk.

2. Model Choice

DeepSeek offers two main models: deepseek-chat: Fast and inexpensive, suited for daily coding, Q&A, and documentation generation. deepseek-reasoner: Strong reasoning ability, best for algorithm design, bug analysis, and architectural decisions.

3. Cost Details

DeepSeek charges per usage; refer to the official pricing page for exact rates.

Set budget alerts to avoid unexpected overspend.

You can limit token usage in the configuration to control per‑request cost.

4. Troubleshooting

Verify that the API key is valid and has sufficient balance.

Ensure network connectivity to api.deepseek.com.

Check that the JSON in settings.json is well‑formed.

Conclusion

By following these steps you can enjoy a more flexible model selection, lower API costs, and a fully compatible experience when using Claude Code with DeepSeek.

DeepSeekAPI configurationClaude CodeAI model integration
Wukong Talks Architecture
Written by

Wukong Talks Architecture

Explaining distributed systems and architecture through stories. Author of the "JVM Performance Tuning in Practice" column, open-source author of "Spring Cloud in Practice PassJava", and independently developed a PMP practice quiz mini-program.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.