SuperAPI AI 工具集

claude-review

编程与开发

查看项目

更新于 10-16 11:01

技能介绍

用途

claude-review 用于搭建一个多轮代码评审循环:由 Codex 编写代码,Claude Code 负责评审,Codex 再根据反馈修改,如此重复。它的定位是在编码智能体内部补充一轮独立评审,而不是独立运行的评审工具。该技能设计为在 Codex 中使用,也可在任何能够执行 shell 命令的智能体中工作。

前置条件

  • 需要安装并完成认证的 claude CLI(Claude Code)。
  • 当前目录必须是一个代码项目。
  • 如果未安装 claude,应提示用户安装 Claude Code。

触发方式

当用户提到 “claude review”、“let claude review”、“claude 看看”,或希望让 Claude 评审代码时激活。

使用方式

命令形式:

/claude-review [scope] [focus]

scope(可选)表示评审范围:

  • uncommitted(默认)——评审工作区改动
  • commit——评审最后一次提交
  • branch——评审当前分支与 main 的差异

focus(可选)表示自定义评审指令。

示例:

  • /claude-review
  • /claude-review branch focus on error handling
  • /claude-review commit check for security issues

工作流

第一步:初始评审

根据 scope 构建评审命令:

未提交改动(默认):

git diff --no-color HEAD | claude -p "Review this diff. Focus on: bugs, security, error handling, edge cases. Be specific about file and line. Output findings as a numbered list. ${FOCUS}"

最后一次提交:

git show --no-color HEAD | claude -p "Review this commit. ${FOCUS}"

当前分支与 main 对比:

git diff --no-color main...HEAD | claude -p "Review these branch changes. ${FOCUS}"

如果没有 diff,检查未跟踪文件:

git diff --no-color && git diff --no-color --cached && git ls-files --others --exclude-standard

随后解析 Claude 的输出——它会返回一份带问题的 markdown 评审。

第二步:评估发现的问题

阅读 Claude 的评审输出并进行分类:

  • Critical(关键)——缺陷、安全问题、数据丢失 → 必须修复
  • Important(重要)——性能、错误处理 → 应当修复
  • Suggestions(建议)——风格、命名 → 有则更好

如果没有发现明显问题,报告 “Claude approved” 并停止。

第三步:修复问题

对 Critical 和 Important 的问题应用修复。除非用户要求,跳过仅涉及风格的建议。

第四步:再次评审

带上上一轮的上下文重新执行评审:

git diff --no-color HEAD | claude -p "Previous review found these issues: [summary]. Verify they are fixed and check for new issues. ${FOCUS}"

第五步:循环控制

  • 最大轮数:默认 3 轮
  • 退出条件:Claude 报告无重大问题;达到最大轮数;用户中断。

第六步:总结

呈现以下内容:

  • 总轮数
  • 每轮发现/修复的问题
  • 剩余的建议
  • 最终结论

适用场景

适合在编码智能体(如 Codex)中自动引入一轮独立的代码评审,尤其是需要针对工作区改动、最近提交或分支差异进行有重点(如错误处理、安全)的多轮审查时。

限制与注意事项

  • claude -p 以非交互方式(打印模式)运行,输出评审后即退出。
  • 每次调用是无状态的,需要通过提示词传入之前的上下文。
  • 评审看到的是当前工作区,因此 Codex 的所有编辑都可见。
  • 需要预先安装并认证 claude CLI。
  • 该技能可在 Codex 以及任何能运行 shell 命令的智能体中使用。