github-review-pr

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Review GitHub Pull Request

审查GitHub Pull Request

A structured, multi-agent workflow for thorough code reviews on GitHub PRs. The approach uses parallel specialized reviewers, confidence scoring, and false positive filtering to produce high-signal, actionable feedback.
Use
gh
for all GitHub interactions. Do not use web fetch or attempt to build/typecheck the app — CI handles that separately.
这是一个用于对GitHub PR进行全面代码审查的结构化多Agent工作流。该方法使用并行的专业审查者、置信度评分和误报过滤机制,以产出高价值、可落地的反馈。
所有GitHub交互均使用
gh
工具完成。请勿使用web fetch或尝试构建/类型检查应用——CI会单独处理这些任务。

Workflow

工作流

1. Eligibility Check

1. 资格检查

Use a subagent to verify the PR is eligible for review. Skip the review if any of these are true:
  • The PR is closed or merged
  • The PR is a draft
  • The PR doesn't need review (e.g., automated/bot PR, or trivially simple)
  • You've already left a code review comment on it
If no PR number is provided, run
gh pr list
to show open PRs and ask which one to review.
使用子代理验证PR是否符合审查条件。若出现以下任一情况,则跳过审查:
  • PR已关闭或合并
  • PR为草稿状态
  • PR无需审查(例如自动化/机器人提交的PR,或内容极其简单的PR)
  • 你已针对该PR留下过代码审查评论
若未提供PR编号,运行
gh pr list
展示所有开放PR,并询问用户要审查哪一个。

2. Gather Context (parallel)

2. 收集上下文(并行执行)

Launch two subagents in parallel:
Subagent A — Project guidance discovery: Find all relevant CLAUDE.md and AGENTS.md files — check the repo root and any directories whose files the PR modified. Return a list of file paths (not contents).
Subagent B — PR summary: View the PR with
gh pr view
and
gh pr diff
, then return a concise summary of what changed.
启动两个并行子代理:
子代理A — 项目指南发现:查找所有相关的CLAUDE.md和AGENTS.md文件——检查仓库根目录以及PR修改过的文件所在的所有目录。返回文件路径列表(无需返回文件内容)。
子代理B — PR摘要:通过
gh pr view
gh pr diff
查看PR,然后返回变更内容的简洁摘要。

3. Parallel Code Review (5 specialized agents)

3. 并行代码审查(5个专业Agent)

Launch 5 parallel subagents, each reviewing the PR from a different angle. Each agent should return a list of issues found, with a reason tag for why it was flagged (e.g., "CLAUDE.md adherence", "bug", "historical git context", "past PR feedback", "code comment violation").
AgentFocusApproach
#1 CLAUDE.md / AGENTS.md complianceCheck changes against project guidanceRead the CLAUDE.md and AGENTS.md files from step 2. Note that these files are guidance for AI agents as they write code, so not all instructions apply during code review.
#2 Shallow bug scanObvious bugs in the diffRead only the changed lines (avoid extra context beyond the diff). Focus on significant bugs, not nitpicks. Ignore likely false positives.
#3 Git history contextBugs visible through historical contextRead
git blame
and history of modified code. Identify issues that become apparent in light of how the code evolved.
#4 Past PR feedbackRecurring issuesFind previous PRs that touched these files. Check their comments for feedback that may also apply here.
#5 Code comment complianceRespect inline guidanceRead code comments in modified files. Verify the PR changes comply with any guidance expressed in those comments.
启动5个并行子代理,每个代理从不同角度审查PR。每个代理应返回发现的问题列表,并附上标记问题原因的标签(例如"CLAUDE.md adherence"、"bug"、"historical git context"、"past PR feedback"、"code comment violation")。
Agent审查重点执行方式
#1 CLAUDE.md / AGENTS.md合规性检查变更是否符合项目指南阅读步骤2中的CLAUDE.md和AGENTS.md文件。请注意,这些文件是AI Agent编写代码时的指南,并非所有指令都适用于代码审查环节。
#2 浅层漏洞扫描差异中的明显漏洞仅阅读变更的代码行(避免查看差异之外的额外上下文)。重点关注严重漏洞,而非琐碎细节。忽略可能的误报。
#3 Git历史上下文通过历史上下文发现的漏洞阅读修改代码的
git blame
和历史记录。识别结合代码演变过程后显现的问题。
#4 过往PR反馈重复出现的问题查找曾修改过这些文件的过往PR。检查其中的评论,看是否有适用于本次PR的反馈。
#5 代码注释合规性遵循内联指南阅读修改文件中的代码注释。验证PR变更是否符合注释中表达的任何指南要求。

