Repository navigation
Add Claude Code GitHub Workflow - #3
Conversation
Walkthrough新增两个 GitHub Actions 工作流:一个在拉取请求开启/同步时自动运行 Claude 进行代码审查;另一个在议题/评论/评审中检测到“@claude”时按需触发。两者均检出仓库并调用 Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Dev as Developer
participant GH as GitHub
participant WF as Workflow: Claude Code Review
participant Act as Claude Code Action
participant PR as Pull Request
Dev->>GH: Open/Synchronize PR
GH-->>WF: Trigger workflow
WF->>Act: Checkout repo and run action
Act->>PR: Post review comments via gh pr comment
Note over WF,Act: 最小权限与令牌配置
sequenceDiagram
autonumber
actor User as User
participant GH as GitHub
participant WF as Workflow: Claude Code
participant Act as Claude Code Action
participant Thread as Issue/PR Thread
User->>GH: Post comment with "@claude"
GH-->>WF: Trigger (conditional on text match)
WF->>Act: Checkout repo and run action
Act->>Thread: Reply/comment with results
Note over WF,Act: 支持可选 prompt/args 配置
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Pre-merge checks (3 passed)✅ Passed checks (3 passed)
Poem
✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 5
🧹 Nitpick comments (4)
.github/workflows/claude-code-review.yml (3)
6-11: 可选:开启 paths 过滤以节省运行成本若目标仅为代码变更,可启用 paths 过滤,避免文档/配置变更触发。
47-47: 确认 CLAUDE.md 的路径与存在性提示引用“仓库的 CLAUDE.md”。请确认文件是否存在以及路径是否为预期(例如 dev-docs/sdd/CLAUDE.md)。若路径固定,建议在 prompt 中明确指向。
遵循长期记忆要求:对 .github/workflows 变更需获得维护者确认。
20-20: 修复 YAML 格式:移除行尾空格与多余空行
- 移除行尾空格:行 20、27、46、50
- 移除文件末尾多余空行
-# (这些行仅删除了不可见的行尾空格)Also applies to: 27-27, 46-46, 50-50, 55-55
.github/workflows/claude.yml (1)
38-38: 修复 YAML 小问题:行尾空格与空行
- 行 38 存在行尾空格
- 文件末尾有多余空行
- claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}␠ + claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}Also applies to: 50-50
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
.github/workflows/claude-code-review.yml(1 hunks).github/workflows/claude.yml(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-09-09T05:32:43.271Z
Learnt from: CR
PR: lwyBZss8924d/spec-kit-ai-sdd#0
File: dev-docs/sdd/CLAUDE.md:0-0
Timestamp: 2025-09-09T05:32:43.271Z
Learning: Applies to dev-docs/sdd/.github/workflows/** : Modifications to CI/CD under .github/workflows/ require confirmation
Applied to files:
.github/workflows/claude-code-review.yml
🪛 YAMLlint (1.37.1)
.github/workflows/claude-code-review.yml
[error] 20-20: trailing spaces
(trailing-spaces)
[error] 27-27: trailing spaces
(trailing-spaces)
[error] 46-46: trailing spaces
(trailing-spaces)
[error] 50-50: trailing spaces
(trailing-spaces)
[warning] 54-54: too many blank lines (1 > 0)
(empty-lines)
.github/workflows/claude.yml
[error] 38-38: trailing spaces
(trailing-spaces)
[warning] 50-50: too many blank lines (1 > 0)
(empty-lines)
🔇 Additional comments (2)
.github/workflows/claude.yml (2)
37-42: 确认密钥存在并避免日志泄漏请在仓库 Settings → Secrets 中创建 CLAUDE_CODE_OAUTH_TOKEN,并确认 anthropics/claude-code-action 仅将其用于 GitHub 操作认证且不会输出到日志。
29-36: 进一步验证:请确认项目根目录下是否存在 Dependabot 配置(如.github/dependabot.yml或.github/dependabot.yaml)来判断是否已启用 Dependabot 维护。若不存在,请添加对应配置并将第三方 Action(anthropics/claude-code-action)固定到具体 commit SHA。
| jobs: | ||
| claude-review: | ||
| # Optional: Filter by PR author |
There was a problem hiding this comment.
💡 Verification agent
🧩 Analysis chain
防止 fork PR 上的秘密缺失或误触发;为 secrets 与 fork 加保护条件
来自 fork 的 pull_request 运行环境无法访问仓库 secrets,当前作业会失败。建议在作业层添加条件,确保仅在非 fork 且已配置密钥时运行。
jobs:
claude-review:
+ if: ${{ !github.event.pull_request.head.repo.fork && secrets.CLAUDE_CODE_OAUTH_TOKEN != '' }}
runs-on: ubuntu-latestAlso applies to: 21-22, 34-39
为了验证 .github/workflows/claude-code-review.yml 中 claude-review 作业当前是否已包含 if 条件,运行以下脚本查看文件前 100 行内容:
🏁 Script executed:
#!/bin/bash
sed -n '1,100p' .github/workflows/claude-code-review.ymlLength of output: 1892
为 fork PR 添加作业级保护
在 claude-review 作业最上层添加以下 if 判断,确保仅在非 fork 且已配置 secrets.CLAUDE_CODE_OAUTH_TOKEN 时运行,否则因 secrets 不可用导致失败。
jobs:
claude-review:
+ if: ${{ !github.event.pull_request.head.repo.fork && secrets.CLAUDE_CODE_OAUTH_TOKEN != '' }}
runs-on: ubuntu-latest
permissions:📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| jobs: | |
| claude-review: | |
| # Optional: Filter by PR author | |
| jobs: | |
| claude-review: | |
| # Optional: Filter by PR author | |
| if: ${{ !github.event.pull_request.head.repo.fork && secrets.CLAUDE_CODE_OAUTH_TOKEN != '' }} | |
| runs-on: ubuntu-latest | |
| permissions: | |
| # …existing permissions… |
🤖 Prompt for AI Agents
.github/workflows/claude-code-review.yml around lines 13 to 15: add a top-level
if condition on the claude-review job to skip running for forked PRs and when
the CLAUDE_CODE_OAUTH_TOKEN secret is not available; specifically require the PR
head repo to be the same as the base repo (non-fork) and that
secrets.CLAUDE_CODE_OAUTH_TOKEN is set (e.g., if:
github.event.pull_request.head.repo.full_name == github.repository &&
secrets.CLAUDE_CODE_OAUTH_TOKEN != '') so the job is only executed in non-forked
PRs with the secret configured.
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| pull-requests: read | ||
| issues: read | ||
| id-token: write | ||
|
|
There was a problem hiding this comment.
💡 Verification agent
🧩 Analysis chain
权限与评论能力不匹配;精简到最小权限并去除不必要的 OIDC
当前仅授予 read 权限,但步骤要求用 gh pr comment 发表评论;若依赖 GITHUB_TOKEN 评论,需要 pull-requests: write / issues: write;若改由 claude_code_oauth_token 进行评论,则可保持 read,但无需 id-token: write。请二选一并移除多余权限。
[建议修订 - 选项A:使用 GITHUB_TOKEN 评论]
permissions:
contents: read
- pull-requests: read
- issues: read
- id-token: write
+ pull-requests: write
+ issues: write[建议修订 - 选项B:继续用 OAuth 令牌评论(推荐最小权限)]
permissions:
contents: read
pull-requests: read
issues: read
- id-token: writeAlso applies to: 49-54
🏁 Script executed:
#!/bin/bash
set -e
FILE=".github/workflows/claude-code-review.yml"
if [ ! -f "$FILE" ]; then
echo "Error: 未找到工作流文件 $FILE"
exit 1
fi
echo "## 查看文件前 100 行:"
sed -n '1,100p' "$FILE"
echo
echo "## 查找评论相关命令:"
grep -n "gh pr comment" "$FILE" || echo "未发现 gh pr comment 用法"
echo
echo "## 查找 OIDC 与 id-token 权限使用:"
grep -n "id-token" "$FILE" || echo "未发现 id-token 字样"
grep -n "uses:.*oidc" "$FILE" || echo "未发现 OIDC 用法"Length of output: 2275
精简权限:移除 id-token 或调整 pull-requests 写权限
- 选项 A(使用 GITHUB_TOKEN 留言):
permissions:
contents: read
- pull-requests: read
+ pull-requests: write
issues: read
- id-token: write- 选项 B(继续使用 claude_code_oauth_token):
permissions:
contents: read
pull-requests: read
issues: read
- id-token: write📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| pull-requests: read | |
| issues: read | |
| id-token: write | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| issues: read |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| pull-requests: read | |
| issues: read | |
| id-token: write | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| pull-requests: read | |
| issues: read |
🧰 Tools
🪛 YAMLlint (1.37.1)
[error] 27-27: trailing spaces
(trailing-spaces)
🤖 Prompt for AI Agents
.github/workflows/claude-code-review.yml lines 21-27: 当前 workflow 同时授予 id-token:
write 和 pull-requests: read,审查建议要求精简权限;如果改为使用 GITHUB_TOKEN 留言,删除 id-token: write
并保留或设置 pull-requests: write 为需要的最小权限以便留言;如果继续使用 claude_code_oauth_token 则移除
id-token: write 并将 pull-requests 权限改为 write(或者仅保留 read 并改用外部 token
完成写入),确保只授予执行所需的最小权限且在文档中注明为什么需要该权限。
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 1 | ||
|
|
||
| - name: Run Claude Code Review | ||
| id: claude-review | ||
| uses: anthropics/claude-code-action@v1 |
There was a problem hiding this comment.
💡 Verification agent
🧩 Analysis chain
将第三方 Action 固定到 commit SHA,降低供应链风险
目前使用浮动标签 @v4 / @v1。请固定到具体 commit SHA,并由 Dependabot 定期更新。
示例(请替换为官网公布的最新 SHA):
-uses: actions/checkout@v4
+uses: actions/checkout@<commit-sha>
...
-uses: anthropics/claude-code-action@v1
+uses: anthropics/claude-code-action@<commit-sha>[建议查证最新可用 SHA]
🌐 Web query:
请查询 actions/checkout@v4 与 anthropics/claude-code-action@v1 的当前推荐 pin 的 commit SHA。
💡 Result:
actions/checkout@v4 的推荐 pin(v4 对应的 commit SHA):
08eba0b27e820071cde6df949e0beb9ba4906955。[1]
anthropics/claude-code-action@v1 的推荐 pin(v1 当前指向的 commit SHA):
fd2c17f101639b10696381c1fd85fa735239090a。[2]
Sources:
[1] actions/checkout — tag v4 commit.
[2] anthropics/claude-code-action — tag v1 commit.
固定第三方 Action 到具体 commit SHA 降低供应链风险
- uses: actions/checkout@v4
+ uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955
…
- uses: anthropics/claude-code-action@v1
+ uses: anthropics/claude-code-action@fd2c17f101639b10696381c1fd85fa735239090a请由 Dependabot 定期检查并更新以上 SHA。
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 1 | |
| - name: Run Claude Code Review | |
| id: claude-review | |
| uses: anthropics/claude-code-action@v1 | |
| uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 | |
| with: | |
| fetch-depth: 1 | |
| - name: Run Claude Code Review | |
| id: claude-review | |
| uses: anthropics/claude-code-action@fd2c17f101639b10696381c1fd85fa735239090a |
🤖 Prompt for AI Agents
.github/workflows/claude-code-review.yml lines 30-36: third-party Actions are
referenced by floating tags which is a supply-chain risk; replace the uses
entries (e.g., actions/checkout@v4 and anthropics/claude-code-action@v1) with
pinned refs that include the exact commit SHA (e.g.,
actions/checkout@<commit-sha> and anthropics/claude-code-action@<commit-sha>),
commit the updated workflow, and add/configure Dependabot to periodically check
and open PRs to update those pinned SHAs so they stay up-to-date.
| if: | | ||
| (github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) || | ||
| (github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) || | ||
| (github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) || | ||
| (github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude'))) | ||
| runs-on: ubuntu-latest |
There was a problem hiding this comment.
🛠️ Refactor suggestion
与 PR 说明不一致:当前任何人@claude均可触发;需限制为具写权限成员
PR 说明称“仅具有写权限的用户可触发”,但 if 条件只检查包含“@claude”,未限制触发者。请加入 author_association 约束。
- claude:
- if: |
- (github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
- (github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
- (github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) ||
- (github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude')))
+ claude:
+ if: |
+ (
+ github.event_name == 'issue_comment' &&
+ contains(github.event.comment.body, '@claude') &&
+ (github.event.comment.author_association == 'OWNER' || github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'COLLABORATOR')
+ ) || (
+ github.event_name == 'pull_request_review_comment' &&
+ contains(github.event.comment.body, '@claude') &&
+ (github.event.comment.author_association == 'OWNER' || github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'COLLABORATOR')
+ ) || (
+ github.event_name == 'pull_request_review' &&
+ contains(github.event.review.body, '@claude') &&
+ (github.event.review.author_association == 'OWNER' || github.event.review.author_association == 'MEMBER' || github.event.review.author_association == 'COLLABORATOR')
+ ) || (
+ github.event_name == 'issues' &&
+ (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude')) &&
+ (github.event.issue.author_association == 'OWNER' || github.event.issue.author_association == 'MEMBER' || github.event.issue.author_association == 'COLLABORATOR')
+ )📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if: | | |
| (github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) || | |
| (github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) || | |
| (github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) || | |
| (github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude'))) | |
| runs-on: ubuntu-latest | |
| claude: | |
| if: | | |
| ( | |
| github.event_name == 'issue_comment' && | |
| contains(github.event.comment.body, '@claude') && | |
| (github.event.comment.author_association == 'OWNER' || github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'COLLABORATOR') | |
| ) || ( | |
| github.event_name == 'pull_request_review_comment' && | |
| contains(github.event.comment.body, '@claude') && | |
| (github.event.comment.author_association == 'OWNER' || github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'COLLABORATOR') | |
| ) || ( | |
| github.event_name == 'pull_request_review' && | |
| contains(github.event.review.body, '@claude') && | |
| (github.event.review.author_association == 'OWNER' || github.event.review.author_association == 'MEMBER' || github.event.review.author_association == 'COLLABORATOR') | |
| ) || ( | |
| github.event_name == 'issues' && | |
| (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude')) && | |
| (github.event.issue.author_association == 'OWNER' || github.event.issue.author_association == 'MEMBER' || github.event.issue.author_association == 'COLLABORATOR') | |
| ) | |
| runs-on: ubuntu-latest |
🤖 Prompt for AI Agents
.github/workflows/claude.yml lines 15-20: the if-condition currently triggers on
any "@claude" mention regardless of who posted it; update each branch to also
require the actor's author_association to indicate write-level access by adding
checks like github.event.comment.author_association,
github.event.review.user.author_association and
github.event.issue.author_association and require one of the write-level values
(e.g. 'COLLABORATOR' or 'MEMBER' or 'OWNER'); apply these additional
author_association checks alongside the existing contains('@claude') checks for
issue_comment, pull_request_review_comment, pull_request_review and issues
branches so only users with write permissions can trigger the workflow.
| permissions: | ||
| contents: read | ||
| pull-requests: read | ||
| issues: read | ||
| id-token: write | ||
| actions: read # Required for Claude to read CI results on PRs | ||
| steps: |
There was a problem hiding this comment.
💡 Verification agent
🧩 Analysis chain
精简权限;评估是否需要 id-token: write
除非确有 OIDC 联邦需求,否则去掉 id-token: write。actions: read 仅在需要读 CI 结果时保留。
permissions:
contents: read
pull-requests: read
issues: read
- id-token: write
actions: read # Required for Claude to read CI results on PRs🏁 Script executed:
#!/bin/bash
# 定位 claude.yml 文件
file=$(fd claude.yml .github/workflows)
if [ -z "$file" ]; then
echo "未找到 .github/workflows/claude.yml"
exit 1
fi
echo "文件路径:$file"
# 输出文件前 200 行,便于检查 OIDC、id-token 用法
sed -n '1,200p' "$file"Length of output: 1980
删除不必要的 id-token: write 权限
除非使用 OIDC 联邦身份验证,否则可移除 id-token: write。 (awesome.ecosyste.ms)
permissions:
contents: read
pull-requests: read
issues: read
- id-token: write
actions: read # Required for Claude to read CI results on PRs📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| permissions: | |
| contents: read | |
| pull-requests: read | |
| issues: read | |
| id-token: write | |
| actions: read # Required for Claude to read CI results on PRs | |
| steps: | |
| permissions: | |
| contents: read | |
| pull-requests: read | |
| issues: read | |
| actions: read # Required for Claude to read CI results on PRs | |
| steps: |
🤖 Prompt for AI Agents
.github/workflows/claude.yml around lines 21 to 27: the workflow currently
grants id-token: write which is unnecessary unless you use OIDC federated
authentication; remove the "id-token: write" permission line (or set it to
"none"/omit it) to follow least-privilege practices and keep other permissions
as-is.
🤖 AI Code Review - comprehensivePR #3 Review Summary
|
@claude Claude, a member of the AI Engineer team, needs to add new issues to address any problems identified above. |
|
Claude finished @lwyBZss8924d's task —— View job Creating GitHub Issues for PR #3 Review FeedbackBased on the automated review feedback, I need to create GitHub issues to address the identified problems from the merged PR #3 that added Claude Code GitHub Actions workflows. Issues to Create:Issue 1: Add Specification for GitHub Actions Workflow FeatureTitle: Missing specification for Claude Code GitHub Actions integration Description: Acceptance Criteria:
Priority: Medium Issue 2: Add Tests for GitHub Actions WorkflowsTitle: Missing tests for Claude Code GitHub Actions workflows Description: Acceptance Criteria:
Technical Notes:
Priority: High Issue 3: Implement Security Scanning for GitHub ActionsTitle: Add actual security scanning implementation for GitHub Actions workflows Description: Acceptance Criteria:
Technical Implementation:
Priority: High Issue 4: Address CodeRabbit Technical FeedbackTitle: Fix GitHub Actions workflow configuration issues identified by CodeRabbit Description: Specific Issues:
Acceptance Criteria:
Priority: High Since I cannot directly create GitHub issues, you can create these issues manually in the repository. Each issue is structured with clear acceptance criteria and priorities based on the automated review feedback. The key problems identified were:
All issues reference PR #3 and provide actionable next steps for addressing the review feedback. |
Addresses CodeQL security warnings about missing workflow permissions. Following the principle of least privilege, all jobs now explicitly declare 'contents: read' permission only. Security improvements: - Added global default permissions at workflow level - Each job explicitly declares minimal required permissions - Prevents unintended write access via GITHUB_TOKEN - Complies with GitHub Actions security best practices Fixes 6 CodeQL alerts: #1, #2, #3, #4, #6, #7
🤖 Installing Claude Code GitHub App
This PR adds a GitHub Actions workflow that enables Claude Code integration in our repository.
What is Claude Code?
Claude Code is an AI coding agent that can help with:
How it works
Once this PR is merged, we'll be able to interact with Claude by mentioning @claude in a pull request or issue comment.
Once the workflow is triggered, Claude will analyze the comment and surrounding context, and execute on the request in a GitHub action.
Important Notes
Security
There's more information in the Claude Code action repo.
After merging this PR, let's try mentioning @claude in a comment on any PR to get started!
Summary by CodeRabbit
新功能
Chores