---
description: "通过 settings.json 一键合并配置，将 Claude Code 接入在问 Anthropic 兼容接口。"
---

# 接入 Claude Code

Claude Code 通过 `~/.claude/settings.json` 的 `env` 字段接入在问 Anthropic 兼容接口，
推荐用一键命令合并写入（自动备份），已有 `theme` 等个人偏好会保留。

## 安装

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

安装后可用 `claude --version` 验证。

## 方式一：一键配置命令（推荐）

站内接入向导选择 `Claude Code`，复制对应平台的一键配置命令执行。
命令会自动备份已有配置为 `~/.claude/settings.json.bak`，再合并写入服务端地址、
API Key 与默认模型（`claude-opus-5-5`），已有 `theme` 等个人偏好会保留。

macOS、Linux 或 WSL：

```bash
mkdir -p "$HOME/.claude"
[ ! -f "$HOME/.claude/settings.json" ] || cp "$HOME/.claude/settings.json" "$HOME/.claude/settings.json.bak"
ZAIWENAI_KEY='你的在问APIKEY' python3 - <<'CLAUDE_EOF'
import json, os
from pathlib import Path
p = Path.home() / '.claude' / 'settings.json'
data = json.loads(p.read_text()) if p.exists() and p.read_text().strip() else {}
data.setdefault('attribution', {})['commit'] = ''
data.setdefault('attribution', {})['pr'] = ''
env = data.setdefault('env', {})
env['ANTHROPIC_BASE_URL'] = 'https://oneapi.zaiwenai.com'
env['ANTHROPIC_AUTH_TOKEN'] = os.environ['ZAIWENAI_KEY']
env['ANTHROPIC_MODEL'] = 'claude-opus-5-5'
env['CLAUDE_CODE_EFFORT_LEVEL'] = 'max'
data['includeCoAuthoredBy'] = False
data['model'] = 'opus'
data['skipDangerousModePermissionPrompt'] = True
p.write_text(json.dumps(data, indent=2, ensure_ascii=False) + '\n')
CLAUDE_EOF
```

Windows PowerShell：

```powershell
$claudeDir = Join-Path $HOME ".claude"
$configPath = Join-Path $claudeDir "settings.json"
New-Item -ItemType Directory -Force -Path $claudeDir | Out-Null
if (Test-Path $configPath) { Copy-Item $configPath "$configPath.bak" -Force }
$apiKey = '你的在问APIKEY'
$data = @{}
if (Test-Path $configPath) {
  $raw = (Get-Content $configPath -Raw).Trim()
  if ($raw) { $data = $raw | ConvertFrom-Json }
}
if (-not $data) { $data = New-Object psobject }
if (-not $data.attribution) { $data | Add-Member -NotePropertyName attribution -NotePropertyValue (@{}) -Force }
$data.attribution | Add-Member -NotePropertyName commit -NotePropertyValue "" -Force
$data.attribution | Add-Member -NotePropertyName pr -NotePropertyValue "" -Force
if (-not $data.env) { $data | Add-Member -NotePropertyName env -NotePropertyValue (@{}) -Force }
$data.env | Add-Member -NotePropertyName ANTHROPIC_BASE_URL -NotePropertyValue "https://oneapi.zaiwenai.com" -Force
$data.env | Add-Member -NotePropertyName ANTHROPIC_AUTH_TOKEN -NotePropertyValue $apiKey -Force
$data.env | Add-Member -NotePropertyName ANTHROPIC_MODEL -NotePropertyValue "claude-opus-5-5" -Force
$data.env | Add-Member -NotePropertyName CLAUDE_CODE_EFFORT_LEVEL -NotePropertyValue "max" -Force
$data | Add-Member -NotePropertyName includeCoAuthoredBy -NotePropertyValue $false -Force
$data | Add-Member -NotePropertyName model -NotePropertyValue "opus" -Force
$data | Add-Member -NotePropertyName skipDangerousModePermissionPrompt -NotePropertyValue $true -Force
$data | ConvertTo-Json -Depth 10 | Set-Content -Encoding utf8 $configPath
```

## 方式二：手动编辑配置文件

打开 `~/.claude/settings.json`（文件不存在则创建），写入以下内容
（将 `你的在问APIKEY` 替换为实际 Key）：

```json
{
  "attribution": {
    "commit": "",
    "pr": ""
  },
  "env": {
    "ANTHROPIC_AUTH_TOKEN": "你的在问APIKEY",
    "ANTHROPIC_BASE_URL": "https://oneapi.zaiwenai.com",
    "ANTHROPIC_MODEL": "claude-opus-5-5",
    "CLAUDE_CODE_EFFORT_LEVEL": "max"
  },
  "includeCoAuthoredBy": false,
  "model": "opus",
  "skipDangerousModePermissionPrompt": true,
  "theme": "dark"
}
```

如果该文件中已有配置（如 `theme` 等个人偏好），请先备份，再手动合并 `env` 与
`model` 等字段，不要整文件覆盖。

## 验证

```bash
claude
```

启动后输入一个问题，如果收到正常回复，说明连接成功。如果提示认证错误，检查
`~/.claude/settings.json` 中 `env.ANTHROPIC_AUTH_TOKEN` 是否正确。

:::: tip 配置说明
- `env.ANTHROPIC_BASE_URL`：在问网关地址，固定 `https://oneapi.zaiwenai.com`
- `env.ANTHROPIC_AUTH_TOKEN`：填入你在问平台的 API Key
- `env.ANTHROPIC_MODEL`：默认 `claude-opus-5-5`，也可替换为在问支持的其他 Claude 系列模型
- `env.CLAUDE_CODE_EFFORT_LEVEL`：默认 `max`，按需可改为低档
- `model = "opus"`：Claude Code 启动默认模型档位
- `includeCoAuthoredBy = false`：提交信息不附加 AI 署名
- `skipDangerousModePermissionPrompt = true`：跳过高危操作二次确认，图方便可保留；
  如在共享机器或重要仓库使用，建议改为 `false`
- 如终端环境变量里仍 export 了 `ANTHROPIC_API_KEY`，请 `unset` 或置空，避免它优先于
  `settings.json` 的认证方式导致鉴权失败
- 辅助命令会在覆盖前将已有配置文件备份为 `~/.claude/settings.json.bak`
::::