4. Confidence Scoring

4. 置信度评分

For each issue found in step 3, launch a parallel subagent that receives the PR context, the issue description, and the CLAUDE.md/AGENTS.md file list. The subagent scores the issue on a 0-100 confidence scale:
ScoreMeaning
0False positive that doesn't stand up to light scrutiny, or a pre-existing issue.
25Might be real, but could be a false positive. Couldn't verify. If stylistic, not explicitly called out in CLAUDE.md or AGENTS.md.
50Verified as real, but may be a nitpick or unlikely to hit in practice. Not very important relative to the rest of the PR.
75Double-checked and very likely real. Will be hit in practice. The existing approach is insufficient. Important for functionality, or directly mentioned in CLAUDE.md/AGENTS.md.
100Definitely real and confirmed. Will happen frequently. Evidence directly confirms the issue.
For issues flagged due to CLAUDE.md/AGENTS.md instructions, the scoring agent should double-check that the relevant file actually calls out that issue specifically.
针对步骤3中发现的每个问题,启动一个并行子代理,该代理会接收PR上下文、问题描述以及CLAUDE.md/AGENTS.md文件列表。子代理需对问题进行0-100分的置信度评分:
分数含义
0经初步检查即可判定为误报,或属于预先存在的问题。
25可能是真实问题,但也可能是误报,无法验证。若为风格问题,CLAUDE.md或AGENTS.md中未明确提及。
50已验证为真实问题,但可能是琐碎细节或实际场景中不太可能出现的问题。相对于PR的其他内容,重要性较低。
75经双重检查,极有可能是真实问题,实际场景中会出现。现有处理方式存在不足。对功能至关重要,或CLAUDE.md/AGENTS.md中直接提及。
100确定为真实问题且已确认,会频繁出现。有直接证据证实该问题。
对于因CLAUDE.md/AGENTS.md指令标记的问题,评分代理需再次确认相关文件是否明确提及该问题。

5. Filter

5. 过滤

Discard any issues scoring below 80. If no issues meet this threshold, skip to posting the "no issues found" comment.
丢弃所有评分低于80的问题。若没有问题达到此阈值,则直接发布“未发现问题”的评论。

6. Re-check Eligibility

6. 重新检查资格

Before posting, use a subagent to repeat the eligibility check from step 1. PRs can be closed or updated while the review runs.
发布评论前,使用子代理重复步骤1的资格检查。PR可能在审查过程中被关闭或更新。

7. Post Review Comment

7. 发布审查评论

Use
gh
to comment on the PR with findings. Follow these rules:
  • Keep output brief
  • No emojis
  • Link and cite relevant code, files, and URLs
  • You must provide the full git SHA in links (not
    $(git rev-parse HEAD)
    — the comment renders as Markdown)
  • Provide at least 1 line of context before and after the issue line in link ranges
使用
gh
工具在PR上发布评论,展示审查结果。需遵循以下规则:
  • 内容保持简洁
  • 不使用表情符号
  • 链接并引用相关代码、文件和URL
  • 链接中必须提供完整的git SHA(不能使用
    $(git rev-parse HEAD)
    ——评论需以Markdown格式呈现)
  • 链接范围需包含问题代码行前后至少1行上下文

Comment format — issues found

发现问题时的评论格式

markdown
undefined
markdown
undefined

Code review

Code review

Found 3 issues:
  1. <brief description> (CLAUDE.md says "<quote>")
  1. <brief description> (AGENTS.md says "<quote>")
  1. <brief description> (bug due to <file and code snippet>)
<sub>- If this code review was useful, please react with a thumbs up. Otherwise, react with a thumbs down.</sub>
undefined
Found 3 issues:
  1. <brief description> (CLAUDE.md says "<quote>")
  1. <brief description> (AGENTS.md says "<quote>")
  1. <brief description> (bug due to <file and code snippet>)
