AI Git Hooks

June 12, 2026 ยท View on GitHub

GitHub stars GitHub forks License Last Commit

AI-powered git hooks that review your code, generate commit messages, catch bugs, and scan for security issues - before you push.

Drop-in git hooks that use AI (Claude, OpenAI, Ollama) to automate code quality checks at every stage of your git workflow.

Hooks

HookDescriptionTrigger
AI Code ReviewReviews staged changes for bugs, style issues, and anti-patternspre-commit
Commit Message GeneratorAuto-generates conventional commit messages from your diffprepare-commit-msg
Commit Message ValidatorValidates commit messages follow conventionscommit-msg
Pre-Push Security ScanScans for secrets, vulnerabilities, and large filespre-push

Quick Start

1. Install

git clone https://github.com/Sagargupta16/ai-git-hooks.git
cd ai-git-hooks
./scripts/install.sh

2. Configure

Create .ai-hooks.yml in your project root:

provider: claude            # claude | openai | ollama
model: claude-sonnet-4-6    # model to use

hooks:
  pre-commit:
    enabled: true
    severity: warn          # error | warn | info
    max_files: 20
    ignore:
      - "*.lock"
      - "*.min.js"
      - "dist/**"

  prepare-commit-msg:
    enabled: true
    style: conventional     # conventional | simple | detailed
    ticket_prefix: true     # auto-detect ticket from branch name

  commit-msg:
    enabled: true
    convention: conventional
    max_length: 72

  pre-push:
    enabled: true
    scan_secrets: true
    scan_dependencies: true
    max_file_size: 5MB

3. Set your API key

# Claude (recommended)
export ANTHROPIC_API_KEY="sk-ant-..."

# OpenAI
export OPENAI_API_KEY="sk-..."

# Ollama (free, local - no key needed)
export OLLAMA_HOST="http://localhost:11434"

Hook Details

Pre-Commit: AI Code Review

Reviews staged changes and catches issues before they're committed.

What it checks:

  • Bug patterns and logic errors
  • Security vulnerabilities (XSS, SQL injection, etc.)
  • Performance anti-patterns
  • Missing error handling

Example output:

AI Code Review (3 files changed)

src/api/users.js:42
  WARNING: SQL query uses string concatenation instead of parameterized query.
  Fix: Use db.query('SELECT * FROM users WHERE id = \$1', [id])

src/components/Dashboard.tsx:108
  INFO: useEffect missing dependency 'userId' in dependency array.

src/utils/parse.js
  OK: No issues found.

Summary: 1 warning, 1 info, 0 errors

Prepare-Commit-Msg: Auto-Generate Messages

Analyzes your diff and generates a commit message following your conventions.

git add .
git commit
# Hook auto-generates:
# feat(auth): add JWT refresh token rotation
#
# - Add refresh token endpoint with 7-day expiry
# - Implement token rotation on each refresh
# - Add rate limiting to prevent token abuse

Commit-Msg: Validate Messages

Ensures commit messages follow your team's conventions.

Commit Message Validation
Message: "fixed stuff"

ERRORS:
  - Type prefix missing. Expected: feat|fix|docs|style|refactor|test|chore
  - Message too vague. Describe what was fixed and why.

Suggested: "fix: resolve null pointer in user authentication flow"

Pre-Push: Security Scan

Scans all commits about to be pushed for security issues.

Pre-Push Security Scan

CRITICAL: Possible API key found in src/config.js:8
  Line: const API_KEY = "sk-ant-api03-..."
  Action: Remove the key and rotate it immediately.

WARNING: Large file detected: assets/video.mp4 (45 MB)
  Action: Consider Git LFS or .gitignore.

Scan complete: 1 critical, 1 warning
Push blocked due to critical finding.

Supported AI Providers

ProviderCostSpeedPrivacySetup
Claude (Anthropic)API pricingFastCloudAPI key
OpenAIAPI pricingFastCloudAPI key
Ollama (local)FreeVariesFull privacyLocal install

Using Ollama (Free & Private)

ollama pull llama3.1
echo 'provider: ollama' >> .ai-hooks.yml
echo 'model: llama3.1' >> .ai-hooks.yml

Scripts

ScriptDescription
install.shInstall hooks to your git project
uninstall.shRemove hooks from your project
test.shTest hooks against sample diffs

Contributing

Contributions welcome - new hooks, better prompts, new AI providers, or bug fixes.

  1. Fork this repo
  2. Create a feature branch
  3. Add your changes with tests
  4. Submit a PR

See CONTRIBUTING.md for full guidelines.

More AI Developer Tools

ProjectDescription
claude-cost-optimizerSave 30-60% on Claude Code costs - proven strategies and benchmarks
claude-code-recipes50+ copy-paste recipes for Claude Code - commands, subagents, hooks, skills
mcp-toolkitProduction-ready middleware for MCP servers - auth, caching, rate limiting
agent-recipesAI agent workflows for real-world dev tasks - code review, testing, security

License

MIT