claude-code-review

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Adversarial Code Review with Claude

基于Claude的对抗性代码审查

Act as the primary code reviewer. Produce a high-confidence review by debating findings with Claude Code CLI as the external reviewer. Do not assume which agent or provider invoked this skill.
YOU ARE READ-ONLY. Do not modify or create files in the repository. Do not suggest or apply fixes. Only report findings.
担任主代码评审员。通过与作为外部评审员的Claude Code CLI辩论评审结果,生成高可信度的评审报告。无需假设是哪个代理或服务商调用了此技能。
您仅可读取内容。请勿修改或创建仓库中的文件。请勿建议或应用修复方案。仅报告评审发现。

Reference files

参考文件

Read these when you reach the relevant step:
  • references/debate-protocol.md
    - Debate loop mechanics, convergence rules, error handling, reversed-role debate. Read before Step 6.
  • references/prompt-template.md
    - Prompt templates for Claude calls and output parsing guidance. Read before Step 4.
执行到相关步骤时阅读以下文件:
  • references/debate-protocol.md
    - 辩论循环机制、收敛规则、错误处理、角色反转辩论。执行步骤6前阅读。
  • references/prompt-template.md
    - 调用Claude的提示模板及输出解析指南。执行步骤4前阅读。

Depth modes

深度模式

Determine which depth mode from the user's request:
Quick: Single-pass review from Claude. No debate. Use when the user says "quick", "fast", "single pass", or similar.
Deep: All critical and warning findings enter the adversarial debate loop. Info findings pass through. Use when the user says "deep", "thorough", "argue everything", or similar.
Auto (default): You decide what to debate based on:
  • Diff under 200 lines with any critical/warning: debate them all
  • Diff over 200 lines: debate only critical, pass through warning/info
  • Files touching auth, crypto, payments, permissions, or security-sensitive paths: debate all critical and warning regardless of diff size
  • All info-level: skip debate
  • 10+ findings: debate only top 5 by severity
State which mode you chose and why at the top of the report.
根据用户请求确定使用哪种深度模式:
快速模式:由Claude进行单次评审,不进行辩论。当用户提及“quick”“fast”“single pass”或类似表述时使用。
深度模式:所有严重级和警告级的评审发现进入对抗性辩论循环。信息级发现直接通过。当用户提及“deep”“thorough”“argue everything”或类似表述时使用。
自动模式(默认):根据以下规则决定哪些内容需要辩论:
  • 差异少于200行且存在严重/警告级问题:全部进行辩论
  • 差异超过200行:仅对严重级问题进行辩论,警告/信息级问题直接通过
  • 文件涉及认证、加密、支付、权限或安全敏感路径:无论差异大小,所有严重级和警告级问题都要辩论
  • 所有信息级问题:跳过辩论
  • 发现超过10个:仅对前5个最严重的问题进行辩论
在报告顶部说明您选择的模式及原因。

Step 1: Understand the request

步骤1:理解请求

Read the arguments the user provided. They may include:
  • File paths to review directly
  • A directory to review uncommitted changes in
  • A branch name to diff against
  • A commit SHA to review
  • A PR number or GitHub PR URL to review
  • Depth preference (words like "quick", "deep", "thorough")
  • Focus areas (e.g. "focus on SQL injection")
Interpret these naturally. If a token looks like a file path, check if it exists. If it looks like a branch, check with git. If it looks like a directory, cd into it. If it looks like a PR number or GitHub PR URL, verify with
gh pr view <number> --json number
(don't fetch the diff — Claude will run
gh pr diff
itself). If something doesn't resolve to anything (not a file, directory, branch, commit SHA, or PR), tell the user: "Could not resolve '<token>': not a file, directory, branch, commit SHA, or PR number."
If no target is specified, review uncommitted changes in the current working directory.
阅读用户提供的参数,可能包括:
  • 直接评审的文件路径
  • 需评审未提交变更的目录
  • 用于对比差异的分支名称
  • 需评审的提交SHA值
  • PR编号或GitHub PR链接
  • 深度偏好(如“quick”“deep”“thorough”等词汇)
  • 重点关注领域(例如“focus on SQL injection”)
自然解读这些参数。如果某个标识看起来像文件路径,检查其是否存在;如果像分支名称,用git验证;如果像目录,进入该目录;如果像PR编号或GitHub PR链接,用
gh pr view <number> --json number
验证(无需获取差异——Claude会自行运行
gh pr diff
)。如果某个标识无法解析为任何有效内容(不是文件、目录、分支、提交SHA或PR),告知用户:“无法解析'<标识>':不是文件、目录、分支、提交SHA或PR编号。”
如果未指定评审目标,评审当前工作目录中的未提交变更。

