Connect Claude Code & Codex to DeepSeek V4 Pro: Config, Cost Analysis & Verification
This guide details how to configure Claude Code and Codex to use DeepSeek V4 Pro instead of official APIs, covering client installation, API key setup, three configuration methods (CC Switch, official scripts, manual), model pricing comparisons with cost calculations for long tasks, verification steps, and troubleshooting common issues.
Overview
This article explains how to connect the popular AI coding agents Claude Code and Codex to domestic Chinese models, using DeepSeek V4 Pro as the primary example. Domestic users often face barriers with Anthropic and OpenAI services including regional availability, network connectivity, payment methods, and rising token costs for long-running agent tasks. Integrating domestic models preserves the clients' file access, terminal, tool-calling, and task-loop capabilities while routing model requests to a local provider.
Important boundary: client capabilities and model capabilities are not fully equivalent. Even with API compatibility, third-party models may differ in tool calling, reasoning messages, context compression, vision input, or built-in tools. Code, documents, and conversations sent to the new provider fall under their data processing terms; verify organizational policies before handling sensitive code.
Prerequisites
Install Clients
Both Claude Code and Codex offer desktop apps and CLIs. Desktop apps are more intuitive; CLIs suit project-directory work and automation.
Codex desktop: https://chatgpt.com/codex/ Claude Code desktop: https://claude.com/download Codex CLI install (macOS/Linux):
curl -fsSL https://chatgpt.com/codex/install.sh | shOr via npm: npm install -g @openai/codex. Verify with codex --version. Start in a project directory: cd /path/to/project && codex. First run may prompt login; exit because we'll switch to DeepSeek API.
Claude Code CLI install (macOS/Linux/WSL): curl -fsSL https://claude.ai/install.sh | bash Windows PowerShell: irm https://claude.ai/install.ps1 | iex. Or with Node.js 22+: npm install -g @anthropic-ai/claude-code (do not use sudo). Verify with claude --version and claude doctor. Start: cd /path/to/workspace && claude. Confirm codex --version and claude --version output before proceeding.
Create DeepSeek API Key
Register and log in to DeepSeek Open Platform.
Add a small balance.
Go to API Keys page.
Create a new API Key.
Copy immediately and store securely (password manager, keychain, secret manager). Do not write to plain notes, commit to Git, or expose in screenshots.
Placeholder used in examples: <your DeepSeek API Key> (replace without angle brackets).
Manage Multiple Configurations with CC Switch
CC Switch is an open-source third-party tool that manages provider configurations for Claude Code, Claude Desktop, and Codex. It reads/writes local configs and stores credentials. Download from https://ccswitch.io. If you only need one provider or prefer not to use a third-party credential manager, skip to manual configuration sections.
In CC Switch's Codex panel, click "+", select DeepSeek, enter API Key, save, and enable. Restart Codex fully and test connection. For Claude Code CLI, similar steps in the Claude Code panel. For Claude Desktop, model mapping is required because DeepSeek model names don't match Claude's native Sonnet/Opus/Haiku roles. Enable "Model Mapping" and map roles to actual DeepSeek models. Then enable local routing (listens on http://127.0.0.1:15721), restart Claude Desktop. Notes: mapping mode requires CC Switch and local routing running; direct mode doesn't. Claude Desktop doesn't support hot reload; full restart needed. Linux not supported for Claude Desktop config in CC Switch.
Codex CLI & Desktop App: Connect to DeepSeek
Method 1: CC Switch (covered above)
Method 2: DeepSeek Official Script
macOS/Linux:
bash <(curl -fsSL https://cdn.deepseek.com/api-docs/codex-deepseek-setup-en.sh)Windows PowerShell:
irm https://cdn.deepseek.com/api-docs/codex-deepseek-setup-en.ps1 | iexScript steps: select deepseek-v4-pro, enter API Key, wait for config and syntax validation, fully restart Codex. Script backs up original config.toml to ~/.codex/backup-deepseek/, generates ~/.codex/models.json, adds DeepSeek provider to config.toml, preserves MCP servers and project trust, validates TOML/JSON syntax, provides restore option. Security note: curl | bash executes remote script; in high-security environments, download, inspect, then run manually.
Method 3: Manual Configuration
Step 1: Save official model catalog to ~/.codex/models.json (copy from DeepSeek Codex integration page to avoid missing metadata like context windows, reasoning tiers, tool formats).
Step 2: Set API Key environment variable.
macOS/Linux: export DEEPSEEK_API_KEY="<your DeepSeek API Key>" Windows PowerShell: $env:DEEPSEEK_API_KEY="<your DeepSeek API Key>" Step 3: Edit ~/.codex/config.toml:
model = "deepseek-v4-pro"Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Shepherd Advanced Notes
Dedicated to sharing advanced Java technical insights, daily work snippets, and the power of persistent effort.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
