Featured image of post claude code cli安装使用与接入第三方模型

claude code cli安装使用与接入第三方模型

claude code cli安装使用与接入第三方模型

claude code cli安装使用与接入第三方模型

1. 安装 Claude Code

若已安装,可跳至下一节。

1.1 第一步:安装 Git for Windows(必需)

⚠️ 重要:Claude Code 在 Windows 上依赖 Git Bash 运行,必须先安装 Git。

1.1.1 下载 Git

访问 Git 官网下载页面:

1
https://git-scm.com/downloads/win

点击下载最新的 64 位版本

1.1.2 安装 Git

  1. 双击下载的安装文件(如 Git-2.51.2-64-bit.exe
  2. 全程使用默认选项,一路点击 “Next”
  3. 确保在 “Adjusting your PATH environment” 步骤中选择:
    • “Git from the command line and also from 3rd-party software”(默认选项)
  4. 点击 “Install” 开始安装
  5. 完成后点击 “Finish”

1.1.3 验证 Git 安装

  1. Win + R
  2. 输入 cmd,按回车
  3. 在命令提示符中输入:
1
git --version

✅ 如果显示类似 git version 2.51.2.windows.1,说明安装成功。


1.2 第二步:安装 Claude Code

1.2.1 以管理员身份打开 PowerShell

  1. Win
  2. 输入 powershell
  3. 右键点击 “Windows PowerShell”
  4. 选择 “以管理员身份运行”

1.2.2 运行安装命令

在 PowerShell 中复制并运行以下命令:

1
irm https://claude.ai/install.ps1 | iex

1.2.3 等待安装完成

安装过程会显示进度信息,完成后会显示:

1
2
3
✅ Installation complete!
Version: 2.0.34
Location: C:\Users\你的用户名\.local\bin\claude.exe

1.3 第三步:配置环境变量(添加 PATH)

安装完成后需要将 Claude 添加到系统 PATH,这样才能在任何地方运行 claude 命令。

1.3.1 方法一:图形界面操作(推荐新手)

  1. Win + R,输入 sysdm.cpl,按回车
  2. 点击 “高级” 标签
  3. 点击 “环境变量” 按钮
  4. “用户变量” 区域(窗口上半部分),找到并双击 Path
  5. 点击 “新建” 按钮
  6. 输入:C:\Users\你的用户名\.local\bin
    • 你的用户名 替换为实际的 Windows 用户名
  7. 依次点击 “确定” 关闭所有窗口

1.3.2 方法二:PowerShell 命令(快速)

在 PowerShell(管理员模式)中运行:

1
[Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\Users\$env:USERNAME\.local\bin", "User")

1.4 第四步:验证安装

1.4.1 重启 PowerShell

⚠️ 必须关闭所有 PowerShell 窗口并重新打开,PATH 修改才会生效。

1.4.2 测试命令

打开新的 PowerShell 窗口,输入:

1
claude --version

✅ 如果显示版本号(如 2.0.34),说明安装成功!

2. 初始化配置

1
2
3
4
5
6
7
8
9
node --eval "
    const homeDir = os.homedir();
    const filePath = path.join(homeDir, '.claude.json');
    if (fs.existsSync(filePath)) {
        const content = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
        fs.writeFileSync(filePath, JSON.stringify({ ...content, hasCompletedOnboarding: true }, null, 2), 'utf-8');
    } else {
        fs.writeFileSync(filePath, JSON.stringify({ hasCompletedOnboarding: true }), 'utf-8');
    }"

如果终端提示 fnm 命令未找到,请重新打开终端窗口再执行后续命令。

2.1 Windows

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 打开 windows 终端中的 powershell 终端
# windows 上安装 nodejs
# 右键按 Windows 按钮,点击「终端」

# 然后依次执行下面的
winget install --id Git.Git -e --source winget # 或者参考 https://git-scm.com/install/windows 用其他办法安装 Git
winget install OpenJS.NodeJS # 或者参考 https://nodejs.org/zh-cn/download 用其他办法安装 Node.js
Set-ExecutionPolicy -Scope CurrentUser RemoteSigned

# 然后关闭终端窗口,新开一个终端窗口


# 初始化配置
node --eval "
    const homeDir = os.homedir();
    const filePath = path.join(homeDir, '.claude.json');
    if (fs.existsSync(filePath)) {
        const content = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
        fs.writeFileSync(filePath, JSON.stringify({ ...content, hasCompletedOnboarding: true }, null, 2), 'utf-8');
    } else {
        fs.writeFileSync(filePath, JSON.stringify({ hasCompletedOnboarding: true }), 'utf-8');
    }"

3. 配置 Kimi For Coding 模型

完成 Claude Code 安装后,按以下方式设置环境变量使用 Kimi For Coding 模型。

3.1 macOS 与 Linux

1
2
3
4
export ANTHROPIC_BASE_URL=https://api.kimi.com/coding/
export ANTHROPIC_AUTH_TOKEN=sk-kimi-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx  # 这里填在会员页面生成的 API Key

claude

3.2 Windows

1
2
3
4
$env:ANTHROPIC_BASE_URL="https://api.kimi.com/coding/";
$env:ANTHROPIC_AUTH_TOKEN="sk-kimi-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"  # 这里填在会员页面生成的 API Key

claude

4. 确认环境变量是否生效

启动 Claude Code 后,在命令输入框输入 /status,确认模型状态。

接下来就可以使用 Claude Code 进行开发了!

Licensed under CC BY-NC-SA 4.0
最后更新于 Nov 16, 2025 01:00 UTC
this is the end :)