Code review that works: small PRs, checklists, and automation
How to run fast, useful code reviews: the goals of review, small PRs, a description template, what to leave to machines, a reviewer checklist, CODEOWNERS, and metrics that don't turn review into punishment.
Development$ pre-commit run --all-files▍Everyone has seen both extremes of code review. On one side, the 3,000-line PR approved in two minutes with an “LGTM” (looks good to me). On the other, the ten-line PR that sits for a week and comes back with forty comments about commas. Neither one improves the code or the team.
Code review that works is fast, focused on what matters, and leaves the repetitive work to machines. In this article, we build that process piece by piece.
What code review is for
Before talking about tools, it’s worth agreeing on the goal. A good review aims for:
- Knowledge sharing: at least one more person understands each change, which reduces the “only so-and-so knows how to touch this” problem.
- Quality and correctness: catching logic bugs, forgotten edge cases, and security issues.
- Design and maintainability: does the change fit the architecture? Will someone understand this code six months from now?
- Consistency: the code follows the conventions the team agreed on.
What review should not be: a gate where someone exercises authority, or a place to impose personal taste. The reviewer and the author are on the same side.
Small PRs: the rule that solves half the problems
Large PRs get worse reviews. Faced with hundreds of changed files, the reviewer gets tired, skims, and approves. Small PRs get reviewed faster, with more attention, and are easier to revert if something goes wrong. There’s no magic number, but many teams use a few hundred changed lines, at most, as a rule of thumb.
How to split a large change:
- Separate refactoring from behavior: one PR only renames and reorganizes; the next one changes the logic.
- Vertical slices: deliver the feature in parts that work on their own (first the API, then the screen, then the report).
- Stacked PRs: each PR is opened on top of the previous one’s branch, and they’re reviewed in sequence. The
git rebase --update-refscommand and dedicated tools help keep the stack up to date. - Feature flags: unfinished code can go into
mainswitched off, which lets you integrate a little at a time. That’s the heart of trunk-based development.
A good PR description
The reviewer wasn’t inside your head when you wrote the code. The description is where you explain the why. A simple template, saved as .github/pull_request_template.md, is filled in automatically by GitHub for every new PR:
## What changes
A 1-3 sentence summary of what this PR does.
## Why
Context for the problem and a link to the issue (e.g., #123).
## How to test
1. Steps to reproduce or validate the change
2. Commands, URLs, or sample data
## Risks and rollback
What could go wrong and how to undo it (flag, revert, reversible migration).
## Author checklist
- [ ] Tests added or updated
- [ ] Documentation updated, if needed
- [ ] No secrets or sensitive data in the code
Humans review ideas, machines review formatting
Arguing about indentation in a PR is a waste of human time. Anything that can be checked automatically should be checked before anyone opens the PR.
| Check | Who does it | Example tools |
|---|---|---|
| Formatting and style | Machine | Prettier, Black, Ruff, gofmt |
| Common mistakes and bad practices | Machine | ESLint, Ruff, golangci-lint |
| Types | Machine | TypeScript (tsc), mypy |
| Passing tests | Machine | pytest, Jest, go test in CI |
| Secrets and vulnerable dependencies | Machine | Gitleaks, Trivy, Dependabot |
| Business logic and edge cases | Human | Careful reading and questions |
| Design, naming, and readability | Human | Conversation on the PR |
| Whether the change solves the right problem | Human | Context from the issue |
Security checks in particular work best when they’re automatic and unobtrusive, as we show in silent DevSecOps. And tests, of course, have to exist and be well balanced; see the test pyramid.
Pre-commit: the first filter, on the developer’s machine
pre-commit is a tool that runs checks automatically on every git commit (a Git hook). That way, code arrives at the PR already formatted. An example .pre-commit-config.yaml for a Python project:
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.0
hooks:
- id: ruff
args: [--fix]
- id: ruff-format
To enable it and run it across the whole repository:
pip install pre-commit
pre-commit install # installs the hook in .git/hooks
pre-commit run --all-files # runs on every file
pre-commit autoupdate # updates the versions in "rev"
Run the same checks in CI: the local hook can be skipped (git commit --no-verify), CI can’t.
Reviewer checklist
With formatting handled by machines, the reviewer can focus on what matters:
- Did I understand the PR’s goal from the description?
- Is the logic correct, including edge cases (empty list, null value, network error)?
- Are there tests that would fail if the code were wrong?
- Do the names make it clear what each thing does?
- Are there security risks, such as unvalidated user input or sensitive data in logs?
- Is the change observable in production (logs, metrics) and easy to revert?
How to give feedback
How a comment is written matters as much as what it says. A few rules:
- Comment on the code, not the person: “this function is doing two things” instead of “you overcomplicated this.”
- Be specific: point to the line, explain the problem, and, if possible, suggest an alternative.
- Make it clear what’s blocking: the author needs to know what’s required and what’s optional.
- Praise, too: recognizing a good solution teaches as much as pointing out a problem.
A useful convention is prefixes, formalized in the Conventional Comments standard: nit: (small detail, not blocking), question: (a genuine question), suggestion: (a proposed improvement), issue: (a problem that must be fixed), and praise: (a compliment). You can also add (non-blocking) or (blocking). For example: suggestion (non-blocking): we could use a dict here and avoid the nested if.
Response time agreements, CODEOWNERS, and branch protection
A PR waiting for review is work sitting in inventory. Agree on a response time: Google’s code review guide, for example, recommends responding within one business day at most. Many teams set aside two fixed slots a day for reviewing.
The CODEOWNERS file defines who should review each part of the repository. GitHub automatically requests a review from those owners when a PR changes the matching files. When more than one rule applies, the last matching one wins:
# .github/CODEOWNERS
* @your-org/platform-team
/src/payments/ @your-org/payments-team
/infra/ @your-org/sre
*.tf @your-org/sre
/docs/ @your-org/documentation
Combine this with branch protection (or rulesets) on main: require a pull request, at least one approval, approval from code owners, passing CI status checks, and resolved conversations before merging. If Git and PRs are still new to you, start with what is Git and GitHub.
Metrics without turning review into punishment
Three metrics help you spot bottlenecks:
- Time to first review: how long the author waits until someone looks at the PR.
- PR size: lines and files changed; growing PRs often explain slow reviews.
- Cycle time: from the first commit to merge (or to production).
Use them to improve the process, never to rank people. When “number of comments” or “PRs approved” becomes an individual target, people optimize the number instead of the quality: pointless comments show up and hard reviews get avoided.
AI-assisted review
AI tools can summarize PRs, flag possible bugs, and suggest tests, and they make a good first pass. But they don’t know the business context or the team’s architecture decisions, and they can be confidently wrong. Treat AI as one more automated reviewer, next to the linter: useful, but approval still belongs to a person.
Checklist
- Small PRs, each with one clear intent
- A description template covering what, why, how to test, and risks
- Formatting, linting, types, and tests checked by machines (pre-commit and CI)
- Comments with prefixes that make it clear what’s blocking
- An agreed response time for the first review
- CODEOWNERS and branch protection configured on
main - Metrics used to improve the process, not to evaluate people
Good code review isn’t the one that finds the most defects; it’s the one that makes the whole team write better code next time.