Pre-Review
Find and fix issues before publishing your PR — not after.
Single-pass review using one capable model. No orchestration overhead, no agent swarm. Fast, cheap, thorough.
When to use
- - Reviewing code changes before publishing a PR
- Auditing existing code for bugs, security, or quality issues
- Finding and fixing issues in specific files or directories
When NOT to use
- - Running a coding agent to write new code → use INLINECODE0
- Checking GitHub CI status → use INLINECODE1
- Managing forks or rebasing branches → use INLINECODE2
Usage
CODEBLOCK0
Two modes:
| Mode | Trigger | Scope | Fix threshold |
|---|
| Diff | No args, on branch with changes | Changed files only | >= 70 |
| Audit |
Paths, patterns, or
--audit | Specified files or full codebase | >= 80 |
Instructions
Step 1: Detect Mode and Scope
No arguments provided:
git diff main...HEAD --name-only 2>/dev/null || git diff master...HEAD --name-only
- - If changes exist → Diff mode
- If no changes → inform user, stop
Paths/patterns provided or --audit:
- - Resolve to actual files (exclude node_modules, dist, build, vendor, .git, coverage)
- If > 50 files, ask user to narrow scope or confirm
- Audit mode
Step 2: Gather Context
Read project guidelines (quick scan, don't overthink):
CODEBLOCK2
Get the diff or file contents:
CODEBLOCK3
Step 3: Review (Single Pass)
Analyze all code in one pass. Cover these areas in priority order:
1. Correctness (highest priority)
- - Logic errors, edge cases, null/undefined handling
- Off-by-one, pagination boundaries, numeric precision
- Async/await mistakes, race conditions, resource leaks
- Data consistency, idempotency
2. Security
- - Injection vulnerabilities (SQL, XSS, command, path traversal)
- Auth/authz gaps, IDOR risks, exposed secrets
- Unvalidated input reaching sensitive operations
- Logging sensitive data, insecure defaults
3. Reliability
- - Error handling gaps, silent failures, swallowed exceptions
- Missing timeouts, retries without backoff
- Unbounded operations on user-controlled data
4. Performance
- - N+1 queries, unnecessary loops, memory bloat
- Missing pagination, inefficient algorithms
- Blocking operations in async context
5. Quality (lowest priority — skip if trivial)
- - Missing tests for new functionality
- Dead code, duplicated logic
- Stale comments, unclear naming
- Style issues only if they violate project guidelines
Step 4: Score and Classify
For each issue found, assign:
| Score | Meaning | Action |
|---|
| 90-100 | Critical bug or vulnerability | Must fix |
| 70-89 |
Real issue, will cause problems | Should fix |
| 50-69 | Code smell, needs human judgment | Report only |
| < 50 | Minor, likely false positive | Discard |
Discard thresholds:
- - Diff mode: discard below 50
- Audit mode: discard below 40
Classify each issue:
- -
blocker — security, data corruption, crash risk - INLINECODE6 — likely bug, perf regression, missing validation
- INLINECODE7 — edge case, maintainability, style
Step 5: Auto-Fix
Apply fixes directly for issues meeting the threshold:
- - Diff mode: fix issues scoring >= 70
- Audit mode: fix issues scoring >= 80
For each fix: read file → apply edit → verify surrounding code preserved.
Never auto-fix:
- - Issues requiring architectural changes
- Ambiguous fixes with multiple valid approaches
- Issues in test files (report only)
After fixing, if any files were modified:
CODEBLOCK4
Step 6: Report
Format:
CODEBLOCK5
If zero issues found: INLINECODE8
Guidelines
DO:
- - Fix issues directly, not just report them
- Match existing code patterns and style
- Be specific: file, line, concrete fix
- Prioritize impact over thoroughness
DON'T:
- - Fix pre-existing issues in diff mode — only what changed
- Bikeshed on style unless it violates project guidelines
- Report what a linter or type checker would catch (assume CI handles these)
- Make architectural changes or large refactors
- Spend tokens on obvious non-issues
False Positives to Avoid
- - Pre-existing code not touched by the current change (diff mode)
- Intentional patterns that look unusual but are correct
- Issues a type checker or linter would flag
- Style opinions not grounded in project guidelines
- General nitpicks a senior engineer would skip
Pre-Review
在发布PR之前发现并修复问题,而非之后。
使用一个高效模型进行单次审查。无需编排开销,无需代理集群。快速、经济、全面。
适用场景
- - 在发布PR前审查代码变更
- 审计现有代码中的错误、安全问题或质量缺陷
- 在特定文件或目录中查找并修复问题
不适用场景
- - 运行编码代理编写新代码 → 请使用 coding-agent
- 检查GitHub CI状态 → 请使用 github
- 管理分支复刻或变基操作 → 请使用 fork-manager
使用方法
/pr-review # 审查当前分支与main/master分支的差异
/pr-review src/api/ src/auth/ # 审计指定目录
/pr-review /*.ts # 审计匹配模式的文件
/pr-review --audit # 智能优先级审计整个代码库
两种模式:
| 模式 | 触发条件 | 范围 | 修复阈值 |
|---|
| 差异 | 无参数,在有变更的分支上 | 仅变更文件 | >= 70 |
| 审计 |
提供路径、模式或 --audit | 指定文件或完整代码库 | >= 80 |
操作说明
步骤1:检测模式与范围
未提供参数:
bash
git diff main...HEAD --name-only 2>/dev/null || git diff master...HEAD --name-only
- - 存在变更 → 差异模式
- 无变更 → 通知用户,停止操作
提供路径/模式或 --audit:
- - 解析为实际文件(排除node_modules、dist、build、vendor、.git、coverage)
- 如果超过50个文件,要求用户缩小范围或确认
- 审计模式
步骤2:收集上下文
快速扫描项目指南(不要过度思考):
bash
检查项目约定
cat CLAUDE.md .claude/settings.json CONTRIBUTING.md 2>/dev/null | head -100
cat .eslintrc
.prettierrc biome.json tsconfig.json 2>/dev/null | head -50
cat package.json 2>/dev/null | head -20 # 技术栈
获取差异或文件内容:
bash
差异模式
git diff main...HEAD # 或 master
审计模式
cat
# 读取目标文件
步骤3:审查(单次通过)
一次性分析所有代码。按优先级顺序覆盖以下领域:
1. 正确性(最高优先级)
- - 逻辑错误、边界情况、null/undefined处理
- 差一错误、分页边界、数值精度
- async/await错误、竞态条件、资源泄漏
- 数据一致性、幂等性
2. 安全性
- - 注入漏洞(SQL、XSS、命令、路径遍历)
- 认证/授权漏洞、IDOR风险、暴露的密钥
- 未经验证的输入到达敏感操作
- 记录敏感数据、不安全的默认配置
3. 可靠性
- - 错误处理缺失、静默失败、吞没异常
- 缺少超时、无退避的重试
- 对用户控制数据的无界操作
4. 性能
- - N+1查询、不必要的循环、内存膨胀
- 缺少分页、低效算法
- 异步上下文中的阻塞操作
5. 质量(最低优先级——琐碎问题可跳过)
- - 新功能缺少测试
- 死代码、重复逻辑
- 过时注释、命名不清
- 仅当违反项目指南时的风格问题
步骤4:评分与分类
为每个发现的问题分配:
| 分数 | 含义 | 操作 |
|---|
| 90-100 | 严重错误或漏洞 | 必须修复 |
| 70-89 |
真实问题,会导致故障 | 应该修复 |
| 50-69 | 代码异味,需要人工判断 | 仅报告 |
| < 50 | 轻微问题,可能是误报 | 丢弃 |
丢弃阈值:
对每个问题分类:
- - blocker — 安全、数据损坏、崩溃风险
- important — 可能的错误、性能回归、缺少验证
- minor — 边界情况、可维护性、风格
步骤5:自动修复
直接应用满足阈值的修复:
- - 差异模式: 修复评分 >= 70 的问题
- 审计模式: 修复评分 >= 80 的问题
每次修复:读取文件 → 应用编辑 → 验证周围代码未被破坏。
绝不自动修复:
- - 需要架构变更的问题
- 存在多种有效方法的模糊修复
- 测试文件中的问题(仅报告)
修复后,如有文件被修改:
bash
git diff --stat # 显示变更内容
步骤6:报告
格式:
Pre-Review完成
风险: 低 / 中 / 高
结论: ✅ 干净 | ⚠️ 发现问题 | 🔴 阻塞项
🔴 阻塞项(必须修复)
- 1. 文件:行号 — 描述
- 影响:会导致什么问题
- 修复:已应用 ✅ | 需手动修复(原因)
⚠️ 重要项(应该修复)
- 1. 文件:行号 — 描述(评分:XX)
- 修复:已应用 ✅ | 建议
💡 轻微项
- 1. 文件:行号 — 描述
需要添加的测试
修改的文件数:N
如果未发现任何问题:## Pre-Review完成 — ✅ 干净。未发现问题。
指南
应做:
- - 直接修复问题,而非仅报告
- 匹配现有代码模式和风格
- 具体明确:文件、行号、具体修复
- 优先考虑影响而非全面性
不应做:
- - 在差异模式下修复预先存在的问题——仅修复变更内容
- 对风格吹毛求疵,除非违反项目指南
- 报告linter或类型检查器会捕获的问题(假设CI处理这些)
- 进行架构变更或大规模重构
- 在明显非问题上消耗令牌
需避免的误报
- - 当前变更未触及的预先存在代码(差异模式)
- 看似异常但实际正确的有意模式
- 类型检查器或linter会标记的问题
- 未基于项目指南的风格意见
- 高级工程师会忽略的一般性吹毛求疵