把 Claude Code 接進 GitHub:從 Code Review、修 Code 到開發功能
最近我試著把 Claude Code GitHub Action 整合到一個 Android 練習專案,看看能不能讓 Claude 直接在 GitHub 專案中幫我分析程式碼、進行 Code Review、修正問題,以及開發新功能。
把 Claude Code 接進 GitHub:從 Code Review、修 Code 到開發功能

最近我試著把 Claude Code GitHub Action 整合到一個 Android 練習專案,看看能不能讓 Claude 直接在 GitHub 專案中幫我分析程式碼、進行 Code Review、修正問題,以及開發新功能。
這篇文章是整個設定過程與實際執行結果的記錄,希望能幫到同樣想在 GitHub workflow 中導入 AI Agent 的朋友。
Claude Code GitHub Action 的付費方式
要把 Claude Code 整合到 GitHub 專案,首先要注意的是:這並不是一項免費服務。
目前主要有兩種付費方式:
- 使用 Anthropic API Key,依照實際 API 用量計費。
- 使用 Claude 訂閱方案,Action 執行所消耗的額度會計入訂閱方案的 usage。
因為我目前有訂閱 Claude Pro Plan,所以這次採用第二種方式,透過訂閱方案的 OAuth token 來執行 Claude Code Action。
安裝 Claude GitHub App
根據 Claude Code GitHub Actions 官方文件,可以直接在 Claude Code 中執行:
/install-github-app
這個指令會協助我們將 Claude GitHub App 安裝到 GitHub Repository,並引導我們加入 GitHub Actions workflow 與需要的認證資訊。
不過,我這次選擇手動安裝。

首先,前往 Claude GitHub App,將它安裝到自己的 GitHub 帳號或 Organization。
安裝時可以選擇:
- 允許存取所有 Repository
- 只允許存取指定的 Repository
我選擇只開放這次要測試的 Repo,避免給予不必要的存取權限。
設定 Claude 的認證資訊
安裝 GitHub App 後,接下來要把 Claude Code 使用的認證資訊存進 GitHub Repository Secrets。
若採用 API 依量計費,可以設定:
ANTHROPIC_API_KEY
若要使用 Claude Pro、Max、Team 或 Enterprise 等訂閱方案,則可以設定:
CLAUDE_CODE_OAUTH_TOKEN
訂閱方案使用的 token,可以在 Terminal 執行以下指令取得:
claude setup-token
執行後,Claude Code 會產生一組可供 CI pipeline 或其他非互動環境使用的長效 OAuth token。
接著進入 GitHub Repository:
Settings
→ Secrets and variables
→ Actions
→ New repository secret

