What Is the Best Claude Prompt for Code Review?
Use this prompt: "You are a senior software engineer reviewing code. Analyze the following code for: (1) bugs and logic errors, (2) security vulnerabilities, (3) performance issues, (4) readability improvements. Be specific -- reference line numbers and suggest exact fixes."
The Full Prompt Template
You are a senior software engineer performing a thorough code review.
Analyze the following code for:
1. **Bugs and Logic Errors**
- Off-by-one errors
- Null/undefined handling
- Race conditions
- Unhandled edge cases
- Incorrect type assumptions
2. **Security Vulnerabilities**
- Injection risks (SQL, XSS, command)
- Authentication/authorization flaws
- Sensitive data exposure
- Insecure dependencies
3. **Performance Issues**
- Unnecessary loops or re-renders
- Missing memoization
- N+1 query patterns
- Memory leaks
4. **Readability Improvements**
- Unclear variable names
- Missing error handling
- Functions that do too much
- Missing or misleading comments
For each issue:
- Reference the specific line number(s)
- Explain WHY it is a problem
- Provide the EXACT fix (show corrected code)
- Rate severity: Critical / Warning / Suggestion
Code to review:
```
[PASTE YOUR CODE HERE]
```
Why This Prompt Works
- Role definition: "Senior software engineer" sets the expertise level and review depth.
- Structured categories: Four specific areas prevent Claude from giving vague feedback.
- Actionable output: Requiring line numbers and exact fixes means you get copy-paste solutions, not hand-wavy suggestions.
- Severity rating: Helps you prioritize which issues to fix first.
Tips for Better Results
- Include the full function with imports and surrounding context, not just the problematic snippet.
- Add the language and framework to the prompt: "This is a Next.js API route using Prisma ORM."
- If reviewing a PR, paste the diff and ask Claude to focus on the changed lines.
- For security-critical code, add: "Assume all user input is untrusted."
Which Claude Model to Use
| Model | Best For | Cost |
|---|---|---|
| Haiku | Quick syntax checks, simple reviews | $0.25/1M tokens |
| Sonnet 3.5 | General code review (best value) | $3/1M tokens |
| Opus | Security audits, architectural review | $15/1M tokens |
Browse more tested prompts in the ClaudHQ prompt library.