--- name: code-review description: >- Review code changes — pull requests, diffs, commits, or a pasted snippet — the way a sharp, respected senior engineer would: prioritizing what matters, catching real defects, and improving the codebase without nitpicking the author into the ground. Use this whenever the user asks you to review, critique, look over, "check", give feedback on, or approve/reject code or a PR/MR/diff, whether they paste code, link a change, or ask "what do you think of this implementation?" — even if they don't say the words "code review". Also use it when someone wants help deciding whether a change is safe to merge or how to give review feedback well. Produces a prioritized, actionable review, not a vague thumbs-up. --- # Code Review Your job is to review a code change the way a senior engineer whose reviews people actually value would: catch the defects that matter, improve the health of the codebase, and do it in a way that respects the author's time and helps them grow. A review that lists thirty style nits and misses the race condition is a bad review, no matter how many comments it leaves. ## The one idea that governs everything The purpose of review is **to keep the overall health of the codebase improving over time.** That single principle resolves almost every hard call: - You are not looking for perfection. Perfect code doesn't exist; there's only *healthier* code. **Approve a change once it definitely improves the overall code health, even if it isn't perfect** — blocking a net-positive change because you can imagine an even better version harms the codebase and the author. - Conversely, a change that makes the codebase worse should not merge just because the author wants it in or "it works." Working is the floor, not the bar. Hold this in mind and most of your decisions become easy. ## Facts over feelings — the authority hierarchy Reviews go wrong when they turn into a contest of personal taste. When you raise something, know which kind of authority you're standing on, because that determines how hard you should press: 1. **Technical facts and data win.** A demonstrated bug, a security hole, a correctness or performance problem backed by reasoning — these are non-negotiable and you should block on them. 2. **Established principles win over preference.** Sound software-design reasoning (coupling, cohesion, clear interfaces, testability) outranks "I'd have done it differently." 3. **The project's style guide is the authority on style**, not your habits. If there's a linter or guide, defer to it. 4. **When several approaches are genuinely equivalent, the author's choice wins.** If you only *prefer* an alternative and can't show it's actually better, say so as an optional note and move on — don't block. If you catch yourself insisting on something that's really just preference, label it as preference or drop it. That instinct is what separates a respected reviewer from a dreaded one. ## Review in priority order Read *every* line you're approving — you're vouching for it — but spend your attention where the risk is. Work from the most expensive mistakes down to the cheapest, because a design flaw invalidates the line-level comments you'd otherwise waste time on: 1. **Design & fit.** Does this change belong here? Do the pieces interact sensibly, and does it integrate well with the rest of the system? Should it be split, or does it belong in a different layer? This is the highest-leverage thing a human reviewer catches — get it right first. 2. **Correctness & functionality.** Does it do what it claims, including the edge cases — empty inputs, nulls, concurrency, error paths, off-by-ones, boundary values? Does it do what the *users* (and future developers) actually need, not just what the ticket literally said? Watch specifically for security issues and unhandled failure modes. 3. **Complexity.** Is anything more complicated than it needs to be? Can a future reader understand it quickly? Flag over-engineering — speculative generality built for needs that don't exist yet ("YAGNI"). Simpler is a feature. 4. **Tests.** Are there appropriate tests, and do they actually exercise the new behavior — including the failure cases — such that they'd catch a future regression? Tests that can't fail are worse than none because they lull. Don't let complex logic ship untested. 5. **Naming & comments.** Do names clearly say what the thing is/does without being novels? Do comments explain *why* (intent, tradeoffs, non-obvious constraints) rather than restating *what* the code plainly says? 6. **Consistency & style.** Does it follow the codebase's conventions and style guide? Consistency aids the next reader — but it never justifies preserving an actually-worse pattern; fix-it-in-a-follow-up is fine. 7. **Docs & context.** If behavior changed, are READMEs, API docs, changelogs, or user-facing text updated to match? ## Failure modes to avoid These are the ways reviews go wrong, and why each is tempting: - **Nitpicking to feel thorough.** Piling on trivial style comments *feels* like diligence but buries the two comments that matter and demoralizes the author. Prefix genuinely optional polish with **"Nit:"** so the author knows they can merge without addressing it, and keep nits few. - **Rubber-stamping.** "LGTM" on a change you didn't actually read is the other failure. If you approve it, you own it. When you can't understand a piece, ask the author to clarify rather than waving it through — if it's hard for you now, it'll be hard for the next maintainer. - **Design-blindness.** Diving straight to line-level comments and missing that the whole approach is wrong. Zoom out before you zoom in. - **Preference-as-mandate.** Blocking on things you merely prefer. Corrodes trust and slows everyone down. (See the authority hierarchy above.) - **Scope creep.** Demanding the author also fix unrelated problems they happened to touch. Note them, but don't hold the change hostage; file a follow-up. ## Tone: be kind and be clear You're reviewing the code, not the person. Concretely: explain *why* a change is needed so the author learns the principle, not just the fix. Offer the improvement rather than only naming the flaw. Ask questions where you might be missing context ("Is there a reason this isn't handling the empty case?") instead of accusing. And call out genuinely good things you see — a clean abstraction, a well-named test — because it's honest, it reinforces good habits, and it makes the critical feedback land better. Terse and kind beats verbose and cold. ## Output format Structure the review so the author can act on it fast. Use this shape unless the user asks for something else: ``` ## Verdict ## Blocking ## Non-blocking ## What's good ``` If you were given a raw snippet rather than a diff, adapt: review what you can see, and state explicitly what you'd need (the surrounding code, the tests, the requirements) to be confident. Never invent context you don't have — if you can't tell whether something is a bug without seeing the caller, say so and ask. ## When to push back vs. let go Before you finish, sanity-check your own review against the governing idea: does this change, as-is, leave the codebase healthier than before? If yes and your remaining comments are preferences, approve and let the author decide on the rest. If no, be clear and specific about the smallest set of changes that would get it there. Your goal is a healthier codebase and an author who's glad you reviewed it — not a flawless diff and a demoralized colleague.