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

> HTML 版本: https://runapi.ai/zh-HK/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-HK/docs/guides/authentication.md)建立標準 RunAPI API 金鑰。
* 從[模型目錄](https://runapi.ai/zh-HK/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 密鑰。僅通過操作的密鑰輸入傳遞：

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

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

以下最簡互動工作流程監聽新的議題及拉取請求審查評論：

```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` 允許操作提交代碼更改。
* `pull-requests: write` 和 `issues: write` 允許其讀取並回覆觸發該操作的對話。
* `id-token: write` 支援操作預設的 GitHub App 身份驗證。
* `actions: read` 允許其查看工作流程結果。

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

### 觸發事件

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



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

## 選擇模型

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

## 驗證

1.  確認 `RUNAPI_API_KEY` 密鑰已存在，但不要打印其值。
2.  將工作流程合併至預設分支，並確認 Actions 已啟用。
3.  從擁有代碼庫寫入權限的帳戶，在議題留言中新增 `@claude describe
    this repository in one sentence`。
4.  開啟工作流程運行記錄，確認操作成功，並驗證 Claude 已在同一議題中回覆。

## 疑難排解

* **未啟動任何工作流程：** 請確認檔案位於預設分支，評論事件相符，且 Actions 已啟用。
* **任務被跳過：** 請確認評論包含 `@claude`，且操作者擁有所需的儲存庫存取權限。
* **身份驗證失敗：** 請確認工作流程引用了 `secrets.RUNAPI_API_KEY`，如有需要，請透過[身份驗證指南](https://runapi.ai/zh-HK/docs/guides/authentication.md)輪換金鑰。
* **Fork 的 pull request 無法使用金鑰：** GitHub 刻意對 fork 觸發的執行隱藏普通 secrets。請勿以明文替換該 secret。
* **模型不可用：** 請從[模型目錄](https://runapi.ai/zh-HK/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-HK/docs/guides/llm-api/quickstart.md) 了解協定行為，使用 [Anthropic Messages API 參考](https://runapi.ai/zh-HK/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-HK/.md)
- [模型目錄](https://runapi.ai/zh-HK/models.md)
- [收費](https://runapi.ai/zh-HK/pricing.md)
- [服務商](https://runapi.ai/zh-HK/models)
- [文件](https://runapi.ai/zh-HK/docs/guides)
- [SDK](https://runapi.ai/zh-HK/sdk.md)
- [CLI](https://runapi.ai/zh-HK/cli.md)
- [MCP Server](https://runapi.ai/zh-HK/mcp.md)
- [Claude Code 與 Cursor](https://runapi.ai/zh-HK/claude-code-vs-cursor.md)
- [Cursor API 設定](https://runapi.ai/zh-HK/cursor-api-setup.md)
- [RunAPI 與 OpenRouter](https://runapi.ai/zh-HK/openrouter-alternative.md)
- [企業版](https://runapi.ai/zh-HK/contact.md)
- [聯絡](https://runapi.ai/zh-HK/contact.md)
- [條款](https://runapi.ai/zh-HK/terms.md)
- [私隱](https://runapi.ai/zh-HK/privacy.md)
- [智能代理網站索引](https://runapi.ai/llms.txt)

聯絡我們: contact@runapi.ai

## 結構化資料

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