> ## Documentation Index
> Fetch the complete documentation index at: https://docs.preview.x6.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Claude Code

> 通过 x6.ai 使用 Claude Code — 从 Credits 中扣费，无需 Anthropic 订阅。

> 本文档仅供参考，演示如何配置我们的 API 与第三方 AI 聊天界面配合使用。文中提及的任何第三方软件、网站或服务均非由我们运营、控制或背书。

# **Claude Code 简介**

<Frame>
  <img src="https://mintcdn.com/x6/el_h-gJpYp66h95k/images/demo.webp?fit=max&auto=format&n=el_h-gJpYp66h95k&q=85&s=410904bb94b5744d371a53c677ffa2ca" alt="Demo" width="1200" height="767" data-path="images/demo.webp" />
</Frame>

[**Claude Code**](https://github.com/anthropics/claude-code) 是一款驻留在终端中的智能编程工具，能理解您的代码库，通过执行日常任务、解释复杂代码和处理 git 工作流来帮助您更快地编写代码——一切均通过自然语言命令完成。

**Claude Code** 核心特性：

* **自主行动**：直接读写文件、运行终端命令并修复 Bug。
* **完整上下文**：自动理解整个代码库，无需手动复制粘贴。
* **安全与控制**：支持一键回滚，关键操作需手动审批。
* **工具集成**：通过 SKILL.md 支持自定义复杂工作流。

## **步骤**

<Steps>
  <Step title="安装 Claude Code" stepNumber={1}>
    > 如果你已经安装了 Claude Code，请在 terminal 中运行以下命令更新到最新版，这可能需要管理员权限。

    ```shellscript theme={null}
    claude update
    ```

    <Tabs>
      <Tab title="CLI - Node.js">
        你可以**手动**安装 Node.js 和对应的 Coding Agent：

        首先安装 [最新 LTS 版本的 Node.js](https://nodejs.org/en/download/)，然后在终端中使用 npm 全局安装：

        ```shellscript theme={null}
        npm install -g @anthropic-ai/claude-code
        ```
      </Tab>

      <Tab title="CLI - 原生安装">
        **macOS、Linux、WSL：**

        ```shellscript theme={null}
        curl -fsSL https://claude.ai/install.sh | bash
        ```

        **Windows PowerShell：**

        ```powershell theme={null}
        irm https://claude.ai/install.ps1 | iex
        ```

        **Windows CMD：**

        ```powershell theme={null}
        curl -fsSL https://claude.ai/install.cmd -o install.cmd && install.cmd && del install.cmd

        ```

        如果看到 `The token '&&' is not a valid statement separator`，说明您在 PowerShell 而非 CMD 中。如果看到 `'irm' is not recognized as an internal or external command`，说明您在 CMD 而非 PowerShell 中。PowerShell 提示符显示 `PS C:\`，CMD 提示符显示 `C:\`（无 `PS`）。

        **原生 Windows 安装需要 [Git for Windows](https://git-scm.com/downloads/win)。** 如果尚未安装，请先安装它。WSL 安装不需要此步骤。

        原生安装会在后台自动更新，始终保持最新版本。
      </Tab>

      <Tab title="VS Code 扩展">
        从 [VS Code](https://code.visualstudio.com/download) 应用市场**安装** [**Claude Code** 扩展](https://marketplace.visualstudio.com/items?itemName=anthropic.claude-code) — 无需单独安装 CLI。VS Code 扩展直接在编辑器中提供内联差异、@-mentions、计划审查和对话历史。

        <Frame>
          <img src="https://mintcdn.com/x6/el_h-gJpYp66h95k/images/image-94.webp?fit=max&auto=format&n=el_h-gJpYp66h95k&q=85&s=003be267b368eab35b581c720e194e0e" alt="Image" width="1600" height="955" data-path="images/image-94.webp" />
        </Frame>
      </Tab>

      <Tab title="Desktop App">
        请按照[**官方教程**](https://code.claude.com/docs/en/desktop-quickstart)完成安装。
      </Tab>
    </Tabs>
  </Step>

  <Step title="将 Claude Code 指向 x6.ai" stepNumber={2}>
    <Tabs>
      <Tab title="CLI — settings.json">
        Claude Code 官方支持通过配置系统管理持久化配置。日常使用时，建议优先将配置写入 `settings.json`。Shell 或系统环境变量更适合临时切换、CI 场景，或作为当前版本已知问题的备用方案。

        **编辑或创建** settings.json 文件<br />macOS 和 Linux：`~/.claude/settings.json`<br />Windows：`C:\Users\<USERNAME>\.claude\settings.json`

        请确保将 `<X6_API_KEY>` 替换为从 [x6.ai Key](https://x6.ai/settings/api-keys) 获取的实际 Key，**替换时请勿保留尖括号**`< `**和** `>`。

        ```json theme={null}
        {
          "env": {
            "ANTHROPIC_AUTH_TOKEN": "<X6_API_KEY>",
            "ANTHROPIC_BASE_URL": "https://api.x6.ai",
            "API_TIMEOUT_MS": "3000000",
            "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1",
            "ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-haiku-4-5",
            "ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-5",
            "ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-opus-5",
            "ANTHROPIC_DEFAULT_FABLE_MODEL": "claude-fable-5"
          }
        }
        ```
      </Tab>

      <Tab title="VS Code 扩展">
        打开 VS Code 的 `settings.json` 。

        <img src="https://mintcdn.com/x6/el_h-gJpYp66h95k/images/claude-code/vscode-settings.webp?fit=max&auto=format&n=el_h-gJpYp66h95k&q=85&s=d816fde5e9dbc7e30dacd79aacf50907" alt="VS Code Claude Code settings" width="1500" height="990" data-path="images/claude-code/vscode-settings.webp" />

        在 \*\*Environment Variables \*\*下点击 **"Edit in settings.json"**。

        <Frame>
          <img src="https://mintcdn.com/x6/el_h-gJpYp66h95k/images/image-4.webp?fit=max&auto=format&n=el_h-gJpYp66h95k&q=85&s=c3ec6c2903e4da47eb67617697357278" alt="Image" width="1200" height="762" data-path="images/image-4.webp" />
        </Frame>

        添加以下内容。请确保将 `<X6_API_KEY>` 替换为从 [x6.ai Key](https://x6.ai/settings/api-keys) 获取的实际 Key。

        ```json theme={null}
        {
            "claudeCode.disableLoginPrompt": true,
            "claudeCode.preferredLocation": "panel",
            "claudeCode.environmentVariables": [
            {"name":"ANTHROPIC_AUTH_TOKEN","value":"<X6_API_KEY>"},
            {"name":"ANTHROPIC_BASE_URL","value":"https://api.x6.ai"}
            ]
        }
        ```
      </Tab>

      <Tab title="Desktop App">
        打开安装完成的 Claude Desktop APP

        * 依次点击顶部菜单栏的 **Help（帮助）** -> **Troubleshooting（疑难解答）**。
        * 在弹出的子菜单中点击 **Enable Developer Mode（启用开发者模式）**。
        * Windows 用户点击 Claude Desktop APP 左上角即可看到同样内容。

        <Frame>
          <img src="https://mintcdn.com/x6/el_h-gJpYp66h95k/images/img_v3_0212p_0c555764-7a1f-439d-ad0b-c5daef51e4hu.webp?fit=max&auto=format&n=el_h-gJpYp66h95k&q=85&s=8b9b224f04fc88dbdf3bbc24e9247eb8" alt="Img V3 0212p 0c555764 7a1f 439d Ad0b C5daef51e4hu" width="1600" height="1082" data-path="images/img_v3_0212p_0c555764-7a1f-439d-ad0b-c5daef51e4hu.webp" />
        </Frame>

        * 启用成功后，顶部菜单栏会多出一个 **Developer（开发者）** 菜单。
        * 在 "Developer" 菜单中选择 "Configure Third-Party Inference..."。

        <Frame>
          <img src="https://mintcdn.com/x6/el_h-gJpYp66h95k/images/img_v3_0212p_2bd65ee8-8d1e-46ba-9343-786dbc96b6hu.webp?fit=max&auto=format&n=el_h-gJpYp66h95k&q=85&s=33d63015a204bb8244ab33666fde486a" alt="Img V3 0212p 2bd65ee8 8d1e 46ba 9343 786dbc96b6hu" width="1236" height="376" data-path="images/img_v3_0212p_2bd65ee8-8d1e-46ba-9343-786dbc96b6hu.webp" />
        </Frame>

        * Credential kind 选择 “Static API key”。
        * Gateway base URL 填入 ”[https://api.x6.ai](https://api.x6.ai)“。
        * Gateway API key 为从 [**x6.ai Key**](https://x6.ai/settings/api-keys) 获取的实际 Key 。

        <Frame>
          <img src="https://mintcdn.com/x6/el_h-gJpYp66h95k/images/img_v3_0212p_8043532d-a2f1-4ac6-833d-f555a4922chu.webp?fit=max&auto=format&n=el_h-gJpYp66h95k&q=85&s=8993566918857456d77aa624d3b48993" alt="Img V3 0212p 8043532d A2f1 4ac6 833d F555a4922chu" width="1600" height="1280" data-path="images/img_v3_0212p_8043532d-a2f1-4ac6-833d-f555a4922chu.webp" />
        </Frame>

        * 页面向下滚动，点击“Add model”。
        * 在 Model ID 中填入”claude-opus-5”，点击下方的“Add”，按照相同步骤添加”claude-sonnet-5“，”claude-haiku-4-5“和“claude-fable-5”。
        * Offer 1M-context variant 可作为可选项启动。
        * 最后点击”Apply Changes“。

        <Frame>
          <img src="https://mintcdn.com/x6/el_h-gJpYp66h95k/images/img_v3_0212p_11d8941c-120f-483c-b289-64dd885062hu.webp?fit=max&auto=format&n=el_h-gJpYp66h95k&q=85&s=27ee12d2dc981533d288f48a6eb21a44" alt="Img V3 0212p 11d8941c 120f 483c B289 64dd885062hu" width="1600" height="1280" data-path="images/img_v3_0212p_11d8941c-120f-483c-b289-64dd885062hu.webp" />
        </Frame>
      </Tab>
    </Tabs>
  </Step>

  <Step title="首次启动">
    <Tabs>
      <Tab title="CLI">
        导航至您的代码工作目录，在终端运行 `claude` 命令即可开始使用 Claude Code：

        ```shellscript theme={null}
        claude
        ```

        首次使用 Claude Code 时，可能会被强制要求登录 Anthropic 账号。

        <Frame>
          <img src="https://mintcdn.com/x6/w6SForJHNVjHtEfm/images/login-1.webp?fit=max&auto=format&n=w6SForJHNVjHtEfm&q=85&s=3f1b3681899be0e832539e2c752f2fc6" alt="Login 1" width="840" height="227" data-path="images/login-1.webp" />
        </Frame>

        1. 请按以下步骤跳过此流程：
        2. 在用户主目录中打开或创建 `.claude.json` 文件。具体路径如下：macOS / Linux：`~/.claude.json`，Windows：`C:\Users\<USERNAME>\.claude.json`
        3. 将 `hasCompletedOnboarding` 字段的值设置为 `true`。

        ```json theme={null}
        {
          "hasCompletedOnboarding": true
        }
        ```

        保存文件后，在终端重新运行 `claude`。

        启动后，选择信任 Claude Code 访问该文件夹中的文件，如下所示：

        <Frame>
          <img src="https://mintcdn.com/x6/el_h-gJpYp66h95k/images/down.webp?fit=max&auto=format&n=el_h-gJpYp66h95k&q=85&s=0192aae2966c60bb989e8cddfc26c0db" alt="Down" width="1132" height="400" data-path="images/down.webp" />
        </Frame>

        完成！您现在可以正常使用 Claude Code。
      </Tab>

      <Tab title="VS Code 扩展">
        点击左侧的 Claude 图标，然后选择"新建会话"即可开始使用 Claude Code for VS Code。

        <Frame>
          <img src="https://mintcdn.com/x6/w6SForJHNVjHtEfm/images/vscode.webp?fit=max&auto=format&n=w6SForJHNVjHtEfm&q=85&s=0b13f239f567ea4edf4c5a7d1456388d" alt="Vscode" width="1200" height="800" data-path="images/vscode.webp" />
        </Frame>

        完成！您现在可以使用 Claude Code for VS Code。
      </Tab>

      <Tab title="Desktop App">
        <Note>
          **Windows 启用虚拟化**

          Cowork 在虚拟环境中运行，Windows 需要先启用 Virtual Machine Platform 特性，否则安装后 Cowork 不可用。以管理员身份打开 PowerShell 执行下面的命令，然后重启系统：

          ```powershell theme={null}
          Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -All -NoRestart
          ```
        </Note>

        打开 Claude Desktop App，就可以开始使用了！

        <Frame>
          <img src="https://mintcdn.com/x6/el_h-gJpYp66h95k/images/img_v3_0212p_acd87bdb-d39f-49ae-b3f1-c0c7d38b40hu.webp?fit=max&auto=format&n=el_h-gJpYp66h95k&q=85&s=b3cbea98b59f10f1fdab711dded94b64" alt="Img V3 0212p Acd87bdb D39f 49ae B3f1 C0c7d38b40hu" width="1600" height="1067" data-path="images/img_v3_0212p_acd87bdb-d39f-49ae-b3f1-c0c7d38b40hu.webp" />
        </Frame>
      </Tab>
    </Tabs>
  </Step>
</Steps>

# **故障排除**

<AccordionGroup>
  <Accordion title="输入提示后无响应 / 出现“You don’t have enough $WAI”错误">
    请确保您的 API 输入正确。由于 Anthropic 模型 Token 消耗较高，每日免费额度可能不足以支持该模型。请为您的账户充值。
  </Accordion>

  <Accordion title="如何切换到其他模型？">
    Claude Code 只支持 Anthropic 格式的 API

    前往 [https://x6.ai/models](https://x6.ai/models)。点击模型，将 API 格式设置为"Anthropic"，并在代码块中找到 `model` 字段。

    从 `model` 字段复制模型名称，替换到上面的 `settings.json` 文件中。

    <Frame>
      <img src="https://mintcdn.com/x6/el_h-gJpYp66h95k/images/image-12.webp?fit=max&auto=format&n=el_h-gJpYp66h95k&q=85&s=d8ddc09da4d2407221a1acc448517671" alt="Image" width="788" height="714" data-path="images/image-12.webp" />
    </Frame>

    打开一个新的终端窗口。运行 `claude` 启动 Claude Code。然后输入 `/model` 切换模型，最后输入 `/status` 验证模型状态。

    <Frame>
      <img src="https://mintcdn.com/x6/el_h-gJpYp66h95k/images/img_v3_02115_9616c753-a33d-47d5-9e3d-dc70d79c24hu.webp?fit=max&auto=format&n=el_h-gJpYp66h95k&q=85&s=bc2c5958e1f91b8d8126aed6b9118db7" alt="Img V3 02115 9616c753 A33d 47d5 9e3d Dc70d79c24hu" width="1018" height="628" data-path="images/img_v3_02115_9616c753-a33d-47d5-9e3d-dc70d79c24hu.webp" />
    </Frame>
  </Accordion>

  <Accordion title="手动配置更改未生效">
    如果您手动编辑了 `~/.claude/settings.json` 文件但更改未应用，请尝试以下操作：

    1. 关闭所有 Claude Code 窗口。打开一个新的终端窗口并重新运行 `claude`。
    2. 如果问题仍然存在，尝试删除 `~/.claude/settings.json` 文件并重新配置环境变量。Claude Code 将自动生成新的配置文件。
    3. 确保配置文件的 JSON 格式正确。检查变量名错误、缺少逗号或多余逗号等问题。您可以使用在线 JSON 验证工具进行验证。
  </Accordion>

  <Accordion title="如何升级 Claude Code？">
    在终端输入以下命令：

    ```shellscript theme={null}
    claude update
    ```
  </Accordion>

  <Accordion title="需要更多信息？">
    请查阅 [官方文档](https://support.claude.com/en/articles/12386420-claude-code-faq)。
  </Accordion>
</AccordionGroup>
