r/codereview • u/CCodeSI • 21d ago
Half our review comments on AI-written PRs were things a script could have caught before the PR existed. So we made the script run first.
Reviewing code from a coding agent, the comments split into two piles. One pile needs a human: is this the right approach, does it handle the edge case, is the API shape sane. The other pile is mechanical: formatter not run, type check failing, a generated file edited by hand, a migration added without the matching down step, a lockfile out of sync. The second pile was bigger, and it was eating the review time the first pile needed.
The usual fix is CI, but CI runs after the PR is opened, so the mechanical comments still land in review, just from a bot. We wanted them to never reach the PR.
In CCode, the coding agent we build, hooks are scripts tied to moments in the agent's work, and the exit code decides what happens. The ones that moved review for us:
- After every file edit, run the formatter and the type checker on that file. Failures go back to the agent as feedback, so it fixes them right then, while it still has the context.
- Before a shell command runs, check it. Exit 2 blocks it and shows your message to the agent, so "don't edit generated files" or "no force-push" becomes a rule, not advice in a prompt.
- When the agent says it's done, run the checks you'd run before opening a PR. Exit 2 sends it back to work.
What changed: the PRs that reach us pass the mechanical bar already, and review comments are the ones only a person can make. The agent also stops relearning your conventions from review feedback, because it hits them while working.
If you review AI-generated PRs: what share of your comments is mechanical, and have you managed to push any of it ahead of the PR?