Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AI Commit Hook

A global Git commit-msg hook that calls Claude Code to review every commit before it completes.

What It Does

On every git commit, the hook:

  1. Collects the staged diff, commit message, branch name, and file list
  2. Sends them to Claude Code for a quick code review
  3. Displays the review (summary, issues, suggestions)
  4. Asks you to proceed or abort

Prerequisites

Configuration

Edit config.conf before installing to customize behavior:

# Model to use for commit reviews (e.g., opus, sonnet, haiku)
MODEL=opus

Values are baked into the hook at install time. After changing config.conf, re-run ./install.sh to apply.

Install

cd ~/ai-commit-hook
./install.sh

This will:

  • Read configuration from config.conf
  • Install the hook to ~/.config/git/hooks/commit-msg with config values baked in
  • Set git config --global core.hooksPath ~/.config/git/hooks

Bypass

Skip the review for a single commit:

git commit --no-verify

Uninstall

git config --global --unset core.hooksPath
rm ~/.config/git/hooks/commit-msg

Model Performance

Review 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.

How It Works

  • 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-msg hook exists, it is chained after the review
  • The prompt asks Claude to check for: message accuracy, bugs, security issues, and leftover debug code

Project Structure

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

About

Have Claude take a look at your git commit before it's committed.

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Used by

Contributors

Languages