Claude Code Deepseek
**Claude Code** is an AI programming assistant launched by Anthropic that runs in the terminal. It supports configuring third-party compatible APIs through environment variables, allowing access to models like DeepSeek.\n\nThis article introduces how to use Claude Code with **DeepSeek** to gain powerful AI-assisted programming capabilities at a lower cost.\n\nKey points:\n\n* Claude Code points to the DeepSeek compatible interface via the **ANTHROPIC_BASE_URL** environment variable.\n* DeepSeek provides an interface compatible with the Anthropic API, with the path `https://api.deepseek.com/anthropic`.\n* Through a set of environment variables, models at different tiers (Opus / Sonnet / Haiku) can be mapped to corresponding DeepSeek models.\n* Once configured, simply execute the `claude` command in your project directory to start using it.\n\nIn short: **Claude Code + DeepSeek = Terminal AI Programming Assistant + Cost-effective Large Model**\n\n* **Claude Code**: Provides a complete terminal AI programming interactive experience, supporting code generation, refactoring, debugging, explanation, etc.\n* **DeepSeek API**: Provides an Anthropic-compatible interface, supporting DeepSeek series model calls.\n* **Environment Variable Bridging**: Connects the two through standard environment variables without modifying any Claude Code source code.\n\n### Prerequisites\n\n**If you have already installed Claude Code, you can skip this step.**\n\n* [Node.js](https://nodejs.org/zh-cn/download/) version 18 or above is installed.\n* Windows users also need to install (https://git-scm.com/download/win) (provides the bash environment).\n* An account has been registered and an API Key has been created on the (https://platform.deepseek.com/api_keys).\n\nExecute the following command in the command line interface to install Claude Code:\n\ncurl -fsSL https://claude.ai/install.sh | bash\nAfter installation, execute the following command to verify. If the version number is output normally, the installation is successful:\n\nclaude --version\n> If you encounter permission issues, Linux / macOS users can add `sudo` before the command.\n> \n> \n> If there is a login verification, you can find the .claude.json file in the user directory:\n> \n> \n> * macOS/Linux: ~/.claude.json\n> * Windows: C:UsersYourUsername.claude.json\n> \n> { "hasCompletedOnboarding": true}\n> !(#)\n> \n> \n> After saving, restart the terminal and run:\n> \n> claude\n> The window / prompt to log in to claude.ai will no longer pop up.\n\n### Get DeepSeek API Key\n\nGo to (https://platform.deepseek.com/api_keys), log in, and create an API Key. Save it securely; it will be needed when configuring environment variables.\n\n!(#)\n\n> The API Key has account operation permissions. Do not commit it to a code repository or share it with others. It is recommended to use the operating system's key management tools or environment variable files (such as `.env`) for management, and add related files to `.gitignore`.\n\n* * *\n\n## Configure Environment Variables\n\nClaude Code interfaces with the DeepSeek API through the following environment variables. The meaning of each variable is as follows:\n\n| Environment Variable | Description |\n| --- | --- |\n| `ANTHROPIC_BASE_URL` | Points to the DeepSeek interface address compatible with the Anthropic protocol |\n| `ANTHROPIC_AUTH_TOKEN` | Your DeepSeek API Key |\n| `ANTHROPIC_MODEL` | The model used by default |\n| `ANTHROPIC_DEFAULT_OPUS_MODEL` | The model mapped to the Opus tier (complex reasoning tasks) |\n| `ANTHROPIC_DEFAULT_SONNET_MODEL` | The model mapped to the Sonnet tier (daily programming tasks) |\n| `ANTHROPIC_DEFAULT_HAIKU_MODEL` | The model mapped to the Haiku tier (fast, lightweight tasks) |\n| `CLAUDE_CODE_SUBAGENT_MODEL` | The model used by the sub-task Agent (a faster model is recommended) |\n| `CLAUDE_CODE_EFFORT_LEVEL` | Thinking depth, options are `low` / `medium` / `max` |\n\n### Linux / macOS\n\nExecute the following commands in the terminal (replace `` with your actual Key):\n\nexport ANTHROPIC_BASE_URL=https://api.deepseek.com/anthropicexport ANTHROPIC_AUTH_TOKEN=export ANTHROPIC_MODEL=deepseek-v4-proexport ANTHROPIC_DEFAULT_OPUS_MODEL=deepseek-v4-proexport ANTHROPIC_DEFAULT_SONNET_MODEL=deepseek-v4-proexport ANTHROPIC_DEFAULT_HAIKU_MODEL=deepseek-v4-flash export CLAUDE_CODE_SUBAGENT_MODEL=deepseek-v4-flash export CLAUDE_CODE_EFFORT_LEVEL=max\n> The above `export` commands only take effect in the current terminal session.\n> \n> \n> To make them permanent, you can append the above commands to the end of the `~/.bashrc` (Bash) or `~/.zshrc` (Zsh) file, and then execute `source ~/.bashrc` to make them take effect immediately.\n\n### Windows (PowerShell)\n\nExecute the following commands in PowerShell:\n\n$env:ANTHROPIC_BASE_URL="https://api.deepseek.com/anthropic" $env:ANTHROPIC_AUTH_TOKEN="" $env:ANTHROPIC_MODEL="deepseek-v4-pro" $env:ANTHROPIC_DEFAULT_OPUS_MODEL="deepseek-v4-pro" $env:ANTHROPIC_DEFAULT_SONNET_MODEL="deepseek-v4-pro" $env:ANTHROPIC_DEFAULT_HAIKU_MODEL="deepseek-v4-flash" $env:CLAUDE_CODE_SUBAGENT_MODEL="deepseek-v4-flash" $env:CLAUDE_CODE_EFFORT_LEVEL="max"\n> PowerShell's `$env:` assignment only takes effect for the current session. To make it permanent, you can add the corresponding user environment variables in "System Properties β Environment Variables", or write the above commands into the PowerShell Profile file (`$PROFILE`).\n\n### Verify if it takes effect\n\nAfter configuration, start Claude Code and execute the /status command to verify:\n\n$ cd Your project directory $ claude /status\nIf configured correctly, you will see output similar to the following:\n\nBase URL: https://api.deepseek.com/anthropicModel: deepseek-v4-proSmall fast model: deepseek-v4-flash\nSeeing this information indicates that the configuration is successful, and Claude Code is now using DeepSeek V4 for inference.\n\n> If the displayed information is not as above, please check item by item: whether the environment variables are set correctly, whether the API Key is valid, and whether there are typos in the variable names.\n\n* * *\n\n## Start Using\n\nNavigate to your project directory and execute the `claude` command to start Claude Code:\n\ncd /path/to/my-project claude\nAfter a successful start, the terminal will enter Claude Code's interactive interface. You can directly describe your programming needs in natural language, for example:\n\n!(#)\n\n# Let Claude Code explain the current project structure> Help me sort out the directory structure of this project and the role of the main modules# Generate code> Add a method to user.go to query users by email, and supplement it with unit tests# Debug issues> An error occurred after running npm test, help me analyze the cause and fix it\n\n* * *\n\n## Reference Configuration\n\n### Complete Environment Variables\n\n| Environment Variable | Value | Required | Description |\n| --- | --- | --- | --- |\n| ANTHROPIC_BASE_URL | https://api.deepseek.com/anthropic | Yes | API endpoint address, pointing to DeepSeek's Anthropic-compatible interface |\n| ANTHROPIC_AUTH_TOKEN | sk-your-api-key | Yes | DeepSeek API Key, used for authentication |\n| ANTHROPIC_MODEL | deepseek-v4-pro | Yes | Main model name, indicates a 1M context window |\n| ANTHROPIC_SMALL_FAST_MODEL | deepseek-v4-flash | Yes | Fast model used by sub-agents |\n\n### Model Name Quick Reference\n\n| Model Name | Capability | Context Window | Applicable Scenarios |\n| --- | --- | --- | --- |\n| deepseek-v4-pro | Strongest reasoning | 1M tokens | Complex architecture design, deep code review, difficult debugging |\n| deepseek-v4-flash | Fast reasoning | 1M tokens | Batch file generation, simple CRUD, documentation writing |\n\n### Shell Configuration File Path Quick Reference\n\n| Shell | Configuration File Path | Command to Take Effect |\n| --- | --- | --- |\n| zsh (macOS default) | ~/.zshrc | source ~/.zshrc |\n| bash (Linux default) | ~/.bashrc | source ~/.bashrc |\n| PowerShell (Windows) |
YouTip