在專案根目錄建立一個名為 .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