plan-local-code-review

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
Provide a code review for the local changes on the current branch compared to the main branch.
To do this, follow these steps precisely:
  1. Use a Haiku agent to check the current git state:
    • Run
      git branch --show-current
      to get the current branch name
    • Run
      git log main..HEAD --oneline
      to see commits on this branch
    • Run
      git diff main...HEAD --stat
      to see changed files
    • If the current branch IS main, or there are no commits/changes compared to main, do not proceed.
  2. Use another Haiku agent to give you a list of file paths to (but not the contents of) any relevant CLAUDE.md files from the codebase: the root CLAUDE.md file (if one exists), as well as any CLAUDE.md files in the directories whose files were modified on this branch
  3. Use a Haiku agent to analyze the branch changes:
    • Run
      git log main..HEAD --format="%s%n%b"
      to get commit messages
    • Run
      git diff main...HEAD
      to get the full diff
    • Return a summary of the changes
  4. Then, launch 5 parallel Sonnet agents to independently code review the change. The agents should do the following, then return a list of issues and the reason each issue was flagged (eg. CLAUDE.md adherence, bug, historical git context, etc.): a. Agent #1: Audit the changes to make sure they comply with the CLAUDE.md. Note that CLAUDE.md is guidance for Claude as it writes code, so not all instructions will be applicable during code review. b. Agent #2: Read the file changes (via
    git diff main...HEAD
    ), then do a shallow scan for obvious bugs. Avoid reading extra context beyond the changes, focusing just on the changes themselves. Focus on large bugs, and avoid small issues and nitpicks. Ignore likely false positives. c. Agent #3: Read the git blame and history of the code modified, to identify any bugs in light of that historical context d. Agent #4: Read previous pull requests that touched these files, and check for any comments on those pull requests that may also apply to the current changes. e. Agent #5: Read code comments in the modified files, and make sure the changes comply with any guidance in the comments.
  5. For each issue found in #4, launch a parallel Haiku agent that takes the diff, issue description, and list of CLAUDE.md files (from step 2), and returns a score to indicate the agent's level of confidence for whether the issue is real or false positive. To do that, the agent should score each issue on a scale from 0-100, indicating its level of confidence. For issues that were flagged due to CLAUDE.md instructions, the agent should double check that the CLAUDE.md actually calls out that issue specifically. The scale is (give this rubric to the agent verbatim): a. 0: Not confident at all. This is a false positive that doesn't stand up to light scrutiny, or is a pre-existing issue. b. 25: Somewhat confident. This might be a real issue, but may also be a false positive. The agent wasn't able to verify that it's a real issue. If the issue is stylistic, it is one that was not explicitly called out in the relevant CLAUDE.md. c. 50: Moderately confident. The agent was able to verify this is a real issue, but it might be a nitpick or not happen very often in practice. Relative to the rest of the changes, it's not very important. d. 75: Highly confident. The agent double checked the issue, and verified that it is very likely it is a real issue that will be hit in practice. The existing approach is insufficient. The issue is very important and will directly impact the code's functionality, or it is an issue that is directly mentioned in the relevant CLAUDE.md. e. 100: Absolutely certain. The agent double checked the issue, and confirmed that it is definitely a real issue, that will happen frequently in practice. The evidence directly confirms this.
  6. Filter out any issues with a score less than 80.
  7. Write the review to claude-review.md. When writing your review, keep in mind to: a. Keep your output brief b. Avoid emojis c. Reference relevant files and line numbers
  8. Briefly summarize claude-review.md as direct output to the user
Examples of false positives, for steps 4 and 5:
  • Pre-existing issues
  • Something that looks like a bug but is not actually a bug
  • Pedantic nitpicks that a senior engineer wouldn't call out
  • Issues that a linter, typechecker, or compiler would catch (eg. missing or incorrect imports, type errors, broken tests, formatting issues, pedantic style issues like newlines). No need to run these build steps yourself -- it is safe to assume that they will be run separately as part of CI.
  • General code quality issues (eg. lack of test coverage, general security issues, poor documentation), unless explicitly required in CLAUDE.md
  • Issues that are called out in CLAUDE.md, but explicitly silenced in the code (eg. due to a lint ignore comment)
  • Changes in functionality that are likely intentional or are directly related to the broader change
  • Real issues, but on lines that were not modified in the current branch
Notes:
  • Do not check build signal or attempt to build or typecheck the app. These will run separately, and are not relevant to your code review.
  • Use git commands to analyze local changes (not
    gh
    commands for remote PRs)
  • Make a todo list first
  • You must cite each bug with file path and line number (eg. if referring to a CLAUDE.md, you must reference it)
  • For your final output, follow the following format precisely (assuming for this example that you found 3 issues):