建立名為 CLAUDE_CODE_OAUTH_TOKEN 的 Repository Secret,並把剛剛取得的 token 貼進去。
這組 token 等同於可以使用自己的 Claude 訂閱額度,因此不應直接寫進 YAML、commit 到 GitHub,或出現在 log 中。
建立 GitHub Actions Workflow
接下來可以參考 Claude Code Action 官方提供的 [claude.yml 範例](https://github.com/anthropics/claude-code-action/blob/main/examples/claude.yml),把 workflow YAML 檔放進 Repo 的:
.github/workflows/
我這次測試用的 workflow 可以在這裡看到:
modernapp001/.github/workflows/claude.yml
完整設定如下:
name: Claude Code
on:
issue_comment:
types: [created]
pull_request_review_comment:
types: [created]
pull_request_review:
types: [submitted]
issues:
types: [opened, assigned]
jobs:
claude:
if: |
(github.event_name == 'issue_comment' &&
contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.comment.author_association) &&
contains(github.event.comment.body, '@claude')) ||
(github.event_name == 'pull_request_review_comment' &&
contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.comment.author_association) &&
contains(github.event.comment.body, '@claude')) ||
(github.event_name == 'pull_request_review' &&
contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.review.author_association) &&
contains(github.event.review.body, '@claude')) ||
(github.event_name == 'issues' &&
contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.issue.author_association) &&
(contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude')))
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-${{ github.event.issue.number || github.event.pull_request.number || github.run_id }}
cancel-in-progress: false
permissions:
contents: write
pull-requests: write
issues: write
id-token: write
actions: read
steps:
- name: Checkout repository
uses: actions/checkout@v7
with:
fetch-depth: 1
- name: Run Claude Code
uses: anthropics/claude-code-action@v1
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
claude_args: |
--max-turns 10
這份 YAML 使用的是:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
而不是官方範例中常見的:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
也就是讓 Claude Code Action 使用我的 Claude 訂閱方案,而不是另外透過 Anthropic API 依量計費。
限制可以觸發 Claude 的使用者身份
這份 workflow 另外加入了一項很重要的安全限制。
如果任何外部使用者都能在公開 Repo 的 Issue 或 Pull Request 中留言 @claude,就可能消耗我的 Claude usage,甚至驅動具有寫入權限的 workflow。
根據 GitHub Copilot Code Review 的建議,我加入了 author_association 的身份檢查。
目前只允許以下三種身份觸發 Claude:
OWNERMEMBERCOLLABORATOR
例如 Issue comment 的判斷條件是:
contains(
fromJSON('["OWNER","MEMBER","COLLABORATOR"]'),
github.event.comment.author_association
)
這樣即使外部使用者在 Issue 或 PR 裡留言:
@claude
workflow 也不會真的執行 Claude job。
對於公開 Repository,或是會讓 AI Agent 取得寫入權限的 workflow,我認為這類身份限制相當重要。
避免同一個 Issue 或 PR 同時執行多個 Claude job
另一項合理的建議是加入 concurrency。
這個 workflow 具有 contents: write 權限,而且可能被 Issue comment、PR review comment 等不同事件觸發。
如果同一個 Issue 或 PR 在短時間內觸發多次 Claude run,兩個 runner 就可能同時建立或修改 branch、push commit,甚至更新同一個 Pull Request,進而造成 race condition。
因此我加入:
concurrency:
group: ${{ github.workflow }}-${{ github.event.issue.number || github.event.pull_request.number || github.run_id }}
cancel-in-progress: false
這裡刻意將:
cancel-in-progress: false
設為 false。
我的想法是,同一個 Issue 或 PR 的 Claude run 應該排隊執行,而不是直接取消前一個。
因為使用者有可能連續下達兩個不同的指令。如果第二個指令一出現就取消第一個正在執行的工作,不一定符合原本的操作意圖,也可能留下只完成一半的修改。
在 Issue 或 Pull Request 中呼叫 Claude
當 workflow 合併到 default branch 後,就可以在 Issue 或 Pull Request 中透過 @claude 驅動 Claude Code Action。
例如,可以請 Claude 分析整個 Repository:

也可以請它進行 Code Review:

或者直接從 Issue 開始開發功能:

Claude Code Action 會讀取 Issue、Pull Request 與 Repository 的內容,接著在 GitHub Actions runner 中執行 Claude Code。
有趣的是,Claude Code Action 在完成開發任務後並不會直接自動建立 Pull Request,而是在完成修改後提供一個 Create PR link。
目前實際看到的流程比較像:
Issue
→ Claude 建立 branch
→ 修改程式
→ commit
→ push
→ 在 Issue 留下 Create PR link
而不是:
Issue
→ Claude 建立 branch
→ 修改程式
→ commit
→ push
→ 自動建立 Pull Request
使用者仍然需要點擊 Claude 留下的連結,再由 GitHub 的頁面建立 PR。 不過,如果期待的是完全自動化的:
Issue → 實作 → 測試 → 建立 PR
應該還需要另外設計 workflow step,使用 GitHub CLI、GitHub API,或其他建立 Pull Request 的 Action 來完成。
@claude 不會出現在 GitHub 的自動完成選單
另外一個比較小的使用體驗問題是:
在 GitHub comment box 輸入 @ 時,並不會出現 claude 讓我們選取。
雖然這是正常的,因為這裡的 @claude 比較像是 workflow 用來判斷的觸發文字,而不是一般 GitHub 使用者帳號的 mention,但操作時還是會覺得少了一點自動完成的便利性。
目前看起來沒有很直接的方法,可以把 claude 加進 GitHub comment box 的 mention 建議清單。
因此現階段還是需要手動輸入:
@claude
使用 actionlint 檢查 Workflow
這次設定 workflow 時,我也用到了 actionlint。
actionlint 是一套 GitHub Actions workflow 的靜態檢查工具,可以協助檢查:
- YAML 語法與結構
- GitHub Actions expression
- context 使用錯誤
- event payload 欄位
- workflow 常見設定問題
- 部分 Action 參數問題
在 macOS 上可以透過 Homebrew 安裝:
brew install actionlint
安裝完成後,在 Repository 根目錄執行:
actionlint
它會自動檢查 .github/workflows/ 目錄中的 workflow 檔案。
如果執行後沒有任何輸出,就代表目前沒有檢查到問題。
雖然 GitHub 也會在 workflow 執行時顯示錯誤,但先在本機透過 actionlint 檢查,可以更早發現 YAML、expression 或 context 欄位寫錯等問題,不必每次都 push 到 GitHub 後才知道 workflow 無法執行。
還可以自訂 Claude 的 Prompt
除了透過 @claude 下達個別任務,Claude Code Action 也支援自訂 prompt 與 system prompt。
例如,可以為 Code Review 加入團隊自己的規則; 也可以要求 Claude 遵循 Repository 內的開發規範、測試要求與架構原則。
我相信這類 AI Agent workflow 對軟體開發與 CI/CD 流程會有不少幫助。
它未必會完全取代人工開發或審查,但很適合用來處理初步分析、Review、測試、修正與重複性的開發工作,最後再由工程師理解並確認實際變更。
也歡迎已經在 GitHub 專案中整合 AI Agent 的朋友,分享你們的使用方式與 workflow 設定。
메타데이터
- post_id
- da2161e3971a
- slug
- 把-claude-code-接進-github-從-code-review-修-code-到開發功能-da2161e3971a
- url
- https://medium.com/ddsakura-blog/%E6%8A%8A-claude-code-%E6%8E%A5%E9%80%B2-github-%E5%BE%9E-code-review-%E4%BF%AE-code-%E5%88%B0%E9%96%8B%E7%99%BC%E5%8A%9F%E8%83%BD-da2161e3971a
- canonical_url
- https://medium.com/ddsakura-blog/%E6%8A%8A-claude-code-%E6%8E%A5%E9%80%B2-github-%E5%BE%9E-code-review-%E4%BF%AE-code-%E5%88%B0%E9%96%8B%E7%99%BC%E5%8A%9F%E8%83%BD-da2161e3971a
- author_url
- https://medium.com/@ddsakura
- status
- ok
- fetched_at
- 2026-07-13 14:44:14