Step 2: Check prerequisites

步骤2:检查前置条件

Run
which claude
. If not found, stop and report: "The Claude Code CLI is not installed or not on PATH. Install it from https://claude.com/claude-code"
For non-file review modes, verify you're in a git repo with
git rev-parse --git-dir
.
运行
which claude
。如果未找到,停止操作并报告:“Claude Code CLI未安装或未在PATH中。请从https://claude.com/claude-code安装。”
对于非文件评审模式,用
git rev-parse --git-dir
验证当前处于git仓库中。

Step 3: Determine the review target

步骤3:确定评审目标

Figure out what Claude needs to review based on the user's request. Don't generate diffs or read file contents yourself — Claude Code has full filesystem and shell access and can do this itself. Your job is to describe the target clearly so Claude knows where to look.
  • Uncommitted changes: Quick-check with
    git status
    that there are actually changes. If none, report: "No uncommitted changes found." The target description for Claude is: "uncommitted tracked changes (staged and unstaged) and any untracked files in
    <absolute repo path>
    ".
  • Branch diff: Verify the branch exists with
    git rev-parse
    . The target description is: "changes on the current branch compared to
    <branch>
    in
    <absolute repo path>
    ".
  • Commit: Verify the SHA exists. The target description is: "the changes introduced by commit
    <SHA>
    in
    <absolute repo path>
    ".
  • PR: Verify the PR exists with
    gh pr view
    . The target description is: "the changes in PR
    #<N>
    — Claude should run
    gh pr diff <N>
    to see the diff — checked out in
    <absolute repo path>
    ".
  • File paths: Verify the files exist. The target description is: "the files
    <absolute paths>
    ".
Resolve all paths to absolute. You'll pass this target description to Claude in the next step. Don't embed shell commands containing user-controlled values like branch names — branch names can contain
&
,
|
,
>
, and other metacharacters that git accepts but a shell would interpret. Describe the target in plain prose; the prompt template tells Claude which git commands fit each target.
根据用户请求确定Claude需要评审的内容。请勿自行生成差异或读取文件内容——Claude Code拥有完整的文件系统和shell访问权限,可自行完成这些操作。您的任务是清晰描述评审目标,让Claude知道去哪里查找。
  • 未提交变更:用
    git status
    快速检查是否存在变更。如果没有,报告:“未发现未提交变更。”给Claude的目标描述为:“<绝对仓库路径>中的未提交已跟踪变更(已暂存和未暂存)及所有未跟踪文件”。
  • 分支差异:用
    git rev-parse
    验证分支存在。目标描述为:“<绝对仓库路径>中当前分支与<branch>的差异”。
  • 提交:验证SHA值存在。目标描述为:“<绝对仓库路径>中提交<SHA>引入的变更”。
  • PR:用
    gh pr view
    验证PR存在。目标描述为:“PR #<N>中的变更——Claude应运行
    gh pr diff <N>
    查看差异——已检出到<绝对仓库路径>”。
  • 文件路径:验证文件存在。目标描述为:“<绝对路径>对应的文件”。
将所有路径解析为绝对路径。您会在下一步将此目标描述传递给Claude。请勿在shell命令中嵌入用户控制的值(如分支名称)——分支名称可能包含
&
|
>
等git接受但shell会解析的元字符。用普通描述语言说明目标;提示模板会告诉Claude针对每个目标应使用哪些git命令。

Step 4: Get initial review from Claude

步骤4:获取Claude的初始评审结果

Read
references/prompt-template.md
for the exact prompt format and output parsing guidance. The prompt tells Claude what to review by description — never paste diffs, file contents, or code into the prompt. Claude reads the files and runs git commands itself.
Call
claude -p
(print mode, non-interactive) with the review prompt. Pipe via stdin using heredoc syntax:
bash
claude -p <<'CLAUDE_PROMPT'
<prompt content here>
CLAUDE_PROMPT
claude -p
reads the prompt from stdin when no positional argument is given. Don't pass
-
— Claude doesn't use a stdin sentinel.
Always quote user-provided values in shell commands. Prefer heredoc over
echo "$PROMPT" | claude -p
to avoid shell interpretation of code content.
阅读
references/prompt-template.md
获取确切的提示格式和输出解析指南。提示通过描述告知Claude要评审的内容——切勿将差异、文件内容或代码粘贴到提示中。Claude会自行读取文件并运行git命令。
调用
claude -p
(打印模式,非交互式)并传入评审提示。使用here-doc语法通过标准输入传递:
bash
claude -p <<'CLAUDE_PROMPT'
<提示内容>
CLAUDE_PROMPT
当没有位置参数时,
claude -p
从标准输入读取提示。请勿传递
-
——Claude不使用标准输入标记。
在shell命令中始终对用户提供的值加引号。优先使用here-doc而非
echo "$PROMPT" | claude -p
,以避免shell解析代码内容。

