結論先說
claude-code-action@v1憑prompt自動切換模式:不傳prompt響應@claude評論;傳入prompt則按事件或 Cron 自動跑批。- 單庫可跑
/install-github-app,組織跨庫宜用 API Key 或 OIDC:跨倉庫不應共享個人訂閱的CLAUDE_CODE_OAUTH_TOKEN,宜改用 Console API Key 或anthropic_federation_rule_id。 - 自動審碼須保留
--comment與對應 MCP 工具白名單:v2.1.229 起需在prompt加--comment,並在claude_args授權mcp__github_inline_comment__create_inline_comment。 - 切勿傳回
github_token: ${{ secrets.GITHUB_TOKEN }}:GitHub 會阻止預設GITHUB_TOKEN推送觸發下游 CI;留空讓其以 Claude GitHub App 身份提交即可。 - 個人驗證與 OAuth 令牌生成須具備付費底座:前期評估或終端協作可參考 Claude Code 訂閱專題 與 Claude Pro 充值指南。

圖:本站根據 Claude Code GitHub Actions 整理的示意圖
本文根據 Anthropic Claude Code 官方文檔整理,資料核對於 2026-12-03。配圖為本站整理的示意圖,不是介面截圖。本站(bigolab.com)由益陽市赫山區必高科技有限公司獨立運營,是獨立第三方服務商,不是 Anthropic 官方網站。
適用於誰
- 希望把 Claude Code 融入 GitHub PR 與 Issue 協作的工程師:在評論區提及
@claude後自動分析 Bug、改碼並提交 PR。 - 配置 CI 自動審碼與定時巡檢的 DevOps 人員:通過 YAML 控制模型、
--max-turns輪次上限與 Cron 調度。 - 從
@beta遷移至anthropics/claude-code-action@v1的維護者:需要對照最新參數替代mode與direct_prompt。
一、交互響應模式與自動化調度模式對比
| 對比維度 | 交互響應模式(無 prompt) | 自動化調度模式(有 prompt) |
|---|---|---|
| 觸發事件 | issue_comment、pull_request_review_comment、issues | pull_request、schedule(cron)等 |
| 觸發條件 | 含完整詞 @claude(非 /claude 或 @claude-bot) | 按事件運行;schedule 跳過寫權限校驗 |
| 身份校驗 | 須有寫權限且非 Bot(除非配 allowed_bots) | 仍攔截 Bot,cron 歸屬於最後改 YAML 的用戶 |
| 輸出位置 | 回覆並更新原 Issue 或 PR 評論 | 預設寫日誌,加 --comment 才回帖 |
| 工具授權 | 使用內置交互工具集 | 純文本 prompt 須配 --allowedTools |
認證支持 ANTHROPIC_API_KEY、由 claude setup-token 生成的 CLAUDE_CODE_OAUTH_TOKEN,或 OIDC 聯邦(傳 anthropic_federation_rule_id、anthropic_organization_id 與 anthropic_service_account_id 並保留 id-token: write)。
二、標準 YAML 模板與部署驗證步驟
以下工作流同時包含 @claude 提及響應與 PR 自動審碼兩個作業(若使用 OAuth 令牌,將 anthropic_api_key 替換為 claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}):

圖:本站根據 Claude Code GitHub Actions 整理的示意圖
name: Claude Code Workflow
on:
issue_comment:
types: [created]
pull_request_review_comment:
types: [created]
pull_request:
types: [opened, synchronize, ready_for_review, reopened]
jobs:
respond-mentions:
if: github.event.comment && 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.ANTHROPIC_API_KEY }}
claude_args: "--max-turns 8"
auto-code-review:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
issues: read
id-token: write
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 1
- uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
plugin_marketplaces: "https://github.com/anthropics/claude-plugins-official.git"
plugins: "code-review@claude-plugins-official"
prompt: "/code-review:code-review --comment ${{ github.repository }}/pull/${{ github.event.pull_request.number }}"
claude_args: '--allowedTools "mcp__github_inline_comment__create_inline_comment"'
若要搭建每日 09:00 UTC 巡檢(schedule),可省去 Checkout,在 claude_args 指定 --model claude-opus-5-5 與 --allowedTools "mcp__github__list_commits,mcp__github__list_issues"。
人工核對要點:
@beta升@v1須刪mode,將direct_prompt改prompt,max_turns與model移入claude_args。- 保持
CLAUDE.md精簡,無人值守 Job 固定加--max-turns。 - 聲明
id-token: write確保應用預設認證正常。
訂閱與開通提示:運行claude setup-token生成 OAuth 憑證須具付費訂閱。站內提供 Claude Pro iOS 自助充值、Claude Max 5x iOS 自助充值、Claude Max 20x iOS 自助充值 與 Claude KYC 協助服務,對比見 Claude Max 5x/20x 充值指南。全站以商品頁實時標價為準,標價不含稅,開具國內增值稅發票另付 6% 稅費;單獨申請自定義明細電子收據免費,企業批量採購支持簽訂正式中文服務合同並對公結算。
常見問題
問:評論寫了 @claude 卻沒觸發或失敗怎麼辦?
答:依次核對:倉庫已裝 Claude GitHub App、Actions 已啟用、含獨立詞 @claude,以及評論者有寫權限且非 Bot。
問:Claude 推送修復後單元測試流水線不觸發怎麼回事?
答:因傳入了 github_token: ${{ secrets.GITHUB_TOKEN }}。GitHub 阻止其推送再觸發 CI,刪掉該參數即可。
問:定時調度(schedule)為什麼沒按時跑?
答:schedule 僅在預設分支生效,公開庫 60 天無提交會自動停用;若最後修改人為 Bot 須加進 allowed_bots。
問:企業採購訂閱或開具 6% 增值稅發票怎麼辦理?
答:前往 AI 訂閱與帳號服務總覽 或 全部商品 選購,可參考 Claude Pro 充值指南 核對方案後聯絡客服。全站以商品頁實時標價為準,標價不含稅,開具國內增值稅發票另付 6% 稅費;單獨申請自定義明細電子收據免費。本站明示質保訂閱、不質保封號,請嚴格遵守服務商條款合規使用。
相關教學
- GitHub Actions 走 Amazon Bedrock 跑 Claude Code:OIDC 鑑權與權限配置
- GitHub Actions 接入 Google Cloud 與 Microsoft Foundry 運行 Claude Code
- CI/CD 中運行 Claude Code 的權限隔離:防範評論區 Prompt 注入與越權推碼
- Headless 無頭模式與 Agent SDK 編程接入:CLI、Python 與 TypeScript 範例
0 條評論
還沒有評論,來搶沙發~