code-review

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
Spawn 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

步骤

  1. Get changed files and line ranges — nothing else
    • Per-cycle:
      git show --unified=0 HEAD -- <changed files> | grep -E "^(---|\\+\\+\\+|@@)"
      (identify files from
      git show --name-only HEAD
      )
    • Final review:
      git diff --unified=0 origin/main | grep -E "^(---|\\+\\+\\+|@@)"
      — unless the user pointed at something more specific (a file path, commit ref, or range)
    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 @@
  2. 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
      openspec list --json
      only if you don't already know)
    • 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. Read
    references/reviewer-light.md
    from your skill directory for the review lens.
    Below 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
      openspec/changes/<name>/proposal.md
      and extract capability names under New Capabilities and Modified Capabilities
    • For each capability, read the global spec (
      openspec/specs/<capability>/spec.md
      ) and the delta spec (
      openspec/changes/<name>/specs/<capability>/spec.md
      )
    • Read
      openspec/changes/<name>/tasks.md
      to identify the behavior in scope
    • Skip any
      openspec/changes/**
      entries in the listing — those files are already provided as structured context
    Undeclared impact (code touches something not listed in the proposal) is itself a finding.
    Model: haiku
    Final review subagent instructions:
    You are doing a final code review. Read
    references/reviewer.md
    from your skill directory for the review lens.
    Below 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
      openspec/changes/<name>/proposal.md
      and extract capability names under New Capabilities and Modified Capabilities
    • For each capability, read the global spec (
      openspec/specs/<capability>/spec.md
      ) and the delta spec (
      openspec/changes/<name>/specs/<capability>/spec.md
      )
    • Read
      openspec/changes/<name>/tasks.md
      to identify which behaviors were in scope
    • Skip any
      openspec/changes/**
      entries in the listing — those files are already provided as structured context
    Undeclared impact (code touches something not listed in the proposal) is itself a finding.
    Model: sonnet
  3. Print the full report verbatim. Output the subagent's findings as a text message before doing anything else. Do not skip ahead to fixing.
  4. Act on findings — only after printing. The main Claude acts on findings per the project workflow in CLAUDE.md.
  1. 获取变更文件及行范围——无需其他内容
    • 循环内审查:
      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 @@
  2. 生成子Agent并传入以下信息:
    • 变更行列表(文件名 +
      @@
      行范围,无差异内容)
    • 审查范围:循环内审查或最终审查
    • 是否存在正在进行的OpenSpec变更(仅当未知时运行
      openspec list --json
    • 当前变更的名称(如有)
    子Agent将处理后续所有读取操作——审查参考资料、OpenSpec文件、变更文件。请勿自行预读这些内容。
    循环内审查子Agent指令:
    你正在执行循环内代码审查。请从你的技能目录中读取
    references/reviewer-light.md
    以了解审查视角。
    以下是变更文件及行范围的列表(无差异内容)。对于每个代码块,请直接从文件中读取变更范围前后±30行的上下文——不要请求差异内容。
    如果存在已命名的正在进行的OpenSpec变更,请自行收集上下文:
    • 读取
      openspec/changes/<name>/proposal.md
      ,提取New CapabilitiesModified Capabilities下的功能名称
    • 针对每个功能,读取全局规范(
      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变更,请自行收集上下文:
    • 读取
      openspec/changes/<name>/proposal.md
      ,提取New CapabilitiesModified Capabilities下的功能名称
    • 针对每个功能,读取全局规范(
      openspec/specs/<capability>/spec.md
      )和增量规范(
      openspec/changes/<name>/specs/<capability>/spec.md
    • 读取
      openspec/changes/<name>/tasks.md
      以确定当前范围内的行为
    • 跳过列表中的任何
      openspec/changes/**
      条目——这些文件已作为结构化上下文提供
    未声明的影响(代码触及提案中未列出的内容)本身就是一个审查发现。
    Model: sonnet
  3. 逐字打印完整报告。在执行其他操作前,先将子Agent的审查发现作为文本消息输出。不要直接跳转到修复步骤。
  4. 根据审查发现采取行动——仅在打印报告后执行。主Claude将根据CLAUDE.md中的项目流程处理审查发现。