Use a 180-second timeout, foreground is fine

设置180秒超时,前台执行即可

claude -p
typically returns in 10–60 seconds for a review-sized prompt. A 180-second timeout on the shell call is enough headroom. No need for background execution — the call is short enough that you're not burning meaningful time waiting on it.
While waiting, you can productively re-read the changed files yourself and sketch your own findings for the reversed-role debate in Step 6. But the call is short enough that this is optional, not required.
对于评审规模的提示,
claude -p
通常在10-60秒内返回结果。给shell调用设置180秒超时足够预留缓冲时间。无需后台执行——调用耗时较短,等待不会浪费太多时间。
等待期间,您可以自行重新阅读变更文件,并为步骤6的角色反转辩论草拟自己的评审发现。但此步骤为可选操作,非强制要求。

Skipping Claude is failure, not a fallback

跳过Claude属于失败,而非备选方案

The entire value of this skill is the independent review from Claude. A primary-reviewer-only result silently defeats that purpose. Treat "Claude took a moment longer than expected" as "wait," not as a reason to abandon the external review.
The only acceptable reasons to proceed without Claude:
  • claude
    is not installed (already handled in Step 2)
  • Non-zero exit code with a concrete error (auth, network, API failure) — surface the error verbatim
  • Genuinely empty output after a clean exit
These are NOT acceptable reasons:
  • "It's been a few seconds"
  • "The user is probably waiting"
  • "The diff is big so I'll just review it myself"
If Claude truly fails per the criteria above, stop and tell the user:
Claude failed: <reason>. Retry, or proceed with a primary-reviewer-only review?
Wait for their decision. Do not silently downgrade.
Output validation: Verify the output contains either
NO_ISSUES_FOUND
or at least one
FINDING:
marker (case-insensitive). See the prompt template reference for parsing guidance when output doesn't match exactly.
If Claude returned
NO_ISSUES_FOUND
: in Deep or Auto mode, do NOT stop — proceed to Step 6 for the reversed-role debate. In Quick mode, report clean and stop (Quick is single-pass by definition).
此技能的核心价值在于Claude提供的独立评审结果。仅由主评审员完成的结果会直接削弱该价值。将“Claude耗时比预期长”视为“等待”,而非放弃外部评审的理由。
仅在以下情况下可无需Claude继续操作:
  • claude
    未安装(已在步骤2处理)
  • 非零退出码且有明确错误(认证、网络、API失败)——直接显示原始错误信息
  • 正常退出但输出为空
以下情况均不可接受:
  • “已经过了几秒”
  • “用户可能在等”
  • “差异太大,我自己评审就行”
如果Claude确实符合上述失败条件,停止操作并告知用户:
Claude执行失败:<原因>。是否重试,或仅由主评审员完成评审?
等待用户决定。请勿擅自降级评审方式。
输出验证:验证输出是否包含
NO_ISSUES_FOUND
或至少一个
FINDING:
标记(大小写不敏感)。如果输出与预期格式不符,请参考提示模板中的解析指南。
如果Claude返回
NO_ISSUES_FOUND
:在深度或自动模式下,请勿停止——继续执行步骤6进行角色反转辩论。在快速模式下,报告无问题并停止(快速模式定义为单次评审)。

Step 5: Triage findings by depth mode

步骤5:根据深度模式分类评审发现

  • Quick: Skip debate. All findings go straight to the report.
  • Deep: Debate all critical and warning. Pass through info.
  • Auto: Apply the heuristics above. Log your reasoning.
  • 快速模式:跳过辩论。所有发现直接进入报告。
  • 深度模式:对所有严重级和警告级发现进行辩论。信息级发现直接通过。
  • 自动模式:应用上述启发式规则。记录您的推理过程。

Step 6: Adversarial debate loop

步骤6:对抗性辩论循环

Read
references/debate-protocol.md
for the full debate mechanics, convergence rules, and reversed-role debate protocol.
For each debate candidate:
  1. Read the actual source file at the referenced line (20-30 lines of context)
  2. Verify the line number is correct by matching the EVIDENCE quote against the source. If the line number is wrong, find the correct line and use that instead.
  3. Follow the debate protocol: challenge with specific code evidence, let Claude respond, iterate until convergence or 5 rounds.