<sub>- If this code review was useful, please react with a thumbs up. Otherwise, react with a thumbs down.</sub>
undefined

Comment format — no issues found

未发现问题时的评论格式

markdown
undefined
markdown
undefined

Code review

Code review

No issues found. Checked for bugs, CLAUDE.md, and AGENTS.md compliance.
undefined
No issues found. Checked for bugs, CLAUDE.md, and AGENTS.md compliance.
undefined

Link format

链接格式

Links must follow this exact format for Markdown rendering to work:
https://github.com/OWNER/REPO/blob/FULL_SHA/path/to/file.ext#L[start]-L[end]
  • Full 40-character git SHA (no shell expansion)
  • Repo name must match the repo being reviewed
  • #
    after the file name
  • Line range as
    L[start]-L[end]
  • Include at least 1 line of context before/after (e.g., commenting on lines 5-6 should link
    L4-L7
    )
链接必须遵循以下精确格式,以确保Markdown渲染正常:
https://github.com/OWNER/REPO/blob/FULL_SHA/path/to/file.ext#L[start]-L[end]
  • 完整的40位git SHA(不使用shell展开)
  • 仓库名称必须与正在审查的仓库一致
  • 文件名后需加
    #
  • 行范围格式为
    L[start]-L[end]
  • 需包含问题代码行前后至少1行上下文(例如,针对第5-6行的评论应链接
    L4-L7

False Positive Examples

误报示例

These should be filtered out during steps 3-5. Share this context with the review and scoring agents:
  • Pre-existing issues (not introduced by this PR)
  • Something that looks like a bug but isn't actually one
  • Pedantic nitpicks a senior engineer wouldn't flag
  • Issues a linter, typechecker, or compiler would catch (imports, types, formatting, test failures)
  • General code quality concerns (test coverage, docs, broad security) unless explicitly required in CLAUDE.md or AGENTS.md
  • Issues called out in CLAUDE.md/AGENTS.md but explicitly silenced in code (e.g., lint ignore comments)
  • Intentional functionality changes directly related to the PR's purpose
  • Real issues on lines the author did not modify
以下情况应在步骤3-5中被过滤掉。请将此上下文告知审查和评分代理:
  • 预先存在的问题(并非由本次PR引入)
  • 看似漏洞但实际并非漏洞的情况
  • 资深工程师不会标记的琐碎细节
  • 代码检查器、类型检查器或编译器可发现的问题(导入、类型、格式、测试失败)
  • 一般性代码质量问题(测试覆盖率、文档、广泛的安全问题),除非CLAUDE.md或AGENTS.md明确要求检查
  • CLAUDE.md/AGENTS.md中提及但代码中明确忽略的问题(例如lint忽略注释)
  • 与PR目的直接相关的有意功能变更
  • 作者未修改的代码行上存在的真实问题

gh Command Reference

gh命令参考

sh
undefined
sh
undefined

List open PRs

List open PRs

gh pr list
gh pr list

View PR description and metadata

View PR description and metadata

gh pr view 78
gh pr view 78

View PR code changes

View PR code changes

gh pr diff 78
gh pr diff 78

Get repo owner/name

Get repo owner/name

gh repo view --json nameWithOwner --jq '.nameWithOwner'
gh repo view --json nameWithOwner --jq '.nameWithOwner'

Get PR head commit SHA (full 40-char)

Get PR head commit SHA (full 40-char)

gh api repos/OWNER/REPO/pulls/78 --jq '.head.sha'
gh api repos/OWNER/REPO/pulls/78 --jq '.head.sha'

Post a comment on the PR

Post a comment on the PR

gh pr comment 78 --body "### Code review ..."
gh pr comment 78 --body "### Code review ..."

Post inline review comment on a specific file/line

Post inline review comment on a specific file/line

gh api repos/OWNER/REPO/pulls/78/comments
--method POST
--field body="[your-comment]"
--field commit_id="[full-sha]"
--field path="path/to/file"
--field line=42
--field side="RIGHT"
undefined
gh api repos/OWNER/REPO/pulls/78/comments
--method POST
--field body="[your-comment]"
--field commit_id="[full-sha]"
--field path="path/to/file"
--field line=42
--field side="RIGHT"
undefined