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

# Claude Code

> Claude Code 配置 AutoDL 大模型接口

Claude Code 是 Anthropic 官方推出的命令行编程工具。通过配置 AutoDL 的大模型 Token，可以让 Claude Code 调用 AutoDL 的大模型接口。

## 前置准备

1. 安装 Node.js 和 npm。
2. 安装 Claude Code：

```Shell theme={null}
npm install -g @anthropic-ai/claude-code
```

3. 前往「大模型」->「[令牌管理](https://www.autodl.art/large-model/tokens)」创建并复制 `密钥`。

> [!NOTE]
>
> 下方命令中的 `<你的API_KEY>` 需要替换为在 AutoDL 令牌管理页面获取的`密钥`。

## CC Switch

推荐使用[CC Switch](https://docs.autodl.art/model/tool/ccswitch.md)配置。

## Windows 配置

### 临时配置

在 PowerShell 中执行以下命令，本次终端会话立即生效：

```PowerShell theme={null}
$env:ANTHROPIC_BASE_URL="https://www.autodl.art/api/v1/anthropic"
$env:ANTHROPIC_AUTH_TOKEN="<你的API_KEY>"
```

### 永久配置

如果希望后续打开 PowerShell 时自动生效，可以执行：

```PowerShell theme={null}
setx ANTHROPIC_BASE_URL "https://www.autodl.art/api/v1/anthropic"
setx ANTHROPIC_AUTH_TOKEN "<你的API_KEY>"
```

执行完成后，关闭当前终端并重新打开，再运行：

```PowerShell theme={null}
claude
```

> [!TIP]
>
> Windows 用户也可以在 WSL 或 Git Bash 中按照 Linux 的方式配置。

## Linux 配置

### 临时配置

在终端中执行以下命令，本次终端会话立即生效：

```Shell theme={null}
export ANTHROPIC_BASE_URL="https://www.autodl.art/api/v1/anthropic"
export ANTHROPIC_AUTH_TOKEN="<你的API_KEY>"
```

### 永久配置

如果使用 Bash，可以写入 `~/.bashrc`：

```Shell theme={null}
echo 'export ANTHROPIC_BASE_URL="https://www.autodl.art/api/v1/anthropic"' >> ~/.bashrc
echo 'export ANTHROPIC_AUTH_TOKEN="<你的API_KEY>"' >> ~/.bashrc
source ~/.bashrc
```

如果使用 Zsh，将 `~/.bashrc` 替换为 `~/.zshrc`。

## macOS 配置

### 临时配置

在终端中执行以下命令，本次终端会话立即生效：

```Shell theme={null}
export ANTHROPIC_BASE_URL="https://www.autodl.art/api/v1/anthropic"
export ANTHROPIC_AUTH_TOKEN="<你的API_KEY>"
```

### 永久配置

macOS 默认使用 Zsh，可以写入 `~/.zshrc`：

```Shell theme={null}
echo 'export ANTHROPIC_BASE_URL="https://www.autodl.art/api/v1/anthropic"' >> ~/.zshrc
echo 'export ANTHROPIC_AUTH_TOKEN="<你的API_KEY>"' >> ~/.zshrc
source ~/.zshrc
```

如果你使用 Bash，将 `~/.zshrc` 替换为 `~/.bash_profile` 或 `~/.bashrc`。

## 可选：指定默认模型

Claude Code 会读取 Anthropic 兼容环境变量。如果你希望固定使用 AutoDL 的 Claude Code 专用模型，可以额外设置默认模型变量，推荐使用 `claude-sonnet-4-6`：

```Shell theme={null}
export ANTHROPIC_DEFAULT_HAIKU_MODEL="claude-sonnet-4-6"
export ANTHROPIC_DEFAULT_SONNET_MODEL="claude-sonnet-4-6"
export ANTHROPIC_DEFAULT_OPUS_MODEL="claude-sonnet-4-6"
```

如果你想使用 `claude-opus-4-6`，把上面的三个值替换成该模型名称即可。

## 验证配置

完成配置后，在项目目录或任意工作目录运行：

```Shell theme={null}
claude
```

如果 Claude Code 正常启动，并且不再提示登录 Anthropic 账号，说明 AutoDL 第三方 Token 已配置成功。

可以发送一句“您好”测试，并观察[数据看板](https://www.autodl.art/large-model/dashboard)消耗。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.