canonical_url: https://yycode.net/docs/zh-TW/auto-config-tool
lang: zh-TW
updated_at: 2026-07-04T13:33:48.616Z
source_html: https://yycode.net/docs/zh-TW/auto-config-tool

# YYCode 自動設定工具

這篇指南解決一件事：用一條指令把 `Claude Code` 或 `Codex` 安裝並接到 `YYCode`，即使你的機器還沒有 Node.js，也可以繼續走下去。 

---

## 1. 建立 API Key

腳本執行過程中會提示你輸入 API Key，因此先在 YYCode 控制台建立好備用。

登入 [YYCode 控制台](https://yycode.net/console/token)，進入 **權杖管理** 頁面，點選 **新增權杖**。

![](https://r2.yycode.net/yycode/i9bq1Ik.png)
![](https://r2.yycode.net/yycode/9KXR1Ik.png)

填寫金鑰名稱，並根據要使用的工具選擇分組：

- 設定 **Claude Code**：選擇 Claude 相關分組
- 設定 **Codex**：選擇 `codex` 分組
- 同時設定兩者：需要分別建立兩枚 Key，各自對應上面一種分組

IP 白名單、額度限制、模型限制和過期時間可按需設定，新手建議直接使用預設設定。

建立完成後，在清單中點選金鑰旁的 **複製** 按鈕拿到完整的 API Key，稍後在腳本交互中貼上。

> **安全提示**：API Key 等同於帳號憑證，請妥善保管，切勿提交到程式碼儲存庫或公開分享。

---

## 2. 推薦用法

### macOS / Linux

直接執行：

```bash
curl -fsSL https://yycode.net/auto-config/install.sh | bash
```

腳本會自動完成以下動作：

- 檢測目前系統是否已有可用的 Node.js
- 如果沒有，則在目前使用者目錄下安裝本機 Node.js 執行時
- 將 npm 鏡像切到國內源，降低無代理環境下載失敗率
- 安裝 `Claude Code` 和 `Codex`
- 寫入對應設定檔
- 最後執行版本檢查，確認指令可以執行

### Windows PowerShell

直接執行：

```powershell
irm https://yycode.net/auto-config/install.ps1 | iex
```

---

## 3. 常用參數

如果你想完全非交互執行，可以直接把參數寫進指令裡。

> **注意：** Claude Code 和 Codex 使用不同的 API Key，設定 `all` 時需要分別提供兩個 Key。

### 只設定 Claude Code

macOS / Linux：

```bash
curl -fsSL https://yycode.net/auto-config/install.sh | bash -s -- --api-key YOUR_CLAUDE_KEY --tools claude
```

Windows PowerShell（管道模式通過環境變數傳參）：

```powershell
$env:YYCODE_CLAUDE_API_KEY='YOUR_CLAUDE_KEY'; $env:YYCODE_TOOLS='claude'; irm https://yycode.net/auto-config/install.ps1 | iex
```

Windows PowerShell（下載後直接執行）：

```powershell
.\install.ps1 --api-key YOUR_CLAUDE_KEY --tools claude
```

### 只設定 Codex

macOS / Linux：

```bash
curl -fsSL https://yycode.net/auto-config/install.sh | bash -s -- --codex-api-key YOUR_CODEX_KEY --tools codex
```

Windows PowerShell（管道模式）：

```powershell
$env:YYCODE_CODEX_API_KEY='YOUR_CODEX_KEY'; $env:YYCODE_TOOLS='codex'; irm https://yycode.net/auto-config/install.ps1 | iex
```

Windows PowerShell（下載後直接執行）：

```powershell
.\install.ps1 --codex-api-key YOUR_CODEX_KEY --tools codex
```

### 同時設定 Claude Code 和 Codex

macOS / Linux：

```bash
curl -fsSL https://yycode.net/auto-config/install.sh | bash -s -- --api-key YOUR_CLAUDE_KEY --codex-api-key YOUR_CODEX_KEY
```

Windows PowerShell（管道模式）：

```powershell
$env:YYCODE_CLAUDE_API_KEY='YOUR_CLAUDE_KEY'; $env:YYCODE_CODEX_API_KEY='YOUR_CODEX_KEY'; irm https://yycode.net/auto-config/install.ps1 | iex
```

Windows PowerShell（下載後直接執行）：

```powershell
.\install.ps1 --api-key YOUR_CLAUDE_KEY --codex-api-key YOUR_CODEX_KEY
```

### 自定義 API 地址

如果你部署了自定義域名，可以覆蓋預設地址：

```bash
curl -fsSL https://yycode.net/auto-config/install.sh | bash -s -- --api-key YOUR_CLAUDE_KEY --base-url https://your-domain.example.com
```

---

## 4. 腳本會寫哪些檔案

### Claude Code

腳本會寫入：

```text
~/.claude/settings.json
```

核心欄位如下：

```json
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://yycode.net",
    "ANTHROPIC_AUTH_TOKEN": "YOUR_API_KEY"
  }
}
```

### Codex

腳本會寫入：

```text
~/.codex/auth.json
~/.codex/config.toml
```

`auth.json`：

```json
{
  "auth_mode": "apikey",
  "OPENAI_API_KEY": "YOUR_API_KEY"
}
```

`config.toml`：

```toml
model_provider = "yycode"
model = "gpt-5.5"
network_access = "enabled"

[model_providers.yycode]
name = "yycode"
base_url = "https://yycode.net/v1"
wire_api = "responses"
requires_openai_auth = true
```

---

## 5. 不需要管理員權限嗎

預設不需要。

腳本優先使用系統已有的 Node.js；如果沒有，就把 Node.js 安裝到目前使用者目錄：

- macOS / Linux：`~/.yycode/node`
- Windows：`%USERPROFILE%\.yycode\node`

客戶端包也會安裝到目前使用者目錄，而不是系統全域目錄。

---

## 6. 首次執行後要做什麼

### macOS / Linux

腳本結束後建議執行：

```bash
source ~/.zshrc
```

如果你不是 `zsh`，則按腳本最後輸出的實際 profile 檔案執行 `source`。

### Windows

重新打開一個 PowerShell 視窗即可。

---

## 7. 如何確認已經成功

### Claude Code

```bash
claude --version
```

### Codex

```bash
codex --version
```

只要指令能輸出版本號，通常就說明安裝鏈路已經打通。

---

## 8. 備份與回滾

如果你的機器上已經有舊設定，腳本會在首次覆蓋前自動生成 `.bak` 備份，例如：

- `~/.claude/settings.json.bak`
- `~/.codex/auth.json.bak`
- `~/.codex/config.toml.bak`

如果需要回滾，直接把對應 `.bak` 檔案恢復回來即可。

---

## 9. 常見問題

### Windows 上提示需要 git-bash

Claude Code 在 Windows 上依賴 git-bash 執行。腳本會自動檢測並安裝 Git for Windows（優先從國內 npmmirror 鏡像下載），無需手動操作。

### Windows 管道模式（`irm | iex`）怎麼傳參數

`irm ... | iex` 後面**不能直接跟參數**，需要通過環境變數傳入：

```powershell
$env:YYCODE_TOOLS='claude'; $env:YYCODE_CLAUDE_API_KEY='YOUR_KEY'; irm https://yycode.net/auto-config/install.ps1 | iex
```

如果不傳環境變數，腳本會交互式提示輸入 API Key。

### 沒有代理，腳本還能跑嗎

腳本預設優先使用國內鏡像：

- Node.js 優先從 `npmmirror` 拉取
- npm registry 預設切到 `https://registry.npmmirror.com`

如果鏡像失敗，腳本還會再嘗試官方源。

### 我只想寫設定，不想安裝客戶端

可以加上：

```bash
--skip-client-install
```

適合你已經裝好 `claude` 或 `codex`，只想重新寫設定檔的情況。

### API 地址不是 `https://yycode.net`

使用 `--base-url` 覆蓋即可。

### 原來的設定被覆蓋了怎麼辦

優先檢查同目錄下的 `.bak` 備份檔案，腳本第一版已經為設定覆蓋預留了回滾路徑。

---

## 10. 下一步

- 想看手動安裝與逐步解釋：繼續檢視 [Claude Code快速開始指南](claude-code-quickstart) 和 [Codex快速開始指南](codex-quickstart)
- 還沒準備好本機環境：檢視 [Node.js環境安裝指南](nodejs-setup)
- 遇到其他常見問題：檢視 [常見問題](faq)
