在项目根目录创建一个名为 .claude-review-prompt.md 的文件。它作为 AI 审查的指令集:
# Code Review InstructionsReview all changes on the current branch compared to the `main` branch.## What to Check### Critical Issues (must fix before merge)- **Logic errors**: Code that doesn't do what it claims- **Security vulnerabilities**: SQL injection, XSS, auth bypasses, credential exposure- **Data loss risks**: Missing transactions, incorrect cascade deletes, race conditions- **Breaking changes**: API contract violations, backwards-incompatible modifications### Warnings (should fix, but not blocking)- **Missing error handling**: Uncaught exceptions, unhandled promise rejections- **Performance concerns**: N+1 queries, unnecessary re-renders, missing memoization- **Missing validation**: User input not validated before processing- **Test coverage gaps**: New code paths without corresponding tests### Suggestions (nice to have)- **Readability improvements**: Unclear variable names, complex logic that could be simplified- **Documentation gaps**: Public APIs without JSDoc/TSDoc comments- **Potential refactoring**: Duplicated logic, overly long functions## Output FormatFor each finding, provide:1. **Severity**: CRITICAL / WARNING / SUGGESTION2. **File**: Exact file path and line numbers3. **Description**: What the issue is, in one sentence4. **Explanation**: Why it matters, with context5. **Fix**: Concrete code suggestion to resolve the issueAt the end, provide:- Summary: X critical, Y warnings, Z suggestions- Overall assessment: Is this branch ready for human review?## What NOT to Flag- Style preferences covered by our linter (ESLint/Prettier handle this)- Import ordering (automated)- Whitespace or formatting (automated)- Type annotations that TypeScript can infer
🔴 CRITICAL — src/api/routes/users.ts:47-52Description: SQL query constructed with string concatenation, vulnerable to injection.Explanation: The search query parameter is interpolated directly into the SQLstring without parameterization. An attacker could craft a search input thatmodifies the query logic, potentially extracting or modifying data.Fix: Use parameterized query: // Before (vulnerable) const results = db.query(`SELECT * FROM users WHERE name LIKE '%${search}%'`) // After (safe) const results = db.query('SELECT * FROM users WHERE name LIKE ?', [`%${search}%`])
对于每个发现,你可以在手机上选择三种操作:
应用修复: 提示 Claude Code 实施建议的修复:
Apply the fix for the SQL injection issue in users.ts:47.
跳过: 如果你不同意该发现或认为是误报,记录下来稍后处理,继续下一个。
讨论: 如果你不确定,向 Claude Code 请求更多上下文:
Explain the SQL injection risk in more detail. Is this exploitable givenour authentication middleware that runs before this route?
Apply fixes for all CRITICAL and WARNING findings from the review.For each fix, run the relevant tests to verify the fix doesn't break anything.Report which fixes were applied and which tests passed.
Claude Code 会系统地处理所有发现,逐一应用修复并运行测试。这又是一个你可以放下手机等待通知的任务。
Create a pull request description that includes:1. What this branch does (based on the commit history)2. Summary of the AI review findings and how they were addressed3. Any remaining suggestions that were intentionally deferred4. Test results