
Every developer I have watched work in 2026 runs Claude Code (or Cursor, or Codex CLI, or Aider) for the big refactors and the tricky bug hunts. Almost nobody wires it into the small, repetitive moment that happens thirty times a day: git commit. That is the moment a fresh set of bugs, dead code, or a leaked secret is about to leave your machine and head to a teammate. It is also the moment when a 2-second AI code review would catch most of them, before they get into a PR, before they hit CI, before they hit a Slack message that says "why is this here."
The fix is a pre-commit hook that pipes your staged diff into claude --print and prints a one-paragraph review to stderr. No new tool. No new service. No new browser tab. Thirty lines of bash, ten minutes of setup, free forever.
Drop this in .git/hooks/pre-commit:
#!/usr/bin/env bash
set -e
# Skip cleanly if Claude Code is not installed
command -v claude >/dev/null 2>&1 || { echo "claude CLI not found, skipping review" >&2; exit 0; }
# Build the diff of what is about to be committed
FULL_DIFF=$(git diff --cached)
[ -z "$FULL_DIFF" ] && exit 0
# Guard against huge diffs that blow the context window
LINES=$(printf '%s' "$FULL_DIFF" | wc -l)
if [ "$LINES" -gt 500 ]; then
echo "Diff too large for hook review ($LINES lines), skipping." >&2
exit 0
fi
# Run Claude in headless print mode with a tight reviewer prompt
REVIEW=$(printf '%s' "$FULL_DIFF" | claude --print \
--model claude-haiku-3 \
--system-prompt "You are a senior code reviewer. Review the diff for bugs, dead code, leaked secrets, race conditions, and obvious security issues. Reply with at most 5 bullet points. If nothing is wrong, reply: LGTM." \
2>/dev/null)
# Print to stderr so it shows up but does not pollute the commit message
echo "--- Claude Code review ---" >&2
echo "$REVIEW" >&2
echo "--------------------------" >&2
# Soft warning only — do not block the commit
exit 0Then chmod +x .git/hooks/pre-commit. Done.
--print Modeclaude --print is the non-interactive variant. Prompt on stdin, single response on stdout. No TUI, no spinner, no permission popups. That is what makes it cheap enough to run on every commit. Pair it with --model claude-haiku-3 and you get cost under a tenth of a cent per review and latency under three seconds on a warm cache. For a working repo with twenty commits a day per developer, that is roughly $0.20 per developer per month. Less than the coffee.
1. git add . 2. git commit -m "fix webhook race" 3. Hook runs. Three seconds later you see 0–5 bullets on stderr. 4. If the bullets name a real issue, git reset, fix, recommit. 5. If the bullets are noise (Haiku hallucinates occasionally), commit anyway.
The whole loop takes about four seconds end to end on a normal diff. It does not feel like a tax. It feels like having a reviewer in the room.
Commit message injection. Never let the review output flow back into the commit. That is why we print to stderr, not stdout. A teammate's --no-verify on a high-pressure day should not silently commit Haiku's opinion into your message.
Large diffs. A 4,000-line refactor will exceed context, produce noise, and burn time. The 500-line guard above skips those. Big refactors get the full review in your terminal session; small commits get the cheap hook.
A pre-commit hook is the highest-leverage place to insert an AI into your day. It runs thirty times a day, costs effectively nothing, catches the bugs you were going to fix in code review anyway, and does not require you to learn a new tool. The whole setup is a 30-line bash file and a chmod. Once it ships, every commit on that machine gets a free reviewer. CI is lighter, PRs are cleaner, code review meetings are shorter.
— Mr. Technology