code-review
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSpawn a code review subagent with the diff and let it gather its own context.
传入代码差异,生成一个代码审查子Agent,让它自行收集相关上下文。
Determine scope
确定审查范围
- Per-behavior cycle (during openspec apply): the files changed in this RED/GREEN cycle only — not the full diff
- Final review (end of all OpenSpec tasks, user-triggered, or any ad-hoc request): the full branch diff against main
- 单次行为循环(在应用OpenSpec期间):仅本次RED/GREEN循环中变更的文件——而非完整差异
- 最终审查(所有OpenSpec任务结束后、用户触发或任何临时请求):当前分支与main分支的完整差异
Steps
步骤
-
Get changed files and line ranges — nothing else
- Per-cycle: (identify files from
git show --unified=0 HEAD -- <changed files> | grep -E "^(---|\\+\\+\\+|@@)")git show --name-only HEAD - Final review: — unless the user pointed at something more specific (a file path, commit ref, or range)
git diff --unified=0 origin/main | grep -E "^(---|\\+\\+\\+|@@)"
The result is a compact listing of which files changed and which line ranges, with no diff content. Example:--- a/src/foo.py +++ b/src/foo.py @@ -45,3 +45,5 @@ @@ -78,1 +80,1 @@ - Per-cycle:
-
Spawn a subagent and pass it:
- The changed-lines listing (file names + line ranges, no diff content)
@@ - The scope: per-cycle or final review
- Whether an active OpenSpec change exists (run only if you don't already know)
openspec list --json - The active change name, if any
The subagent handles all further reading — reviewer reference, OpenSpec files, changed files. Do not pre-read those yourself.Per-cycle subagent instructions:You are doing a per-cycle code review. Readfrom your skill directory for the review lens.references/reviewer-light.mdBelow is a listing of which files changed and which line ranges (no diff content). For each hunk, read ±30 lines of context around the changed range directly from the file — do not ask for a diff.If an active OpenSpec change is named, gather context yourself:- Read and extract capability names under New Capabilities and Modified Capabilities
openspec/changes/<name>/proposal.md - For each capability, read the global spec () and the delta spec (
openspec/specs/<capability>/spec.md)openspec/changes/<name>/specs/<capability>/spec.md - Read to identify the behavior in scope
openspec/changes/<name>/tasks.md - Skip any entries in the listing — those files are already provided as structured context
openspec/changes/**
Undeclared impact (code touches something not listed in the proposal) is itself a finding.Model: haikuFinal review subagent instructions:You are doing a final code review. Readfrom your skill directory for the review lens.references/reviewer.mdBelow is a listing of which files changed and which line ranges (no diff content). Read each changed file in full before reviewing — use the line ranges only to know which files to open.If an active OpenSpec change is named, gather context yourself:- Read and extract capability names under New Capabilities and Modified Capabilities
openspec/changes/<name>/proposal.md - For each capability, read the global spec () and the delta spec (
openspec/specs/<capability>/spec.md)openspec/changes/<name>/specs/<capability>/spec.md - Read to identify which behaviors were in scope
openspec/changes/<name>/tasks.md - Skip any entries in the listing — those files are already provided as structured context
openspec/changes/**
Undeclared impact (code touches something not listed in the proposal) is itself a finding.Model: sonnet - The changed-lines listing (file names +
-
Print the full report verbatim. Output the subagent's findings as a text message before doing anything else. Do not skip ahead to fixing.
-
Act on findings — only after printing. The main Claude acts on findings per the project workflow in CLAUDE.md.
-
获取变更文件及行范围——无需其他内容
- 循环内审查:(从
git show --unified=0 HEAD -- <changed files> | grep -E "^(---|\\+\\+\\+|@@)"中识别变更文件)git show --name-only HEAD - 最终审查:——除非用户指定了更具体的内容(文件路径、提交引用或范围)
git diff --unified=0 origin/main | grep -E "^(---|\\+\\+\\+|@@)"
结果是一份简洁的列表,包含变更的文件及对应的行范围,无差异内容。示例:--- a/src/foo.py +++ b/src/foo.py @@ -45,3 +45,5 @@ @@ -78,1 +80,1 @@ - 循环内审查:
-
生成子Agent并传入以下信息:
- 变更行列表(文件名 + 行范围,无差异内容)
@@ - 审查范围:循环内审查或最终审查
- 是否存在正在进行的OpenSpec变更(仅当未知时运行)
openspec list --json - 当前变更的名称(如有)
子Agent将处理后续所有读取操作——审查参考资料、OpenSpec文件、变更文件。请勿自行预读这些内容。循环内审查子Agent指令:你正在执行循环内代码审查。请从你的技能目录中读取以了解审查视角。references/reviewer-light.md以下是变更文件及行范围的列表(无差异内容)。对于每个代码块,请直接从文件中读取变更范围前后±30行的上下文——不要请求差异内容。如果存在已命名的正在进行的OpenSpec变更,请自行收集上下文:- 读取,提取New Capabilities和Modified Capabilities下的功能名称
openspec/changes/<name>/proposal.md - 针对每个功能,读取全局规范()和增量规范(
openspec/specs/<capability>/spec.md)openspec/changes/<name>/specs/<capability>/spec.md - 读取以确定当前范围内的行为
openspec/changes/<name>/tasks.md - 跳过列表中的任何条目——这些文件已作为结构化上下文提供
openspec/changes/**
未声明的影响(代码触及提案中未列出的内容)本身就是一个审查发现。Model: haiku最终审查子Agent指令:你正在执行最终代码审查。请从你的技能目录中读取以了解审查视角。references/reviewer.md以下是变更文件及行范围的列表(无差异内容)。审查前请完整读取每个变更文件——仅使用行范围来确定需要打开哪些文件。如果存在已命名的正在进行的OpenSpec变更,请自行收集上下文:- 读取,提取New Capabilities和Modified Capabilities下的功能名称
openspec/changes/<name>/proposal.md - 针对每个功能,读取全局规范()和增量规范(
openspec/specs/<capability>/spec.md)openspec/changes/<name>/specs/<capability>/spec.md - 读取以确定当前范围内的行为
openspec/changes/<name>/tasks.md - 跳过列表中的任何条目——这些文件已作为结构化上下文提供
openspec/changes/**
未声明的影响(代码触及提案中未列出的内容)本身就是一个审查发现。Model: sonnet - 变更行列表(文件名 +
-
逐字打印完整报告。在执行其他操作前,先将子Agent的审查发现作为文本消息输出。不要直接跳转到修复步骤。
-
根据审查发现采取行动——仅在打印报告后执行。主Claude将根据CLAUDE.md中的项目流程处理审查发现。