A global Git commit-msg hook that calls Claude Code to review every commit before it completes.
On every git commit, the hook:
- Collects the staged diff, commit message, branch name, and file list
- Sends them to Claude Code for a quick code review
- Displays the review (summary, issues, suggestions)
- Asks you to proceed or abort
- Claude Code CLI installed and authenticated
Edit config.conf before installing to customize behavior:
# Model to use for commit reviews (e.g., opus, sonnet, haiku)
MODEL=opusValues are baked into the hook at install time. After changing config.conf, re-run ./install.sh to apply.
cd ~/ai-commit-hook
./install.shThis will:
- Read configuration from
config.conf - Install the hook to
~/.config/git/hooks/commit-msgwith config values baked in - Set
git config --global core.hooksPath ~/.config/git/hooks
Skip the review for a single commit:
git commit --no-verifygit config --global --unset core.hooksPath
rm ~/.config/git/hooks/commit-msgReview times measured on a typical commit:
| Model | Review Time |
|---|---|
| Claude Haiku 4.5 | ~7.5 s |
| Claude Opus 4.6 | ~15.0 s |
| Claude Sonnet 4.5 | ~17.5 s |
Haiku is the fastest option for low-latency reviews. Notably, Opus 4.6 — the most capable and accurate model — also beats Sonnet 4.5 on speed, making it a strong default choice.
- Large diffs (>20,000 lines) are truncated to keep the review fast
- If Claude is unavailable, the commit proceeds without blocking
- If a local
.git/hooks/commit-msghook exists, it is chained after the review - The prompt asks Claude to check for: message accuracy, bugs, security issues, and leftover debug code
ai-commit-hook/
commit-msg # The hook script (template with placeholders)
install.sh # Installation helper (substitutes config, sets hooksPath)
config.conf # Install-time configuration
README.md # This file
CLAUDE.md # Project conventions for Claude
plans/ # Implementation plans
PLAN-001.md
PLAN-002.md