第一步:准备 Node.js 环境
Claude Code 要求 Node.js 版本在 18.19.0 或 20.0.0 以上。
检查版本:
node -v
切换镜像源(核心步骤):
为了避免安装过程中因为连接 GitHub 或 NPM 官方仓库失败,建议先切换到淘宝(腾讯/华为)镜像:
Bash
npm config set registry https://registry.npmmirror.com
第二步:安装 Claude Code
使用全局安装命令:
npm install -g @anthropic-ai/claude-code
如果遇到权限错误,Linux/macOS 用户请在前面加 sudo。
第三步:配置 API 网络代理(关键)
由于 Claude Code 在终端运行,它不会自动走你浏览器的代理插件。你需要为终端配置系统代理,以便它能连接到 Anthropic 的服务器。
在终端执行(假设你的代理端口是 7890):
Windows (PowerShell):
PowerShell
$env:HTTP_PROXY=”http://127.0.0.1:7890″
$env:HTTPS_PROXY=”http://127.0.0.1:7890″
Linux / macOS / Git Bash:
export http_proxy=http://127.0.0.1:7890
export https_proxy=http://127.0.0.1:7890
第四步:初始化与认证
在终端输入以下命令启动:
claude
登录: 它会弹出一个链接(或要求你复制验证码),引导你到 Anthropic 官网进行授权。
API Key: 确保你的 Anthropic 账户有可用额度(Credits),Claude Code 目前不占用 Claude Pro 网页版的订阅额度,而是按 API 使用量扣费。
第五步:切换成deepseek
1/ 跳过检查
C:\Users\Administrator\.claude.json
{
…
“hasCompletedOnboarding”: true
}
2/ 创建 api key
3/ 设置用户id
# 设置一个只包含英文字母的临时 ID
$env:CLAUDE_USER_ID=“Developer001”
❯ 在windows下Claude Code 会自动抓取你电脑的 “计算机名” 或 “系统用户名” 作为 API 请求的标识,有可能报以下错误
⎿ API Error: 400 Invalid ‘user_id’: string does not match pattern. Expected a string that matches the pattern ‘^[a-zA-Z0-9_-]+$’.
4/ 进入项目目录,重新运行claude