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.
| Hook | Description | Trigger |
|---|---|---|
| AI Code Review | Reviews staged changes for bugs, style issues, and anti-patterns | pre-commit |
| Commit Message Generator | Auto-generates conventional commit messages from your diff | prepare-commit-msg |
| Commit Message Validator | Validates commit messages follow conventions | commit-msg |
| Pre-Push Security Scan | Scans for secrets, vulnerabilities, and large files | pre-push |
git clone https://github.com/Sagargupta16/ai-git-hooks.git
cd ai-git-hooks
./scripts/install.shCreate .ai-hooks.yml in your project root:
provider: claude # claude | openai | ollama
model: claude-sonnet-4-5-20250514 # 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
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# 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"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
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 abuseEnsures 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"
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.
| Provider | Cost | Speed | Privacy | Setup |
|---|---|---|---|---|
| Claude (Anthropic) | API pricing | Fast | Cloud | API key |
| OpenAI (GPT-4) | API pricing | Fast | Cloud | API key |
| Ollama (local) | Free | Varies | Full privacy | Local install |
ollama pull llama3.1
echo 'provider: ollama' >> .ai-hooks.yml
echo 'model: llama3.1' >> .ai-hooks.yml| Script | Description |
|---|---|
install.sh |
Install hooks to your git project |
uninstall.sh |
Remove hooks from your project |
test.sh |
Test hooks against sample diffs |
Contributions welcome — new hooks, better prompts, new AI providers, or bug fixes.
- Fork this repo
- Create a feature branch
- Add your changes with tests
- Submit a PR
See CONTRIBUTING.md for full guidelines.