# Code review prompt

Ask Claude to review a diff for supported issues, ordered by severity, with a location, impact and suggested fix for each finding.

Paste into: **a new Claude conversation**

## Prompt template

How the builder on the page fills in this template, so you can do the same:

- `{{key}}` becomes the text entered for that field, exactly as typed. Empty text, or text that is only whitespace (spaces, tabs or line breaks), counts as empty: a required field then becomes `[fill in: <label>]` with its label, and an optional field becomes nothing.
- For a choice field, `{{key}}` becomes the text of the chosen option, or of the default when none is chosen.
- Text between `{{#key}}` and `{{/key}}` stays only when that field is not empty; a choice field always counts as filled. The markers themselves are removed, and a marker that stands alone on its line takes its line break with it.
- Each value is inserted once, as it is: `{{…}}` inside a value stays as typed.

```text
<diff>
{{diff}}
</diff>
{{#intent}}

What this change is supposed to do:
{{intent}}
{{/intent}}
{{#language}}

Language or framework: {{language}}
{{/language}}

Review the code change above the way a careful senior engineer would.

Review focus: {{focus}}

For each problem you find, give:
- Location: the file and line from the diff.
- Problem: what is wrong, in one or two sentences.
- Impact: what could go wrong for users or maintainers.
- Fix: a concrete suggestion, with a short code snippet when it helps.

Order the findings from most to least severe, and label each one "Must fix" or "Worth considering".

Only report problems you can support from the code shown. If judging something needs code that is not in the diff, such as a caller or a config file, say what you would need to see instead of assuming. If you find no real problems, say so plainly rather than listing minor style preferences.
```

## Fields

- `{{diff}}` (required): Diff or code change. A unified diff works best because it shows file names and what changed. Remove secrets such as keys or passwords before pasting.
- `{{intent}}`: What the change is supposed to do. Optional, but it lets Claude check the change against its purpose instead of only its style.
- `{{language}}`: Language or framework.
- `{{focus}}`: Review focus. Choose one:
  - Everything that matters (default)
  - Correctness and edge cases
  - Security
  - Readability and maintainability
  - Performance

This site doesn't run Claude or show model output. Results depend on your input and the model you use.

## When to use this template

- You have a diff or a small set of changed files and want a second look before you merge or ask a colleague to review.
- You want the review aimed at one concern, such as security or edge cases, rather than a general list of comments.
- You are reviewing someone else's change and want help spotting problems you can then verify yourself.

## When not to use it

- The change spans many files that depend on code you cannot paste. Claude will only see the diff, so it cannot judge effects outside it.
- You need a style or lint check. A formatter or linter does that faster and more reliably than a prompt.
- The code contains secrets or material you are not allowed to share. Remove or replace them before pasting anything.

## Why this structure

- The diff comes first, inside `<diff>` tags, which helps Claude tell the code apart from your instructions and from the optional context lines below it.
- The optional intent block appears only when you fill it in. When present, it lets Claude check whether the change does what it is meant to do, which a diff alone cannot show.
- Each finding is requested in four parts (location, problem, impact and fix), so you can check the evidence and judge the suggested change.
- Findings are ordered by severity and labelled "Must fix" or "Worth considering", which makes important problems easier to spot among small suggestions.
- The last paragraph asks Claude to report only what the code supports and to say what context is missing. It also gives Claude explicit permission to report that there are no real problems, which discourages padding the review.

## Example input (fictional)

Diff or code change:

```
--- a/billing/invoice.py
+++ b/billing/invoice.py
@@ -10,7 +10,7 @@ def total(lines):
-    return sum(l.price * l.qty for l in lines)
+    return sum(l.price for l in lines) * len(lines)
```

What the change is supposed to do:

```
Simplify the invoice total calculation.
```

Language or framework:

```
Python
```

Review focus:

```
Correctness and edge cases
```

## Follow-ups to send Claude

- For the first "Must fix" item, write the corrected code and a unit test that would have caught the problem.
- Which of your findings depend on assumptions about code that is not in the diff? List the assumption for each.
- Explain the most severe issue as a short comment I can paste into the pull request.

## Common mistakes

- Pasting a whole file when only a few lines changed. The review then spreads across code you did not touch. Paste the diff, or mark which lines changed.
- Leaving out what the change is for. Without intent, Claude can only judge how the code is written, not whether it does the right thing.
- Accepting a finding without checking it. Treat each item as a lead to verify against the real codebase, especially anything about code outside the diff.

## Related templates

- [Debug an error](https://awesomeclaudeprompts.com/prompts/debug-error/): Turn an error message and the code around it into a ranked list of likely causes, a check for each, and a fix you can try.
- [Write unit tests](https://awesomeclaudeprompts.com/prompts/write-unit-tests/): Get unit tests for a function or module in your framework, covering normal cases, edge cases and errors, with each test explained.

## Sources

- [Prompting best practices: Structure prompts with XML tags](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/claude-prompting-best-practices#structure-prompts-with-xml-tags) (Anthropic documentation)
- [Prompting best practices: Be clear and direct](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/claude-prompting-best-practices#be-clear-and-direct) (Anthropic documentation)
- [Reduce hallucinations](https://platform.claude.com/docs/en/test-and-evaluate/strengthen-guardrails/reduce-hallucinations) (Anthropic documentation)

---

Awesome Claude Prompts is an independent project. It is not affiliated with, endorsed by, or sponsored by Anthropic. Claude is a trademark of Anthropic, PBC.
