Skip to content

feat: Claude Code PR review & @claude comment Actions#3

Merged
lishuceo merged 3 commits into
mainfrom
feat/github-actions-claude-review
Feb 17, 2026
Merged

feat: Claude Code PR review & @claude comment Actions#3
lishuceo merged 3 commits into
mainfrom
feat/github-actions-claude-review

Conversation

@lishuceo
Copy link
Copy Markdown
Owner

Summary

  • Add automatic Claude Code review on PR open/sync (Opus model, inline comments, confidence scoring)
  • Add @claude trigger in PR comments for on-demand AI assistance
  • Progress tracking, git blame analysis, full source file reading for deep context

New Files

  • .github/workflows/pr-review.yml — Auto PR review
  • .github/workflows/claude-comment.yml@claude comment response

Prerequisites

Add ANTHROPIC_API_KEY to repo Settings → Secrets → Actions

Test Plan

  • Verify this PR itself triggers the review action (check Actions tab)
  • Comment @claude what does this PR do? to test comment response
  • Verify inline comments appear on code lines
  • Check progress tracking shows real-time status

🤖 Generated with Claude Code

- Auto review on PR open/sync using Opus model with inline comments
- @claude trigger in PR comments/reviews for on-demand assistance
- Confidence scoring (≥75) to minimize false positives
- Progress tracking, git blame analysis, full file context reading

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Owner Author

@lishuceo lishuceo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review: Claude Code PR Review & @claude Comment Actions

总体评价

这是一个高质量的 PR。Prompt 工程做得很好——confidence scoring、false positive filters、分步 review 流程都是经过思考的设计。整体可以合并,有几个小点值得注意。

Action 运行状态

从 CI 日志看到本次 action 因 workflow validation 被跳过:

Skipping action due to workflow validation: Workflow file must exist and have identical content to the version on the repository's default branch.

这是预期行为——claude-code-action@v1 要求 workflow 文件已存在于 default branch(安全机制,防止 PR 注入恶意 workflow)。合并到 main 后才会生效。 PR body 的 test plan 第一项 "Verify this PR itself triggers the review action" 实际上无法通过,建议更新。

亮点

  • Confidence scoring (≥75) — 有效减少 false positive 噪音,这是很多 AI review 方案缺失的
  • False positive filters — 明确列出不报告的类别(pre-existing issues, style nitpicks, hypothetical problems),指导性很强
  • concurrency: cancel-in-progress — PR review 有并发控制,push 新 commit 会取消旧 review,避免浪费
  • Draft PR 跳过if: !github.event.pull_request.draft,正确
  • fetch-depth: 0 — 拉全量 git history,git blamegit log 才能工作
  • $10 budget cap — 合理的单次上限
  • 分步 review prompt — Setup → Process → What to Look For → Output Format,结构清晰

需关注的问题

详见 inline comments。

# 严重度 问题
1 Medium claude-comment.yml 缺少 concurrency 控制
2 Low --model opus shorthand 可能随 CLI 版本变化
3 Info Test plan 第一项因 workflow validation 机制无法验证
4 Info 无每日预算上限,write 权限用户可反复触发

🤖 Reviewed by Claude Code

actions: read

jobs:
respond:
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Medium] 缺少 concurrency 控制

pr-review.ymlconcurrency: cancel-in-progress: true,但 claude-comment.yml 没有。如果有人快速发多条 @claude 评论,会同时触发多个 action 实例,可能导致:

  • 重复回复
  • 并发超出 API budget
  • 竞争写同一个 PR comment

建议加上:

concurrency:
  group: claude-comment-${{ github.event.issue.number || github.event.pull_request.number }}
  cancel-in-progress: true

或者如果希望每条 @claude 评论都得到回复(不取消),至少加 cancel-in-progress: false 做队列化。

anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
track_progress: true
claude_args: |
--model opus
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Low] --model opus shorthand 建议改为完整 model ID

Claude Code CLI 支持 opus 作为 shorthand,但它解析为当前最新的 Opus 模型。如果未来 CLI 更新改变了 shorthand 映射,review 质量可能突然变化且不易察觉。

建议显式指定完整 model ID:

--model claude-opus-4-6

这样 review 结果在不同时间点保持一致,也方便回溯。


jobs:
respond:
if: |
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Info] issue_comment 事件在 fork PR 上的行为

issue_comment 事件的 GITHUB_TOKEN 权限由 base repo 决定(不是 fork),所以 fork PR 的评论也能正常触发。但 actions/checkout@v4 默认 checkout 的是 base repo 的代码,不是 fork 的 PR 分支。

对于 fork PR 的 @claude 请求,Claude 读到的代码可能不包含 PR 的变更。如果需要支持 fork PR,checkout step 需要改为:

- uses: actions/checkout@v4
  with:
    fetch-depth: 0
    ref: ${{ github.event.pull_request.head.sha }}

不过 claude-code-action@v1 可能内部已处理此问题,如果只在自有仓库使用可以忽略。

claude_args: |
--model opus
--max-budget-usd 10
--allowedTools "mcp__github_inline_comment__create_inline_comment,Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*),Bash(gh pr checks:*),Bash(git log:*),Bash(git blame:*),Bash(git diff:*),Read,Glob,Grep"
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Info] allowedTools 白名单完整性

当前白名单:

mcp__github_inline_comment__create_inline_comment
Bash(gh pr comment:*)
Bash(gh pr diff:*)
Bash(gh pr view:*)
Bash(gh pr checks:*)
Bash(git log:*)
Bash(git blame:*)
Bash(git diff:*)
Read, Glob, Grep

看起来很完整。几个观察:

  • Write / Edit 未列入,意味着 Claude 不能修改代码文件(只能 review,不能 auto-fix)。这是故意的且合理的——review bot 不应该修改代码。
  • Bash(git show:*) 可能会用到(查看特定 commit 内容),但 Read + git diff 基本可以覆盖。
  • Bash(gh api:*) 未列入,限制了 Claude 对 GitHub API 的访问范围。这是好的安全限制。

lishuceo and others added 2 commits February 17, 2026 13:25
- Add concurrency control to claude-comment workflow (cancel-in-progress: false for queue behavior)
- Use explicit model ID claude-opus-4-6 instead of opus shorthand

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@lishuceo lishuceo merged commit 3dc19b1 into main Feb 17, 2026
1 check failed
@lishuceo lishuceo deleted the feat/github-actions-claude-review branch February 17, 2026 05:31
@claude
Copy link
Copy Markdown

claude Bot commented Feb 17, 2026

Claude encountered an error —— View job


I'll analyze this and get back to you.

lishuceo added a commit that referenced this pull request Apr 8, 2026
* feat: add Claude Code PR review and @claude comment GitHub Actions

- Auto review on PR open/sync using Opus model with inline comments
- @claude trigger in PR comments/reviews for on-demand assistance
- Confidence scoring (≥75) to minimize false positives
- Progress tracking, git blame analysis, full file context reading

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: address PR review feedback

- Add concurrency control to claude-comment workflow (cancel-in-progress: false for queue behavior)
- Use explicit model ID claude-opus-4-6 instead of opus shorthand

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* refactor: use opus alias to always track latest model

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant