---
title: Claude Code GitHub Actions | RunAPI
description: 使用 RunAPI 密鑰、模型、權限、觸發條件及最小化工作流程設定 Claude Code GitHub Actions。
url: https://runapi.ai/zh-TW/docs/resources/tool-integrations/claude-code-github-actions.md
canonical: https://runapi.ai/zh-TW/docs/resources/tool-integrations/claude-code-github-actions
locale: zh-TW
---

> HTML 版本: https://runapi.ai/zh-TW/docs/resources/tool-integrations/claude-code-github-actions
> 代理程式網站索引: https://runapi.ai/llms.txt

# Claude Code GitHub Actions

## 概覽

官方 `anthropics/claude-code-action` 可在 GitHub Actions 工作流程中執行 Claude Code。本指南將 RunAPI 金鑰儲存為 GitHub Secret，在 Claude Code 設定中設定非敏感的 Base URL，選擇模型，並回應已授權的 `@claude` 評論。

## 開始之前

* 您需要儲存庫管理員存取權限，才能安裝 Claude GitHub App、建立 Actions 密鑰及新增工作流程。
* 依照[身分驗證指南](https://runapi.ai/zh-TW/docs/guides/authentication.md)建立一組標準 RunAPI API 金鑰。
* 從[模型目錄](https://runapi.ai/zh-TW/models)複製支援 Anthropic Messages 的模型識別碼。
* 閱讀 [Claude Code GitHub Actions 設定說明][1]及您組織的工作流程政策。



[1]: https://code.claude.com/docs/en/github-actions

## 安裝

在目標儲存庫的 Claude Code 中，執行 `/install-github-app` 並依照提示安裝 GitHub App。當系統提示建立 Anthropic 憑證時，請在儲存前停止：本指南改用 RunAPI 儲存庫或組織密鑰。

若要手動設定，請安裝 [Claude GitHub App][1]，然後將
以下工作流程新增至 `.github/workflows/claude.yml`。



[1]: https://github.com/apps/claude

## 設定 RunAPI

建立名為 `RUNAPI_API_KEY` 的儲存庫或組織 Actions 密鑰。僅透過 action 的 secret 輸入傳遞：

```yaml
anthropic_api_key: ${{ secrets.RUNAPI_API_KEY }}
```

請勿將金鑰放入工作流程檔案或 action 的 `settings` JSON 中。
action 會單獨處理設定；只有非敏感的 Base
URL 可以放在那裡。

以下最簡互動工作流程會監聽新的 issue 及 pull request 審查評論：

```yaml
name: Claude Code

on:
  issue_comment:
    types: [created]
  pull_request_review_comment:
    types: [created]

jobs:
  claude:
    if: contains(github.event.comment.body, '@claude')
    runs-on: ubuntu-latest
    permissions:
      contents: write
      pull-requests: write
      issues: write
      id-token: write
      actions: read
    steps:
      - uses: actions/checkout@v6
        with:
          fetch-depth: 1
      - uses: anthropics/claude-code-action@v1
        with:
          anthropic_api_key: ${{ secrets.RUNAPI_API_KEY }}
          settings: |
            {
              "env": {
                "ANTHROPIC_BASE_URL": "https://runapi.ai"
              }
            }
          claude_args: "--model YOUR_RUNAPI_MODEL_ID"
```

### 密鑰

GitHub 不會將一般 Actions 密鑰傳遞至由 fork pull request 或 Dependabot 事件觸發的工作流程。若某次執行沒有憑證，請在輪替 RunAPI 金鑰前確認事件來源。請使用 GitHub 的 [Actions 密鑰指南][1] 設定儲存庫與組織範圍的密鑰。



[1]: https://docs.github.com/en/actions/how-tos/write-workflows/choose-what-workflows-do/use-secrets

### 權限

* `contents: write` 允許 action 提交程式碼變更。
* `pull-requests: write` 與 `issues: write` 允許其讀取並回覆觸發的對話。
* `id-token: write` 支援 action 預設的 GitHub App 身分驗證。
* `actions: read` 允許其檢查工作流程執行結果。

使用這些明確的權限取代 `write-all`。移除工作流程不需要的功能。

### 觸發事件

`issue_comment` 涵蓋議題及拉取請求對話中的留言；`pull_request_review_comment` 涵蓋差異行上的留言。工作流程檔案必須存在於預設分支上，`issue_comment` 才能觸發它。此 action 也會檢查啟動執行的人員；請以[官方安全行為][1]作為權威參考。



[1]: https://code.claude.com/docs/en/github-actions#who-can-trigger-runs

## 選擇模型

將 `claude_args` 中的 `YOUR_RUNAPI_MODEL_ID` 替換為[模型目錄](https://runapi.ai/zh-TW/models)中的確切識別碼。將模型選擇保留在 `settings.env` 之外，可使工作流程所選的模型在動作設定中清晰可見。

## 驗證

1.  確認 `RUNAPI_API_KEY` 密鑰已存在，但不要列印其值。
2.  將工作流程合併至預設分支，並確認 Actions 已啟用。
3.  以具有儲存庫寫入權限的帳戶，在 Issue 留言中加入 `@claude describe
    this repository in one sentence`。
4.  開啟工作流程執行紀錄，確認 action 執行成功，並驗證 Claude 已在同一 Issue 中回覆。

## 疑難排解

* **未啟動任何工作流程：** 請確認檔案位於預設分支上、comment 事件相符，且 Actions 已啟用。
* **工作已被略過：** 請確認 comment 中包含 `@claude`，且操作者具備所需的儲存庫存取權限。
* **身分驗證失敗：** 請確認工作流程參照了 `secrets.RUNAPI_API_KEY`，若有需要，請透過[身分驗證指南](https://runapi.ai/zh-TW/docs/guides/authentication.md)輪換金鑰。
* **Fork 的 pull request 無法使用該金鑰：** GitHub 刻意不對 fork 觸發的執行作業提供一般 secrets。請勿以明文取代該 secret。
* **模型無法使用：** 請從[模型目錄](https://runapi.ai/zh-TW/models)複製正確的識別碼。
* **Claude 的提交未觸發其他工作流程：** 請查閱官方 action 的 [GitHub token 疑難排解][1]說明。



[1]: https://code.claude.com/docs/en/github-actions#ci-not-running-on-claudes-commits

## 後續步驟

有關協定行為，請參閱 [LLM API 快速入門](https://runapi.ai/zh-TW/docs/guides/llm-api/quickstart.md)；有關請求欄位，請參閱 [Anthropic Messages API 參考](https://runapi.ai/zh-TW/docs/api/anthropic/messages.md)。如需更多觸發條件和動作輸入，請參閱[官方範例][1]和[設定參考][2]。



[1]: https://github.com/anthropics/claude-code-action/tree/main/examples
[2]: https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md

---

## RunAPI 的更多內容

- [首頁](https://runapi.ai/zh-TW/.md)
- [模型目錄](https://runapi.ai/zh-TW/models.md)
- [價格](https://runapi.ai/zh-TW/pricing.md)
- [提供商](https://runapi.ai/zh-TW/models)
- [文件](https://runapi.ai/zh-TW/docs/guides)
- [SDK](https://runapi.ai/zh-TW/sdk.md)
- [CLI](https://runapi.ai/zh-TW/cli.md)
- [MCP Server](https://runapi.ai/zh-TW/mcp.md)
- [Claude Code 與 Cursor](https://runapi.ai/zh-TW/claude-code-vs-cursor.md)
- [Cursor API 設定](https://runapi.ai/zh-TW/cursor-api-setup.md)
- [RunAPI 與 OpenRouter](https://runapi.ai/zh-TW/openrouter-alternative.md)
- [企業版](https://runapi.ai/zh-TW/contact.md)
- [聯絡我們](https://runapi.ai/zh-TW/contact.md)
- [服務條款](https://runapi.ai/zh-TW/terms.md)
- [隱私權](https://runapi.ai/zh-TW/privacy.md)
- [代理程式網站索引](https://runapi.ai/llms.txt)

聯絡我們: contact@runapi.ai

## 結構化資料

```json
[
  {
    "@context": "https://schema.org",
    "inLanguage": "zh-TW",
    "@type": "WebSite",
    "name": "RunAPI",
    "url": "https://runapi.ai/zh-TW",
    "potentialAction": {
      "@type": "SearchAction",
      "target": {
        "@type": "EntryPoint",
        "urlTemplate": "https://runapi.ai/zh-TW/models?q={search_term_string}"
      },
      "query-input": "required name=search_term_string"
    }
  },
  {
    "@context": "https://schema.org",
    "inLanguage": "zh-TW",
    "@type": "Organization",
    "name": "RunAPI",
    "url": "https://runapi.ai/zh-TW",
    "logo": {
      "@type": "ImageObject",
      "url": "https://runapi.ai/zh-TWicon.svg"
    },
    "sameAs": [
      "https://github.com/runapi-ai"
    ]
  },
  {
    "@context": "https://schema.org",
    "inLanguage": "zh-TW",
    "@type": "TechArticle",
    "headline": "Claude Code GitHub Actions",
    "description": "使用 RunAPI 密鑰、模型、權限、觸發條件及最小化工作流程設定 Claude Code GitHub Actions。",
    "url": "https://runapi.ai/zh-TW/docs/resources/tool-integrations/claude-code-github-actions",
    "mainEntityOfPage": "https://runapi.ai/zh-TW/docs/resources/tool-integrations/claude-code-github-actions"
  }
]
```
