Principles
- Those who write don't review: The main Claude focuses on writing code and does not self-review boundary conditions
- Those who review don't write: Review subagents focus on finding problems and do not modify code
- Parallel multi-dimensional: Three subagents review simultaneously from different angles, improving coverage
- Loop until clean: If there are issues, fix them; after fixing, review again, until all subagents report no new issues
Trigger Timing
After completing feature development, bug fixes, or refactoring, run this workflow before git commit .
Process
Step 1: Confirm the scope of work
git diff --stat
git diff HEAD
List the changed files and confirm the review scope. Save the full output of git diff HEAD for later use (all three agents need it).
Step 2: Dispatch three review subagents in parallel
In the same message, use the Agent tool to simultaneously start the following three subagents (subagent_type=general) and let them run in parallel. Each agent is responsible for only one review dimension.
Agent 1 — Logic and boundary conditions
你是一位专注逻辑与边界条件的代码审查员。只输出问题列表,不评价整体质量。没有问题则输出:NO_ISSUES
【审查维度】
- 边界条件:空数组/空字符串、零值、极大/极小值、索引越界
- 逻辑漏洞:条件判断遗漏、逻辑短路错误、状态机缺失状态
- 控制流:提前返回遗漏、循环条件错误、递归终止条件缺失
【代码变更】
<git diff HEAD 完整输出>
【输出格式】
问题 #1:[逻辑/边界] [文件路径:行号]
描述:...
风险:...
修复建议:(思路即可,不写代码)
Agent 2 — Type safety and error handling
你是一位专注类型安全与错误处理的代码审查员。只输出问题列表,不评价整体质量。没有问题则输出:NO_ISSUES
【审查维度】
- 类型安全:nil/null 解引用、类型断言失败、接口不匹配、类型转换溢出
- 错误处理:忽略 error 返回值、错误信息丢失、panic 未恢复
- 空值安全:可选值未检查、指针解引用前未判空
【代码变更】
<git diff HEAD 完整输出>
【输出格式】
问题 #1:[类型/错误] [文件路径:行号]
描述:...
风险:...
修复建议:(思路即可,不写代码)
Agent 3 — Concurrency and resource safety
你是一位专注并发与资源安全的代码审查员。只输出问题列表,不评价整体质量。没有问题则输出:NO_ISSUES
【审查维度】
- 并发安全:数据竞争、死锁、未加锁的共享状态、goroutine/协程泄漏
- 资源管理:文件/连接未关闭、内存泄漏、defer 使用错误、事件监听器未清理
- 幂等性:重复调用是否安全、重试逻辑是否正确
【代码变更】
<git diff HEAD 完整输出>
【输出格式】
问题 #1:[并发/资源] [文件路径:行号]
描述:...
风险:...
修复建议:(思路即可,不写代码)
Step 3: Consolidate issues
Wait for all three agents to finish, merge the outputs, deduplicate, and sort by priority:
Priority: logic flaws > type safety > concurrency safety > boundary conditions > resource management
If all three agents output NO_ISSUES → skip to Step 6
Step 4: The main Claude fixes item by item
Fix one by one in priority order:
- Update progress after each fix:
已修复 #Nor跳过 #N(说明原因) - Do not over-fix: only change the issues pointed out by the subagents, and do not casually refactor unrelated code
Step 5: Dispatch review again
Repeat Steps 2-3 and check:
- Whether the fix correctly resolved the original issue
- Whether the fix introduced new issues
If there are new issues → return to Step 4
If all are NO_ISSUES → continue to Step 6
Step 6: Verification
# 根据项目类型选择合适的验证命令
# lint / typecheck
# build / compile
# test
After all pass, proceed to Step 7. If verification fails → fix and return to Step 2.
Step 7: Commit
git add <相关文件>
git commit -m "$(cat <<'EOF'
<commit message>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
EOF
)"
Output Format
Report at the end of the workflow:
## Claude Cross-Review 完成报告
**审查轮次**:N 轮
**发现问题**:N 个(逻辑 N + 类型 N + 并发 N)
**已修复**:N 个
**跳过**:N 个(含原因)
**验证结果**:全部通过 / 部分失败
已提交:<commit hash> <commit message>