code-reviewer-agent

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

代码审查

Code Review

使用上下文隔离的 subagent 执行深度代码审查。
Perform in-depth code reviews using context-isolated subagents.

触发时机

Trigger Conditions

  • 用户要求进行代码审查
  • 用户提到"code review"、"代码审查"、"审查代码"等关键词
  • 用户要求检查安全性、性能或代码质量
  • User requests a code review
  • User mentions keywords such as "code review", "代码审查", "审查代码"
  • User requests checks for security, performance, or code quality

步骤

Steps

第一步:整理用户需求

Step 1: Organize User Requirements

将用户的审查需求整理为简洁的指令,包括:
  • 审查目标(如"当前 git 暂存变更"、"src/auth/ 目录"、"PR #42")
  • 重点关注方向(安全/性能/质量,如用户未指定则不限定)
  • 其他用户补充的要求
如果用户未指定审查目标,整理为"审查当前项目的 git 暂存变更(git diff --cached)"。
Organize the user's review requirements into concise instructions, including:
  • Review target (e.g., "current git staged changes", "src/auth/ directory", "PR #42")
  • Focus areas (security/performance/quality; no restriction if not specified by the user)
  • Additional requirements provided by the user
If the user does not specify a review target, default to "Review the git staged changes of the current project (git diff --cached)".

第二步:启动审查 subagent

Step 2: Launch Review Subagent

读取本目录下的
code-reviewer.md
,将其完整内容与第一步整理的需求拼接,作为 prompt 传给 Agent 工具 spawn subagent。
  • description
    : "深度代码审查"
  • prompt
    :
    code-reviewer.md
    完整内容 + "\n\n## 审查任务\n" + 用户需求指令
  • model
    : 读取
    code-reviewer.md
    frontmatter 中的
    model
    字段决定(如未指定则默认 sonnet)
关键原则
  • 不要在主 agent 中搜集代码内容,只传递审查目标的描述
  • subagent 自己拥有 Bash、Read 等工具,会自行读取代码和 diff
  • 必须将
    code-reviewer.md
    的全部内容传递给 subagent,不可截断或摘要
Read the
code-reviewer.md
file in the current directory, concatenate its full content with the requirements organized in Step 1, and pass it as a prompt to the Agent tool to spawn a subagent.
  • description
    : "In-depth Code Review"
  • prompt
    : Full content of
    code-reviewer.md
    + "\n\n## Review Task\n" + User requirement instructions
  • model
    : Determined by the
    model
    field in the frontmatter of
    code-reviewer.md
    (default to sonnet if not specified)
Key Principles:
  • Do not collect code content in the main agent, only pass the description of the review target
  • The subagent has its own tools like Bash and Read, and will read code and diffs on its own
  • Must pass the entire content of
    code-reviewer.md
    to the subagent; do not truncate or summarize

第三步:输出审查结果

Step 3: Output Review Results

将 subagent 返回的审查结果直接输出给用户,不做摘要或缩写。
Directly output the review results returned by the subagent to the user without summarization or abbreviation.