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

# Claude Code 安裝與設定

> 安裝 Claude Code，並以 Anthropic 原生設定連接 NexusAPI。

Claude Code 使用 Anthropic 的原生 Messages 設定，因此 NexusAPI Base URL 為 `https://nexusapi.link`；**不要加上 `/v1`**。

## 1. 安裝 Claude Code

請優先使用官方安裝方式。

### macOS、Linux 或 WSL

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

### Windows PowerShell

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

Windows 亦可使用 `winget install Anthropic.ClaudeCode`，macOS 可使用 `brew install --cask claude-code`。安裝後先檢查：

```bash theme={"system"}
claude --version
claude doctor
```

## 2. 建立 NexusAPI Key

在控制台的 **令牌管理 → 新增令牌** 建立 Key，選取含目標 Claude 模型的群組並設定合理上限。不要僅憑模型名稱猜測協定；請以模型廣場或[能力矩陣](/zh-TW/developer/capability-matrix)確認。

## 3. 設定使用者層級設定檔

| 系統              | 路徑                                      |
| --------------- | --------------------------------------- |
| macOS／Linux／WSL | `~/.claude/settings.json`               |
| Windows         | `%USERPROFILE%\\.claude\\settings.json` |

macOS、Linux、WSL 或 Git Bash 建立檔案：

```bash theme={"system"}
mkdir -p ~/.claude
touch ~/.claude/settings.json
```

將下列 `env` 合併進現有設定，不要覆蓋既有 MCP 或權限設定：

```json theme={"system"}
{
  "env": {
    "ANTHROPIC_AUTH_TOKEN": "YOUR_NEXUSAPI_KEY",
    "ANTHROPIC_BASE_URL": "https://nexusapi.link"
  }
}
```

請放在使用者目錄，不要寫入專案儲存庫、截圖或聊天內容。

## 4. 啟動並驗證

重新開啟終端，在專案目錄執行 `claude`。進入後使用 `/status` 確認 **Anthropic base URL** 為 `https://nexusapi.link`，驗證後送出一條短文字。

## 常見問題

### `Invalid API Key · Please run /login`

確認兩個環境變數已儲存、Key 已啟用，並重新開啟終端。不要為此直接修改 Claude 的內部登入狀態檔。

### `fetch failed`

1. 先送一條普通短訊息。若成功，通常是 WebFetch 等獨立網路功能，而非 NexusAPI 模型呼叫。
2. 若所有模型呼叫都失敗，執行 `claude doctor` 並用 `/status` 確認 Base URL。
3. 檢查 DNS、防火牆、公司網路或既有可信代理是否阻擋 `nexusapi.link`。
4. 重新開啟終端後僅測試一次。持續失敗時，保存版本、doctor 輸出、完整錯誤與 Request ID，依[問題自查](/zh-TW/faq/self-check)提交。

### 顯示 `offline`

部分輔助功能會單獨檢查官方或第三方服務。先以 `/status` 和短文字測試確認實際模型呼叫，不要只憑 `offline` 判斷閘道故障。

## 官方文件

* [Claude Code 安裝](https://code.claude.com/docs/en/installation)
* [環境變數](https://code.claude.com/docs/en/env-vars)
* [Gateway 設定](https://code.claude.com/docs/en/llm-gateway)