对当前分支相对于main分支的本地变更执行代码审查。
请严格按照以下步骤操作:
  1. 使用Haiku Agent检查当前Git状态:
    • 执行
      git branch --show-current
      获取当前分支名称
    • 执行
      git log main..HEAD --oneline
      查看此分支上的提交记录
    • 执行
      git diff main...HEAD --stat
      查看变更的文件
    • 如果当前分支就是main分支,或者相对于main分支没有任何提交/变更,则停止后续操作。
  2. 使用另一个Haiku Agent从代码库中获取所有相关CLAUDE.md文件的路径列表(无需获取文件内容):包括根目录下的CLAUDE.md文件(如果存在),以及当前分支中被修改文件所在目录下的所有CLAUDE.md文件
  3. 使用Haiku Agent分析分支变更:
    • 执行
      git log main..HEAD --format="%s%n%b"
      获取提交信息
    • 执行
      git diff main...HEAD
      获取完整的差异内容
    • 返回变更内容的摘要
  4. 随后,启动5个并行的Sonnet Agent对变更内容进行独立代码审查。这些Agent需完成以下操作,然后返回问题列表及每个问题被标记的原因(例如:CLAUDE.md合规性、bug、Git历史上下文等): a. Agent #1:审核变更内容,确保其符合CLAUDE.md的要求。注意:CLAUDE.md是Claude编写代码时的指导文档,并非所有指令都适用于代码审查环节。 b. Agent #2:读取文件变更内容(通过
    git diff main...HEAD
    ),然后对明显的bug进行浅层扫描。避免读取变更之外的额外上下文,仅聚焦于变更本身。重点排查严重bug,忽略小问题和吹毛求疵的细节。排除可能的误报。 c. Agent #3:读取被修改代码的Git Blame信息和历史记录,结合历史上下文识别潜在bug d. Agent #4:查看过往涉及这些文件的Pull Request,检查其中是否有适用于当前变更的评论 e. Agent #5:读取被修改文件中的代码注释,确保变更内容符合注释中的指导要求
  5. 针对步骤4中发现的每个问题,启动一个并行的Haiku Agent,传入差异内容、问题描述以及步骤2中获取的CLAUDE.md文件列表,返回一个分数以表示该Agent对问题是否为真实问题或误报的置信度。Agent需为每个问题在0-100的范围内评分,具体评分标准如下(需将此标准原封不动告知Agent): a. 0:完全不置信。这是经不起初步检查的误报,或是预先存在的问题。 b. 25:略有置信。这可能是真实问题,但也可能是误报。Agent无法验证其是否为真实问题。如果是风格类问题,则是相关CLAUDE.md中未明确提及的问题。 c. 50:中等置信。Agent已验证这是真实问题,但可能是无关紧要的细节问题,或在实际场景中很少出现。相对于其他变更,此问题并不重要。 d. 75:高度置信。Agent已再次检查该问题,验证其极有可能是实际场景中会出现的真实问题。现有解决方案存在不足。此问题非常重要,会直接影响代码功能,或是相关CLAUDE.md中明确提及的问题。 e. 100:绝对确定。Agent已再次检查该问题,确认其肯定是真实问题,且在实际场景中会频繁出现。有直接证据可以证实。
  6. 过滤掉所有评分低于80的问题。
  7. 将审查结果写入claude-review.md文件。撰写审查结果时,请注意: a. 内容简洁 b. 避免使用表情符号 c. 引用相关文件和行号
  8. 将claude-review.md的内容进行简要总结,直接输出给用户
步骤4和5中的误报示例:
  • 预先存在的问题
  • 看似bug但实际并非bug的情况
  • 资深工程师不会提出的吹毛求疵的细节问题
  • 可由Linter、类型检查器或编译器发现的问题(例如:缺失或错误的导入、类型错误、测试失败、格式问题、换行符这类过于苛刻的风格问题)。无需自行执行这些构建步骤——可以认为这些步骤会作为CI流程的一部分单独运行。
  • 一般性代码质量问题(例如:测试覆盖率不足、一般性安全问题、文档不完善),除非CLAUDE.md中明确要求检查
  • CLAUDE.md中提及但代码中明确忽略的问题(例如:通过lint忽略注释)
  • 可能是有意为之或与整体变更直接相关的功能变更
  • 真实存在但位于当前分支未修改行上的问题
注意事项:
  • 不要检查构建信号,也不要尝试构建或对应用进行类型检查。这些操作会单独执行,与本次代码审查无关。
  • 使用Git命令分析本地变更(不要使用用于远程PR的
    gh
    命令)
  • 首先创建一个待办事项列表
  • 必须为每个bug标注文件路径和行号(例如:如果引用CLAUDE.md,必须标注其路径)
  • 最终输出请严格遵循以下格式(假设本次审查发现3个问题):

Code review for branch
<branch-name>

分支
<branch-name>
的代码审查结果

Reviewed X commits with changes to Y files.
Found 3 issues:
  1. <brief description of bug> (CLAUDE.md says "<...>")
    • File:
      path/to/file.ts:L10-L15
  2. <brief description of bug> (some/other/CLAUDE.md says "<...>")
    • File:
      path/to/other-file.ts:L25-L30
  3. <brief description of bug> (bug due to <reasoning>)
    • File:
      path/to/another-file.ts:L5-L8

  • Or, if you found no issues:

已审查X次提交,涉及Y个文件的变更。
发现3个问题:
  1. <bug简要描述>(CLAUDE.md中提到:"<...>")
    • 文件:
      path/to/file.ts:L10-L15
  2. <bug简要描述>(some/other/CLAUDE.md中提到:"<...>")
    • 文件:
      path/to/other-file.ts:L25-L30
  3. <bug简要描述>(bug原因:<推理过程>)
    • 文件:
      path/to/another-file.ts:L5-L8

  • 如果未发现任何问题:

Code review for branch
<branch-name>

分支
<branch-name>
的代码审查结果

Reviewed X commits with changes to Y files.
No issues found. Checked for bugs and CLAUDE.md compliance.

已审查X次提交,涉及Y个文件的变更。
未发现任何问题。已检查bug和CLAUDE.md合规性。