Review a git diff, commit or snippet for bugs, security, performance and maintainability, with file:line evidence and a concrete fix per finding.
---
name: code-review
description: Reviews a code change or file for correctness, security, performance and maintainability, and reports findings in a severity table with file:line evidence and a concrete fix for each. Works from git diff output, a pasted snippet, or named files. Use when asked to review code, check a diff or commit before merging, look for bugs or security issues, or give feedback on a change.
compatibility: Works on pasted code alone; reviewing a working tree or commit range needs git and read access to the repository.
metadata:
version: "2.0.0"
---
# Code Review
A focused review that finds real problems in the code in front of it and explains how to fix them. Every finding must point to a line the reviewer actually read. An empty result ("no issues found in the areas checked") is acceptable; padding the table is not.
## Inputs to collect
- **Scope** (pick one):
- uncommitted changes: `git diff` and `git diff --cached`
- last commit: `git show HEAD`
- branch against its base: `git diff main...HEAD` (three dots = changes since the merge base)
- specific files the user names, or a pasted snippet
- Language/framework, and any project rules (lint config, `CONTRIBUTING.md`, style guide).
- Focus areas if the user has them (for example "security only").
## Workflow
1. **Collect the change.** Run the git command for the scope, plus `git diff --stat` for an overview. For each changed hunk, read enough surrounding code (the whole function, its callers if behavior changed) to judge it. Skip generated files and lockfiles, and say so.
2. **Check, in this order:**
1. Correctness: wrong logic, off-by-one, null/undefined paths, unhandled errors, race conditions, broken edge cases (empty, zero, negative, very large, Unicode).
2. Security: injection (SQL, shell, template), XSS from unescaped output, missing authorization checks, secrets in code or logs, unsafe deserialization, unvalidated redirects or file paths.
3. Performance: queries in loops (N+1), unbounded memory or result sets, repeated expensive work.
4. Maintainability: unclear names, duplication introduced by the change, magic numbers, missing or weakened tests for changed behavior.
3. **Verify before reporting.** Where cheap, confirm a suspected bug: run the existing tests, a tiny script, or trace a concrete input through the code. Mark anything you could not confirm as "possible".
4. **Write the report** (format below), most severe first. Suggest fixes; apply them only if the user asks.
## Output format
| Severity | Location | Issue | Suggested fix |
|----------|----------|-------|---------------|
| 🔴 Critical | app/users.py:4 | SQL built with an f-string from `email`; input `' OR '1'='1` returns every user | Use a parameterized query: `conn.execute("... WHERE email = ?", (email,))` |
| 🟡 Warning | app/users.py:7 | `page_size(n)` accepts negative or huge `n` | Validate the range and add a test |
| 🔵 Info | app/users.py:8 | Magic number 25 | Name it `DEFAULT_PAGE_SIZE` |
Severity guide: **Critical** = exploitable or data-corrupting; **Warning** = likely bug or risky pattern; **Info** = readability or style.
Close with: scope reviewed (files, commit range), what was verified by running something, what was skipped, and an overall recommendation (ready / needs changes).
## Limitations
- A review is not a security audit or a test run. Do not claim the code is "secure" or "bug-free".
- Do not report issues in lines outside the reviewed scope as if the change introduced them; label pre-existing issues separately.
- Never invent line numbers, CVE IDs or benchmark figures.
## Example
Input: `git diff` where `app/users.py` replaced a parameterized query with `query = f"SELECT id, email FROM users WHERE email = '{email}'"`.
Result: one Critical finding at `app/users.py:4` with the injection input that returns all rows and the parameterized fix, plus the Warning and Info rows above, and "needs changes".
Refactor code in small, test-protected steps: pin current behavior first, change one thing at a time, and rerun tests after every step.
Debug systematically: reproduce the bug, rank hypotheses by evidence, test them with logging, a debugger or git bisect, then fix the root cause with a regression test.
Set up transactional email
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
Before opening a PR, a developer wants their uncommitted change to a user lookup function reviewed.
Review my uncommitted changes (git diff). I changed app/users.py so find_user builds the query as f"SELECT id, email FROM users WHERE email = '{email}'" and added page_size(n) returning n * 25.A severity table whose first row is Critical at app/users.py:4: SQL injection via the f-string, demonstrated with the input ' OR '1'='1 returning every row, fixed by a parameterized query. Lower rows: Warning at app/users.py:7 (no range check on n) and Info at app/users.py:8 (magic number 25). It closes with the scope reviewed, what was actually run, and 'needs changes'. It does not call the rest of the code secure.
AI Agent Skills are reusable workflow packages that extend your AI coding assistant with multi-step capabilities. Install code-review by following these steps.
SKILL.md inside, in the location documented by your client. Do not assume every AI application reads the same directory.Requires an Agent Skills-compatible client; supported locations and activation vary by version. Read the SKILL.md setup guide. MCP connects tools and data and does not, by itself, install a skill.
Refactor code in small, test-protected steps: pin current behavior first, change one thing at a time, and rerun tests after every step.
Debug systematically: reproduce the bug, rank hypotheses by evidence, test them with logging, a debugger or git bisect, then fix the root cause with a regression test.
Set up transactional email