> For the complete documentation index, see [llms.txt](https://docs.xxooapi.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.xxooapi.com/an-zhuang-pei-zhi.md).

# 安装配置

Windows / macOS 上从零安装 Node.js、Claude Code、Codex，并接入 xxooAPI

本章完成后你的电脑上会有：

* **Node.js** —— Claude Code / Codex 的运行环境
* **Claude Code** —— Anthropic 终端助手
* **Codex CLI** —— OpenAI 终端助手
* **CC Switch（可选）** —— 图形化切换不同 API 供应商

{% hint style="warning" %}
**开始前先退出所有翻墙 / 代理软件**（Clash、V2Ray、机场客户端等）。浏览器能上网 ≠ 终端能上网。代理是安装过程中最常见的"隐形坑"，详见 [故障排查 §代理问题](https://docs.xxooapi.com/pages/b48fd9690c5f8f5e444eb54ceb63eb889424950c#%E4%BB%A3%E7%90%86%E9%97%AE%E9%A2%98)。
{% endhint %}

## 第一步：安装 Node.js

Node.js 是 Claude Code 和 Codex 的运行环境，版本需 ≥ **v18 LTS**（推荐最新 LTS）。

### Windows

打开 PowerShell（按 `Win` → 输入 `PowerShell` → 回车），输入：

```bash
winget install OpenJS.NodeJS.LTS
```

提示确认时输入 `Y`。安装完毕后 **关闭 PowerShell 重新打开**，输入：

```bash
node -v
npm -v
```

两个版本号都能打印出来，表示安装成功。

### macOS

**方式 A：官网安装包（最简单）**

打开 [nodejs.org](https://nodejs.org/zh-cn/download)，下载 macOS 的 `.pkg` 安装包，双击安装即可。

**方式 B：Homebrew**

```bash
brew install node@20
```

完成后在终端验证：

```bash
node -v
npm -v
```

### Linux

```bash
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs
```

其他发行版参考 [NodeSource 官方说明](https://github.com/nodesource/distributions)。

## 第二步：安装 Claude Code

**macOS / Linux**

```bash
sudo npm install -g @anthropic-ai/claude-code@latest
```

**Windows**

```bash
npm install -g @anthropic-ai/claude-code@latest
```

验证：

```bash
claude --version
```

## 第三步：配置 Claude Code 连到 xxooAPI

Claude Code 通过两个环境变量知道要走 xxooAPI：

| 变量                     | 值                                                        |
| ---------------------- | -------------------------------------------------------- |
| `ANTHROPIC_BASE_URL`   | `https://www.xxooapi.com`                                |
| `ANTHROPIC_AUTH_TOKEN` | 你在 [令牌管理](https://xxooapi.com/console/token) 创建的 API Key |

### macOS / Linux

编辑你的 shell 配置文件（zsh 用户改 `~/.zshrc`，bash 用户改 `~/.bashrc`）：

```bash
echo 'export ANTHROPIC_BASE_URL="https://www.xxooapi.com"' >> ~/.zshrc
echo 'export ANTHROPIC_AUTH_TOKEN="sk-你的密钥"' >> ~/.zshrc
source ~/.zshrc
```

### Windows（PowerShell）

**永久设置**：

```powershell
[System.Environment]::SetEnvironmentVariable('ANTHROPIC_BASE_URL', 'https://www.xxooapi.com', 'User')
[System.Environment]::SetEnvironmentVariable('ANTHROPIC_AUTH_TOKEN', 'sk-你的密钥', 'User')
```

设置后 **关闭所有 PowerShell / 终端窗口重新打开** 才会生效。

### 启动 Claude Code

在任意项目目录下：

```bash
cd ~/你的项目
claude
```

首次进入会有引导，一路回车即可。出现对话提示符就可以开始了。

## 第四步：安装 Codex CLI

**macOS / Linux**

```bash
sudo npm install -g @openai/codex@latest
```

**Windows**

```bash
npm install -g @openai/codex@latest
```

## 第五步：配置 Codex 连到 xxooAPI

Codex 使用 OpenAI 协议，环境变量名略有不同：

| 变量                | 值                            |
| ----------------- | ---------------------------- |
| `OPENAI_BASE_URL` | `https://www.xxooapi.com/v1` |
| `OPENAI_API_KEY`  | 你的 xxooAPI API Key           |

**macOS / Linux**：

```bash
echo 'export OPENAI_BASE_URL="https://www.xxooapi.com/v1"' >> ~/.zshrc
echo 'export OPENAI_API_KEY="sk-你的密钥"' >> ~/.zshrc
source ~/.zshrc
```

**Windows**：同上 `[System.Environment]::SetEnvironmentVariable(...)` 写法。

启动：

```bash
codex
```

## 第六步（可选）：CC Switch 图形化管理

如果你同时用多个 API 供应商（xxooAPI、官方、其他中转），推荐 [CC Switch](https://github.com/farion1231/cc-switch)，一个开源 GUI 工具，一键切换。

**下载地址**： <https://github.com/farion1231/cc-switch/releases>

* **Windows**：`.msi` 安装包
* **macOS**：`.dmg`

**系统要求**：Windows 10+ / macOS 12+ / Ubuntu 22.04+

**添加** xxooAPI **供应商**：

{% stepper %}
{% step %}

### 打开 CC Switch

打开 CC Switch → 点右上角 `+`
{% endstep %}

{% step %}

### 选择「自定义配置」

选择「 **自定义配置**」
{% endstep %}

{% step %}

### 填写配置

* 供应商名称：`xxooapi`
* 请求地址：`https://www.xxooapi.com`（不勾选"完整 URL"）
* API Key：贴入 xxooAPI 密钥
  {% endstep %}

{% step %}

### 添加并启用

点「添加」→ 列表中点「启用」→ 点「检测」
{% endstep %}

{% step %}

### 检查结果

顶部出现绿色提示 = 配置成功
{% endstep %}
{% endstepper %}

CC Switch 会自动帮你写好 Claude Code 的配置，不需要再手动改环境变量。

## 其他工具接入

<table><thead><tr><th width="210.60711669921875">工具</th><th>Base URL</th><th>密钥字段</th></tr></thead><tbody><tr><td><strong>Cursor</strong></td><td>Settings → Models → Override OpenAI Base URL: <code>https://www.xxooapi.com/v1</code></td><td>OpenAI API Key</td></tr><tr><td><strong>Continue (VS Code)</strong></td><td><code>apiBase: "https://www.xxooapi.com/v1"</code></td><td><code>apiKey</code></td></tr><tr><td><strong>Cline (VS Code)</strong></td><td>API Provider 选 <code>OpenAI Compatible</code>，Base URL: <code>https://www.xxooapi.com/v1</code></td><td>API Key</td></tr><tr><td><strong>Gemini CLI</strong></td><td>参考工具文档，指向 <code>https://www.xxooapi.com</code></td><td>xxooAPI Key</td></tr><tr><td><strong>JetBrains AI Assistant</strong></td><td>通过 Continue 插件或 Proxy 配置</td><td>xxooAPI Key</td></tr></tbody></table>

## 验证一切正常

在 Claude Code 或 Codex 里问一句：

```bash
你现在用的是什么模型？
```

如果它回答了一个模型名（比如 `claude-sonnet-4-6`），说明整条链路打通。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.xxooapi.com/an-zhuang-pei-zhi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
