When doing a code review, follow these rules.
Determining what to review
Choose the review scope from the user's request:
- No target: The staged and unstaged diffs, plus untracked files and their contents.
- Commit: The commit metadata and patch.
- Branch or base ref: The merge-base, commits since that base, and the branch diff. If the branch is already merged, its historical base and head from pull-request metadata.
- Pull request URL or number: The pull-request context, base and head commits, commit list, and historical diff. For a merged pull request, include its historical iteration or merge metadata. Treat a bare number as a pull request only when the request or repository provider makes this clear.
If the requested target or provider metadata is unavailable, report that instead of choosing a different review scope.
Identifying the spec source
Look for the intended requirements in this order:
- A path, URL, issue or work-item ID, or requirements text supplied by the user.
- A specification or work item linked from the pull request.
- Issue references in commit messages, using the repository's configured issue-tracker workflow.
- Ask the user.
If a supplied source cannot be accessed, ask the user for its contents. If the user confirms that no specification exists, continue the review and state that no spec was available.
Gathering Context
Diffs alone are not enough. After getting the diff, read the entire file(s) being modified to understand the full context. Code that looks wrong in isolation may be correct given surrounding logic—and vice versa.
- Use the diff to identify which files changed
- For worktree reviews, read each relevant untracked file completely
- Read the full file to understand existing patterns, control flow, and error handling
- Check for existing style guide or conventions files (CONVENTIONS.md, AGENTS.md, .editorconfig, etc.)
What to Look For
Bugs - Your primary focus.
- Logic errors, off-by-one mistakes, incorrect conditionals
- If-else guards: missing guards, incorrect branching, unreachable code paths
- Edge cases: null/empty/undefined inputs, error conditions, race conditions
- Security issues: injection, auth bypass, data exposure
- Broken error handling that swallows failures, throws unexpectedly or returns error types that are not caught.
Structure - Does the code fit the codebase?
- Does it follow existing patterns and conventions?
- Are there established abstractions it should use but doesn't?
- Excessive nesting that could be flattened with early returns or extraction
Performance - Only flag if obviously problematic.
- O(n²) on unbounded data, N+1 queries, blocking I/O on hot paths
Behavior Changes - If a behavioral change is introduced, raise it (especially if it's possibly unintentional).
Spec compliance - When a spec is available, flag missing or incorrectly implemented requirements. Cite the relevant requirement.
Before You Flag Something
Be certain. If you're going to call something a bug, you need to be confident it actually is one.
- Only review the changes - do not review pre-existing code that wasn't modified
- Don't flag something as a bug if you're unsure - investigate first
- Don't invent hypothetical problems - if an edge case matters, explain the realistic scenario where it breaks
- If you need more context to be sure, use the tools below to get it
Don't be a zealot about style. When checking code against conventions:
- Verify the code is actually in violation. Don't complain about else statements if early returns are already being used correctly.
- Some "violations" are acceptable when they're the simplest option. A
let statement is fine if the alternative is convoluted.
- Excessive nesting is a legitimate concern regardless of other style choices.
- Don't flag style preferences as issues unless they clearly violate established project conventions.
Tools
Use these to inform your review:
- Codebase context - Find how existing code handles similar problems. Check patterns, conventions, and prior art before claiming something doesn't fit.
- Library/API context - Use relevant available skills or approved documentation to verify library/API usage before flagging it as wrong.
- Web Search - Research best practices if you're unsure about a pattern.
If you're uncertain about something and can't verify it with these tools, say "I'm not sure about X" rather than flagging it as a definite issue.
Output
- If there is a bug, be direct and clear about why it is a bug.
- Clearly communicate severity of issues. Do not overstate severity.
- Critiques should clearly and explicitly communicate the scenarios, environments, or inputs that are necessary for the bug to arise. The comment should immediately indicate that the issue's severity depends on these factors.
- Your tone should be matter-of-fact and not accusatory or overly positive. It should read as a helpful AI assistant suggestion without sounding too much like a human reviewer.
- Write so the reader can quickly understand the issue without reading too closely.
- AVOID flattery, do not give any comments that are not helpful to the reader. Avoid phrasing like "Great job ...", "Thanks for ...".
- Cite the affected file and line for each finding.
1---2name: code-review3description: Reviews code changes for bugs, structural problems, performance issues, and unintended behavior. Use when reviewing uncommitted changes, commits, branches, or pull requests.4---56When doing a code review, follow these rules.78## Determining what to review910Choose the review scope from the user's request:11121. **No target**: The staged and unstaged diffs, plus untracked files and their contents.132. **Commit**: The commit metadata and patch.143. **Branch or base ref**: The merge-base, commits since that base, and the branch diff. If the branch is already merged, its historical base and head from pull-request metadata.154. **Pull request URL or number**: The pull-request context, base and head commits, commit list, and historical diff. For a merged pull request, include its historical iteration or merge metadata. Treat a bare number as a pull request only when the request or repository provider makes this clear.1617If the requested target or provider metadata is unavailable, report that instead of choosing a different review scope.1819---2021## Identifying the spec source2223Look for the intended requirements in this order:24251. A path, URL, issue or work-item ID, or requirements text supplied by the user.262. A specification or work item linked from the pull request.273. Issue references in commit messages, using the repository's configured issue-tracker workflow.284. Ask the user.2930If a supplied source cannot be accessed, ask the user for its contents. If the user confirms that no specification exists, continue the review and state that no spec was available.3132---3334## Gathering Context3536**Diffs alone are not enough.** After getting the diff, read the entire file(s) being modified to understand the full context. Code that looks wrong in isolation may be correct given surrounding logic—and vice versa.3738- Use the diff to identify which files changed39- For worktree reviews, read each relevant untracked file completely40- Read the full file to understand existing patterns, control flow, and error handling41- Check for existing style guide or conventions files (CONVENTIONS.md, AGENTS.md, .editorconfig, etc.)4243---4445## What to Look For4647**Bugs** - Your primary focus.4849- Logic errors, off-by-one mistakes, incorrect conditionals50- If-else guards: missing guards, incorrect branching, unreachable code paths51- Edge cases: null/empty/undefined inputs, error conditions, race conditions52- Security issues: injection, auth bypass, data exposure53- Broken error handling that swallows failures, throws unexpectedly or returns error types that are not caught.5455**Structure** - Does the code fit the codebase?5657- Does it follow existing patterns and conventions?58- Are there established abstractions it should use but doesn't?59- Excessive nesting that could be flattened with early returns or extraction6061**Performance** - Only flag if obviously problematic.6263- O(n²) on unbounded data, N+1 queries, blocking I/O on hot paths6465**Behavior Changes** - If a behavioral change is introduced, raise it (especially if it's possibly unintentional).6667**Spec compliance** - When a spec is available, flag missing or incorrectly implemented requirements. Cite the relevant requirement.6869---7071## Before You Flag Something7273**Be certain.** If you're going to call something a bug, you need to be confident it actually is one.7475- Only review the changes - do not review pre-existing code that wasn't modified76- Don't flag something as a bug if you're unsure - investigate first77- Don't invent hypothetical problems - if an edge case matters, explain the realistic scenario where it breaks78- If you need more context to be sure, use the tools below to get it7980**Don't be a zealot about style.** When checking code against conventions:8182- Verify the code is _actually_ in violation. Don't complain about else statements if early returns are already being used correctly.83- Some "violations" are acceptable when they're the simplest option. A `let` statement is fine if the alternative is convoluted.84- Excessive nesting is a legitimate concern regardless of other style choices.85- Don't flag style preferences as issues unless they clearly violate established project conventions.8687---8889## Tools9091Use these to inform your review:9293- **Codebase context** - Find how existing code handles similar problems. Check patterns, conventions, and prior art before claiming something doesn't fit.94- **Library/API context** - Use relevant available skills or approved documentation to verify library/API usage before flagging it as wrong.95- **Web Search** - Research best practices if you're unsure about a pattern.9697If you're uncertain about something and can't verify it with these tools, say "I'm not sure about X" rather than flagging it as a definite issue.9899---100101## Output1021031. If there is a bug, be direct and clear about why it is a bug.1042. Clearly communicate severity of issues. Do not overstate severity.1053. Critiques should clearly and explicitly communicate the scenarios, environments, or inputs that are necessary for the bug to arise. The comment should immediately indicate that the issue's severity depends on these factors.1064. Your tone should be matter-of-fact and not accusatory or overly positive. It should read as a helpful AI assistant suggestion without sounding too much like a human reviewer.1075. Write so the reader can quickly understand the issue without reading too closely.1086. AVOID flattery, do not give any comments that are not helpful to the reader. Avoid phrasing like "Great job ...", "Thanks for ...".1097. Cite the affected file and line for each finding.