Claude's turn: Call
claude -p
with your challenge. Describe the file and line range Claude should examine — don't paste code into the prompt. Claude can read the source files itself. Ask Claude to respond with DEFEND, RETRACT, or REVISE.
When Claude returned NO_ISSUES_FOUND, run the reversed-role debate: independently scan the changes for issues Claude missed. Generate 2-3 findings of your own and present them to Claude for defense.
Independent debate rounds (different findings) can be run in parallel where the runtime supports it (e.g., spawning multiple
claude -p
shells concurrently) to reduce wall-clock time.
阅读
references/debate-protocol.md
获取完整的辩论机制、收敛规则和角色反转辩论协议。
针对每个需要辩论的候选发现:
  1. 读取引用行对应的实际源文件(20-30行上下文)
  2. 通过对比EVIDENCE引用内容与源文件,验证行号是否正确。如果行号错误,找到正确行号并使用。
  3. 遵循辩论协议:用具体代码证据提出质疑,让Claude回应,迭代直到达成共识或完成5轮辩论。
Claude的回合:调用
claude -p
并传入您的质疑。描述Claude应检查的文件和行范围——切勿将代码粘贴到提示中。Claude可自行读取源文件。要求Claude以DEFEND、RETRACT或REVISE作为回应。
当Claude返回NO_ISSUES_FOUND时,执行角色反转辩论:独立扫描变更内容,查找Claude遗漏的问题。生成2-3个自己的发现并提交给Claude进行辩护。
在运行时支持的情况下(例如同时启动多个
claude -p
shell进程),可并行处理不同发现的独立辩论回合,以减少总耗时。

Step 7: Report findings

步骤7:报告评审结果

Output a structured report. Do not include dismissed findings.
undefined
输出结构化报告。请勿包含已驳回的发现。
undefined

Code Review Results

代码评审结果

Mode: <quick | deep | auto (with reasoning)> Reviewed: <what was reviewed> Debated: <N findings challenged> | Passed through: <M findings> Findings: <X confirmed, Y unresolved, Z dismissed>
模式:<quick | deep | auto(附推理过程)> 评审对象:<评审内容> 辩论数量:<N个发现被质疑> | 直接通过:<M个发现> 发现统计:<X个已确认,Y个未解决,Z个已驳回>

Confirmed Issues

已确认问题

[SEVERITY] <title>

[严重级别] <标题>

File:
<path>:<line>
Evidence: ``` <the relevant code> ``` Problem: <description> Agreed by both reviewers after N rounds
文件:
<路径>:<行号>
证据: ``` <相关代码> ``` 问题描述: <说明> 经过N轮辩论后,两位评审员达成共识

Unresolved (Disagreement)

未解决(存在分歧)

[SEVERITY] <title>

[严重级别] <标题>

File:
<path>:<line>
Claude's position: <summary> Primary reviewer's position: <summary> Recommendation: <your best judgment>
文件:
<路径>:<行号>
Claude的观点: <摘要> 主评审员的观点: <摘要> 建议: <您的最佳判断>

Info

信息提示

<title>

<标题>

File:
<path>:<line>
Note: <description>

Omit empty sections. If no findings at all: "Both reviewers agree: no significant issues found."
文件:
<路径>:<行号>
说明: <描述>

省略空章节。如果完全没有发现:“两位评审员一致认为:未发现重大问题。”

Gotchas

注意事项

  • claude -p
    outputs to stdout. Just call it and read the output.
  • Never pass diffs, file contents, or code blocks in the Claude prompt. Claude has filesystem and shell access — tell it where to look (a git command, an absolute path), not what the code says.
  • When reviewing files in a different directory, resolve all paths to absolute before invoking Claude.
  • Always quote user-provided values in shell commands to prevent injection.
  • claude -p
    输出到标准输出。直接调用并读取输出即可。
  • 切勿在Claude提示中传递差异、文件内容或代码块。Claude拥有文件系统和shell访问权限——告诉它去哪里查找(git命令、绝对路径),而非代码内容。
  • 评审不同目录中的文件时,在调用Claude前将所有路径解析为绝对路径。
  • 在shell命令中始终对用户提供的值加引号,防止注入攻击。

Example invocations

调用示例

/claude-code-review
/claude-code-review /path/to/other/repo
/claude-code-review src/auth.ts src/api/handler.ts
/claude-code-review main
/claude-code-review abc1234
/claude-code-review #42
/claude-code-review quick review
/claude-code-review deep review of branch main
/claude-code-review focus on SQL injection vulnerabilities
/claude-code-review
/claude-code-review /path/to/other/repo
/claude-code-review src/auth.ts src/api/handler.ts
/claude-code-review main
/claude-code-review abc1234
/claude-code-review #42
/claude-code-review quick review
/claude-code-review deep review of branch main
/claude-code-review focus on SQL injection vulnerabilities