怎么让claude code用国内的模型

之前体验过gemini code这个工具,谷歌还算比较友好,有token,有网络就可以用,claude code目前是个很严格,而且这家公司也对国内用户很不友好
所以就研究了下怎么把它对接上国内的模型
幸好之前deepseek发布v3.1的时候天然给了支持

1
2
3
4
5
6
7
8
## 由deepseek提供的兼容claude code的base url
export ANTHROPIC_BASE_URL=https://api.deepseek.com/anthropic
## deepseek的token
export ANTHROPIC_AUTH_TOKEN={token}
## 对应的deepseek-chat模型,这个是非推理的
export ANTHROPIC_MODEL=deepseek-chat
## 快速小模型(同样可设为 deepseek-chat)
export ANTHROPIC_SMALL_FAST_MODEL=deepseek-chat

如果需要设置乘推理型的
可以把模型改成

1
export ANTHROPIC_MODEL=deepseek-reasoner

当然这个如果要长久有效得放在 .zshrc ,根据所用的shell工具来设置
然后安装claude需要node版本在18及以上

1
2
nvm use v18
npm install -g @anthropic-ai/claude-code

安装以后到想要开发的项目
运行

1
claude

接下来我们同样以todo应用作为测试应用

1
帮我写一个todo应用,使用react,ui需要尽可能美观

只是加了个美观的要求

1
2
3
4
5
6
7
8
⏺ Update Todos
⎿  ☐ Set up React project structure and dependencies
☐ Create main Todo component with state management
☐ Design and implement beautiful UI with CSS/styling
☐ Add todo functionality (add, delete, toggle complete)
☐ Test the application

⏺ Let me start by checking the current directory structure and then create the React todo application.

首先它分了五步
然后逐步运行对应的动作,生成文件等

生成的还是比较美观可用的,说明国内模型在简单的编码任务上也具有比较不错的能力了