Code Review
Overview
Structured, actionable code review focused on correctness, bugs, style, and maintainability.
Act as a senior engineer: thorough, pragmatic, impact-first.
Constraints
- Do NOT modify code unless explicitly asked.
- Do NOT guess missing code or behavior; ask for missing context.
- Do NOT suggest adding suppressions (e.g.,
#pragma warning disable).
- Stay focused on review quality; avoid unrelated commentary.
- Work strictly from the provided diff or code context.
When to Use
- Reviewing staged changes before committing.
- Reviewing branch changes before merging or opening a PR.
- Checking a diff for correctness, bugs, style, or structure.
- Final review of all changes on a feature branch.
- Quick sanity-check of a small changeset before pushing.
When NOT to use:
- Implementing new features from scratch.
- Running test suites (see
python-testing or equivalent).
- Refactoring without a prior review (review first, then refactor on request).
- Linting or formatting only — use a linter or formatter directly.
Quick Reference
| Area |
Look for |
| Correctness & Logic |
Wrong behavior, broken contracts, off-by-one |
| Bugs & Edge Cases |
Nil/null paths, boundary values, error propagation |
| Code Quality & Style |
Naming, readability, idiomatic usage |
| Structure & Maintainability |
Coupling, duplication, separation of concerns |
| Best Practices |
Language/framework conventions, SOLID, DRY |
| Test Adequacy |
Missing tests for behavior changes, regression gaps |
| Security & Risk |
Input validation, auth, secrets, dependency risk |
| Documentation |
Misleading comments, missing doc for public API |
Common Mistakes
- Reviewing without full context — jumping to conclusions without reading the complete diff or understanding intent.
- Mixing review and edits — modifying code during the review phase instead of separating feedback from implementation.
- Nitpick overload — burying critical issues under dozens of style nitpicks.
- Ignoring intent — critiquing design choices without understanding the constraints or goals behind them.
- Incomplete scope — reviewing only one file when the change spans multiple files or modules.
Workflow
Step 0 — Set Review Strategy
Before collecting findings:
- For medium/large or cross-module changes, write a short review plan focused on risk hotspots.
- Optionally split analysis by module and use subagents/parallel review passes when available.
- Consolidate findings into one prioritized report after parallel passes.
Step 1 — Identify Changes
Determine the review scope based on what the user is reviewing.
Pre-commit (staged changes):
# List staged files
git diff --cached --name-status
# View staged diff
git --no-pager diff --cached
# View staged diff for a specific file
git --no-pager diff --cached -- path/to/file.ext
Pre-merge (branch vs. target):
# Resolve target base branch from origin/HEAD when available
BASE_BRANCH=$(git rev-parse --abbrev-ref origin/HEAD 2>/dev/null)
BASE_BRANCH=${BASE_BRANCH#origin/}
BASE_BRANCH=${BASE_BRANCH:-main}
MERGE_BASE=$(git merge-base "$BASE_BRANCH" HEAD)
# List changed files on this branch relative to the target base
git diff --name-status "$MERGE_BASE"...HEAD
# View full branch diff
git --no-pager diff "$MERGE_BASE"...HEAD
# View diff for a specific file or directory
git --no-pager diff "$MERGE_BASE"...HEAD -- path/to/file.ext
If the user does not specify scope, infer from context:
- On a feature branch with commits ahead of the target base branch → pre-merge review.
- Staged changes present → pre-commit review.
- Ask if ambiguous, especially when default branch detection fails.
Step 2 — Structured Review (No Edits)
For each changed file or module, summarize what changed and why.
Evaluate each area in the Quick Reference table above.
Rules:
- If intent is unclear, ask clarifying questions before judging.
- If an area has no issues, state that explicitly.
- Reference specific code locations (line numbers or quoted snippets).
- Keep feedback actionable and concise.
- Review all changed lines before final judgment; open surrounding context where needed.
- Address runtime errors, validation, error handling, concurrency risks, resource usage, and obvious performance pitfalls.
- Behavior changes without tests → raise an issue (at least Medium).
- Style comments are non-blocking unless they map to project conventions.
- Dependency manifest or lockfile changes → assess supply-chain risk and compatibility.
- Call out TODO comments and their implications.
Compile findings into issues using the template in assets/issue-template.md.
Sort issues by priority: critical > high > medium > low.
For each issue, include blocking status, confidence, and evidence.
Step 3 — Apply Changes (Only on Explicit Request)
Proceed only when the user asks to "apply changes", "fix issues", "implement suggestions", or similar.
- Apply only changes discussed in Step 2.
- Make minimal, targeted edits.
- Do not introduce additional refactors without user approval.
- After editing, summarize what changed and why, mapping back to the original review items.
Scope Note
Treat these recommendations as preferred defaults.
When a default conflicts with project constraints, suggest a better-fit alternative, call out tradeoffs, and note compensating controls.
References
assets/issue-template.md — issue type/priority legends and suggestion format.
references/review-best-practices-links.md — external review best-practice links used by this skill.
1---2name: code-review-163description: Use when reviewing code changes before committing or merging — staged diffs, branch diffs, or PR readiness checks. Triggers: 'review my code', 'check these changes', 'review this branch', 'give feedback on my diff', 'is this PR ready?'. Not for implementing features, running test suites, or formatting-only passes.4---5
6# Code Review
7
8## Overview
9
10Structured, actionable code review focused on correctness, bugs, style, and maintainability.
11Act as a senior engineer: thorough, pragmatic, impact-first.
12
13## Constraints
14
15- Do NOT modify code unless explicitly asked.
16- Do NOT guess missing code or behavior; ask for missing context.
17- Do NOT suggest adding suppressions (e.g., `#pragma warning disable`).
18- Stay focused on review quality; avoid unrelated commentary.
19- Work strictly from the provided diff or code context.
20
21## When to Use
22
23- Reviewing staged changes before committing.
24- Reviewing branch changes before merging or opening a PR.
25- Checking a diff for correctness, bugs, style, or structure.
26- Final review of all changes on a feature branch.
27- Quick sanity-check of a small changeset before pushing.
28
29**When NOT to use:**
30
31- Implementing new features from scratch.
32- Running test suites (see `python-testing` or equivalent).
33- Refactoring without a prior review (review first, then refactor on request).
34- Linting or formatting only — use a linter or formatter directly.
35
36## Quick Reference
37
38| Area | Look for |
39| --------------------------- | --------------------------------------------------- |
40| Correctness & Logic | Wrong behavior, broken contracts, off-by-one |
41| Bugs & Edge Cases | Nil/null paths, boundary values, error propagation |
42| Code Quality & Style | Naming, readability, idiomatic usage |
43| Structure & Maintainability | Coupling, duplication, separation of concerns |
44| Best Practices | Language/framework conventions, SOLID, DRY |
45| Test Adequacy | Missing tests for behavior changes, regression gaps |
46| Security & Risk | Input validation, auth, secrets, dependency risk |
47| Documentation | Misleading comments, missing doc for public API |
48
49## Common Mistakes
50
51- **Reviewing without full context** — jumping to conclusions without reading the complete diff or understanding intent.
52- **Mixing review and edits** — modifying code during the review phase instead of separating feedback from implementation.
53- **Nitpick overload** — burying critical issues under dozens of style nitpicks.
54- **Ignoring intent** — critiquing design choices without understanding the constraints or goals behind them.
55- **Incomplete scope** — reviewing only one file when the change spans multiple files or modules.
56
57## Workflow
58
59### Step 0 — Set Review Strategy
60
61Before collecting findings:
62
63- For medium/large or cross-module changes, write a short review plan focused on risk hotspots.
64- Optionally split analysis by module and use subagents/parallel review passes when available.
65- Consolidate findings into one prioritized report after parallel passes.
66
67### Step 1 — Identify Changes
68
69Determine the review scope based on what the user is reviewing.
70
71**Pre-commit (staged changes):**
72
73```sh
74# List staged files
75git diff --cached --name-status
76
77# View staged diff
78git --no-pager diff --cached
79
80# View staged diff for a specific file
81git --no-pager diff --cached -- path/to/file.ext
82```
83
84**Pre-merge (branch vs. target):**
85
86```sh
87# Resolve target base branch from origin/HEAD when available
88BASE_BRANCH=$(git rev-parse --abbrev-ref origin/HEAD 2>/dev/null)
89BASE_BRANCH=${BASE_BRANCH#origin/}
90BASE_BRANCH=${BASE_BRANCH:-main}
91MERGE_BASE=$(git merge-base "$BASE_BRANCH" HEAD)
92
93# List changed files on this branch relative to the target base
94git diff --name-status "$MERGE_BASE"...HEAD
95
96# View full branch diff
97git --no-pager diff "$MERGE_BASE"...HEAD
98
99# View diff for a specific file or directory
100git --no-pager diff "$MERGE_BASE"...HEAD -- path/to/file.ext
101```
102
103If the user does not specify scope, infer from context:
104
105- On a feature branch with commits ahead of the target base branch → pre-merge review.
106- Staged changes present → pre-commit review.
107- Ask if ambiguous, especially when default branch detection fails.
108
109### Step 2 — Structured Review (No Edits)
110
111For each changed file or module, summarize what changed and why.
112Evaluate each area in the Quick Reference table above.
113
114Rules:
115
116- If intent is unclear, ask clarifying questions before judging.
117- If an area has no issues, state that explicitly.
118- Reference specific code locations (line numbers or quoted snippets).
119- Keep feedback actionable and concise.
120- Review all changed lines before final judgment; open surrounding context where needed.
121- Address runtime errors, validation, error handling, concurrency risks, resource usage, and obvious performance pitfalls.
122- Behavior changes without tests → raise an issue (at least Medium).
123- Style comments are non-blocking unless they map to project conventions.
124- Dependency manifest or lockfile changes → assess supply-chain risk and compatibility.
125- Call out TODO comments and their implications.
126
127Compile findings into issues using the template in `assets/issue-template.md`.
128Sort issues by priority: critical > high > medium > low.
129For each issue, include blocking status, confidence, and evidence.
130
131### Step 3 — Apply Changes (Only on Explicit Request)
132
133Proceed only when the user asks to "apply changes", "fix issues", "implement suggestions", or similar.
134
1351. Apply only changes discussed in Step 2.
1362. Make minimal, targeted edits.
1373. Do not introduce additional refactors without user approval.
1384. After editing, summarize what changed and why, mapping back to the original review items.
139
140## Scope Note
141
142Treat these recommendations as preferred defaults.
143When a default conflicts with project constraints, suggest a better-fit alternative, call out tradeoffs, and note compensating controls.
144
145## References
146
147- `assets/issue-template.md` — issue type/priority legends and suggestion format.
148- `references/review-best-practices-links.md` — external review best-practice links used by this skill.