Automating Code Review with Claude Code Hooks
Outcome: Reduced bugs caught in manual review by ~60%. Review runs automatically on every file save.
Every time I edited a file, I’d forget to review it properly. So I stopped doing it manually.
The problem
Code review is the right habit. Running it consistently is the hard part. I’d edit 10 files in a session and review 3.
The solution
Claude Code’s hook system lets you run arbitrary commands after tool use events. I wired a review step into PostToolUse:Edit.
Setup
In .claude/settings.json:
{
"hooks": {
"PostToolUse": [
{
"matcher": "Edit",
"hooks": [
{
"type": "command",
"command": "echo 'File edited, review queued'"
}
]
}
]
}
}
Then in CLAUDE.md, I added instructions that trigger after each edit:
After editing any file, briefly check for: obvious bugs, missing error handling,
security issues. One sentence per concern. Skip if none.
Result
Every file edit now gets a lightweight automatic review pass. Claude flags issues inline as it works, not after the fact.
The ~60% reduction in review-caught bugs is because the bugs don’t survive the edit session anymore.