How to use Claude Code with DeepSeek, Kimi, GLM, Qwen, and MiniMax
本文为原文前 6,000 字符的节选翻译,完整内容请查看原文。
Originally published at alwaysagent.app. The original is kept up to date. Claude Code is a terminal coding agent, not a single locked-in model. Because DeepSeek, Moonshot (Kimi), Z.ai (GLM), Alibaba Cloud Model Studio (Qwen), and MiniMax all publish official Anthropic-compatible endpoints, you can connect Claude Code to any of them with a base URL, an API key, and a model mapping.
本文最初发布于 alwaysagent.app,原文会保持更新。Claude Code 是一个终端编码代理,而非单一锁定的模型。由于 DeepSeek、月之暗面 (Kimi)、智谱 AI (GLM)、阿里云百炼 (Qwen) 和 MiniMax 都发布了官方兼容 Anthropic 的端点,你可以通过基础 URL、API 密钥和模型映射将 Claude Code 连接到其中任何一个平台。
The short answer: why it works You can use Claude Code with DeepSeek, Kimi, GLM, Qwen, and MiniMax without installing a third-party proxy or modifying the CLI. It works because all five providers publish official endpoints that speak Anthropic’s Messages API format natively. Claude Code separates the local terminal harness (reading files, editing code, running shell commands, and managing context) from the remote language model.
简短的回答:为什么可行?你可以在不安装第三方代理或修改 CLI 的情况下,将 Claude Code 与 DeepSeek、Kimi、GLM、Qwen 和 MiniMax 一起使用。之所以可行,是因为这五家提供商都发布了原生支持 Anthropic Messages API 格式的官方端点。Claude Code 将本地终端工具(读取文件、编辑代码、运行 shell 命令和管理上下文)与远程语言模型分离开来。
When you change two environment variables—where the request goes and how it authenticates—Claude Code sends its standard Anthropic-formatted requests to the new provider instead of Anthropic’s servers. These compatible endpoints are maintained by each model provider, not by Anthropic. Anthropic’s documentation states that it does not support or guarantee Claude Code when routed to non-Claude models. Always test a provider on a small task before relying on it for production work.
当你更改两个环境变量(请求发送的目标地址以及身份验证方式)时,Claude Code 会将其标准的 Anthropic 格式请求发送给新的提供商,而不是 Anthropic 的服务器。这些兼容端点由各模型提供商维护,而非 Anthropic。Anthropic 的文档声明,当 Claude Code 被路由到非 Claude 模型时,它不支持也不提供保证。在依赖某个提供商进行生产工作之前,请务必先在小任务上进行测试。
How the configuration works Every Anthropic-compatible provider setup relies on the same group of Claude Code environment variables. You can export them in your shell profile or place them inside the env block of your Claude Code settings file. ANTHROPIC_BASE_URL: Points Claude Code at the provider’s Anthropic-compatible endpoint instead of https://api.anthropic.com. ANTHROPIC_AUTH_TOKEN: Holds your provider API key. Claude Code sends this value as an Authorization: Bearer header. ANTHROPIC_MODEL: Sets the primary active model for your session.
配置是如何工作的:每个兼容 Anthropic 的提供商设置都依赖于同一组 Claude Code 环境变量。你可以在 shell 配置文件中导出它们,或者将它们放在 Claude Code 设置文件的 env 块中。ANTHROPIC_BASE_URL:将 Claude Code 指向提供商兼容 Anthropic 的端点,而不是 https://api.anthropic.com。ANTHROPIC_AUTH_TOKEN:存放你的提供商 API 密钥。Claude Code 会将此值作为 Authorization: Bearer 标头发送。ANTHROPIC_MODEL:设置会话的主要活动模型。
ANTHROPIC_DEFAULT_OPUS_MODEL, ANTHROPIC_DEFAULT_SONNET_MODEL, and ANTHROPIC_DEFAULT_HAIKU_MODEL: Map Claude Code’s internal model tiers (used when you switch aliases or when Claude Code runs background tasks) to specific model IDs on your chosen provider. CLAUDE_CODE_SUBAGENT_MODEL: Sets the default model for subagents that are not assigned a model another way. ANTHROPIC_DEFAULT_FABLE_MODEL: Maps the fable alias. Moonshot’s guide sets it too, so set it if your provider’s guide does.
ANTHROPIC_DEFAULT_OPUS_MODEL、ANTHROPIC_DEFAULT_SONNET_MODEL 和 ANTHROPIC_DEFAULT_HAIKU_MODEL:将 Claude Code 的内部模型层级(在你切换别名或 Claude Code 运行后台任务时使用)映射到你所选提供商的具体模型 ID。CLAUDE_CODE_SUBAGENT_MODEL:为未以其他方式分配模型的子代理设置默认模型。ANTHROPIC_DEFAULT_FABLE_MODEL:映射 fable 别名。月之暗面的指南也设置了它,因此如果你的提供商指南中包含此项,请务必设置。
Putting these variables in ~/.claude/settings.json is the cleanest approach for a single default provider. It applies every time you launch claude, including background subagents. Use ANTHROPIC_AUTH_TOKEN, not ANTHROPIC_API_KEY: Provider guides use ANTHROPIC_AUTH_TOKEN. Leaving an old ANTHROPIC_API_KEY exported in your shell causes authentication conflicts because Claude Code sends it as an x-api-key header.
对于单一默认提供商而言,将这些变量放入 ~/.claude/settings.json 是最整洁的方法。它适用于你每次启动 claude 时,包括后台子代理。请使用 ANTHROPIC_AUTH_TOKEN,而不是 ANTHROPIC_API_KEY:提供商指南使用的是 ANTHROPIC_AUTH_TOKEN。在 shell 中保留旧的 ANTHROPIC_API_KEY 导出会导致身份验证冲突,因为 Claude Code 会将其作为 x-api-key 标头发送。
Clear saved logins: If you previously signed in with a claude.ai subscription, run /logout inside Claude Code so your token and base URL take over cleanly. Keep keys out of Git: Put credentials in ~/.claude/settings.json (user scope) or .claude/settings.local.json (git-ignored project scope). Never put API keys in a shared project .claude/settings.json file that gets committed to version control.
清除已保存的登录信息:如果你之前使用 claude.ai 订阅登录过,请在 Claude Code 内运行 /logout,以便你的令牌和基础 URL 能顺利接管。不要将密钥放入 Git:将凭据放入 ~/.claude/settings.json(用户范围)或 .claude/settings.local.json(被 git 忽略的项目范围)。切勿将 API 密钥放入会被提交到版本控制系统的共享项目 .claude/settings.json 文件中。
Mind variable precedence: When the same variable is set in both your shell and a settings file env block, Claude Code applies the settings file value in most sessions. Providers such as MiniMax and Moonshot still recommend clearing old export ANTHROPIC_* lines from ~/.zshrc or ~/.bashrc first, because stale values can conflict with the new setup.
注意变量优先级:当同一个变量同时在 shell 和设置文件的 env 块中设置时,Claude Code 在大多数会话中会应用设置文件中的值。MiniMax 和月之暗面等提供商仍然建议先从 ~/.zshrc 或 ~/.bashrc 中清除旧的 export ANTHROPIC_* 行,因为过时的值可能会与新设置冲突。
DeepSeek setup DeepSeek provides an official Anthropic-compatible endpoint at https://api.deepseek.com/anthropic. Its API documentation includes a dedicated Claude Code integration guide and supports automatic model name mapping if you pass standard Claude aliases. Create an API key in the DeepSeek Platform console, then add the configuration from DeepSeek’s Claude Code guide to ~/.claude/settings.json:
DeepSeek 设置:DeepSeek 在 https://api.deepseek.com/anthropic 提供了一个官方兼容 Anthropic 的端点。其 API 文档包含专门的 Claude Code 集成指南,如果你传递标准的 Claude 别名,它还支持自动模型名称映射。在 DeepSeek 平台控制台中创建 API 密钥,然后将 DeepSeek 的 Claude Code 指南中的配置添加到 ~/.claude/settings.json:
~/.claude/settings.json (DeepSeek) { “env”: { “ANTHROPIC_BASE_URL”: “https://api.deepseek.com/anthropic”, “ANTHROPIC_AUTH_TOKEN”: “YOUR_DEEPSEEK_API_KEY”, “ANTHROPIC_MODEL”: “deepseek-flash[1m]”, “ANTHROPIC_DEFAULT_OPUS_MODEL”: “deepseek-flash[1m]”, “ANTHROPIC_DEFAULT_SONNET_MODEL”: “deepseek-flash[1m]”, “ANTHROPIC_DEFAULT_HAIKU_MODEL”: “deepseek-flash”, “CLAUDE_CODE_SUBAGENT_MODEL”: “deepseek-flash”, “CLAUDE_CODE_EFFORT_LEVEL”: “max”, “CLAUDE_CODE_AUTO_COMPACT_WINDOW”: “786432” } }
(此处为 ~/.claude/settings.json (DeepSeek) 的配置代码块)
Available models: DeepSeek’s Anthropic endpoint supports deepseek-flash and deepseek-v4-pro. Built-in alias fallback: DeepSeek notes that if an unmapped claude-* model name reaches its endpoint, names starting with claude-opus are automatically mapped to deepseek-v4-pro, and claude-sonnet or claude-haiku names are mapped to deepseek-flash. Non-Claude model names that DeepSeek does not recognize return a 400 error. Context suffix: Appending [1m] tells Claude Code to treat the model as having a 1M context window rather than capping sessions at 200k.
可用模型:DeepSeek 的 Anthropic 端点支持 deepseek-flash 和 deepseek-v4-pro。内置别名回退:DeepSeek 指出,如果未映射的 claude-* 模型名称到达其端点,以 claude-opus 开头的名称会自动映射到 deepseek-v4-pro,而 claude-sonnet 或 claude-haiku 名称会映射到 deepseek-flash。DeepSeek 无法识别的非 Claude 模型名称会返回 400 错误。上下文后缀:附加 [1m] 会告诉 Claude Code 将该模型视为拥有 1M 上下文窗口,而不是将会话限制在 200k。
Kimi (Moonshot AI) setup Moonshot AI serves Kimi models (including Kimi K3) through an Anthropic-compatible endpoint at https://api.moonshot.ai/anthropic. You can generate an API key in the Kimi platform console at platform.kimi.ai. Moonshot’s official Claude Code guide maps every Claude Code model tier in ~/.claude/settings.json so background tasks and subagents do not fall back to unmapped Claude model names:
Kimi (月之暗面) 设置:月之暗面通过 https://api.moonshot.ai/anthropic 的兼容 Anthropic 端点提供 Kimi 模型(包括 Kimi K3)。你可以在 platform.kimi.ai 的 Kimi 平台控制台中生成 API 密钥。月之暗面的官方 Claude Code 指南在 ~/.claude/settings.json 中映射了每一个 Claude Code 模型层级,这样后台任务和子代理就不会回退到未映射的 Claude 模型名称:
~/.claude/settings.json (Kimi) { “env”: { “ANTHROPIC_BASE_URL”: “https://api.moonshot.ai/anthropic”, “ANTHROPIC_AUTH_TOKEN”: “YOUR_MOONSHOT_API_KEY”, “ANTHROPIC_MODEL”: “kimi-k3[1m]”, “ANTHROPIC_DEFAULT_OPUS_MODEL”: “kimi-k3[1m]”, “ANTHROPIC_DEFAULT_SONNET_MODEL”: “kimi-k3[1m]”, “ANTHROPIC_DEFAULT_HAIKU_MODEL”: “kimi-k3[1m]”, “ANTHROPIC_DEFAULT_FABLE_MODEL”: “kimi-k3[1m]”, “CLAUDE_CODE_SUBAGENT_MODEL”: “kimi-k3[1m]”, “CLAUDE_CODE_AUTO_COMPACT_WINDOW”: “1000000”, “CLAUDE_CODE_EFFORT_LEVEL”: “max” } }
(此处为 ~/.claude/settings.json (Kimi) 的配置代码块)
Model and thinking: Moonshot’s guide uses kimi-k3[1m] for every tier. Kimi K3 always reasons, so no separate thinking parameter is
模型与思考:月之暗面的指南在每个层级都使用了 kimi-k3[1m]。Kimi K3 始终会进行推理,因此没有单独的思考参数。