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

Tips for Better Results

  1. Include the full function with imports and surrounding context, not just the problematic snippet.
  2. Add the language and framework to the prompt: "This is a Next.js API route using Prisma ORM."
  3. If reviewing a PR, paste the diff and ask Claude to focus on the changed lines.
  4. 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.

Related Questions