| name | git-hooks |
| description | Set up and configure Git pre-commit hooks for code quality, secrets scanning, and commit message validation. Use when installing git hooks, configuring pre-commit checks, or enforcing code standards. |
Git Hooks Skill
When to Activate
Activate this skill when:
- Setting up pre-commit hooks
- Configuring commit message validation
- Installing secrets scanners
- Enforcing code quality standards
- Automating pre-push tests
Quick Installation
./AgentUsage/pre_commit_hooks/install_hooks.sh
cp AgentUsage/pre_commit_hooks/commit-msg .git/hooks/
cp AgentUsage/pre_commit_hooks/pre-commit-python .git/hooks/pre-commit
cp AgentUsage/pre_commit_hooks/pre-commit-secrets-scanner .git/hooks/pre-commit-secrets
cp AgentUsage/pre_commit_hooks/pre-push .git/hooks/
chmod +x .git/hooks/*
Available Hooks
Core Hooks (All Projects)
| Hook | Purpose |
|---|
commit-msg | Validates conventional commit format |
pre-commit-secrets-scanner | Prevents leaked API keys/secrets |
Language-Specific
| Hook | Language | Checks |
|---|
pre-commit-python | Python | Black, Ruff |
pre-commit-javascript | JS/TS | Prettier, ESLint, TypeScript |
pre-commit-go | Go | gofmt, go vet |
pre-commit-multi-language | Mixed | Auto-detects and runs appropriate tools |
Automation Hooks
| Hook | Purpose |
|---|
pre-push | Runs tests before push |
post-checkout | Auto-updates dependencies on branch switch |
post-commit | Shows commit summary and TODOs |
Hook Selection by Project
commit-msg + pre-commit-python + pre-commit-secrets-scanner + pre-push
commit-msg + pre-commit-javascript + pre-commit-secrets-scanner + pre-push
commit-msg + pre-commit-go + pre-commit-secrets-scanner + pre-push
commit-msg + pre-commit-multi-language + pre-commit-secrets-scanner + pre-push
What Each Hook Does
commit-msg
Validates commit message format:
feat: Add user authentication
fix: Correct validation error
docs(readme): Update installation
Update files
feat add feature
pre-commit-secrets-scanner
Scans for exposed secrets:
- Anthropic API keys (
sk-ant-...)
- OpenAI API keys (
sk-...)
- AWS credentials (
AKIA...)
- GitHub tokens (
ghp_...)
- Hardcoded passwords
pre-commit-python
uv run black --check $file
uv run ruff check $file
pre-push
uv run pytest tests/
Testing Hooks
.git/hooks/pre-commit
git add .
git commit -m "test: verify hooks"
bash -x .git/hooks/pre-commit
Bypassing Hooks (Emergency Only)
git commit --no-verify -m "Emergency fix"
Troubleshooting
Hook Not Running
ls -l .git/hooks/
chmod +x .git/hooks/*
bash -n .git/hooks/pre-commit
Permission Denied
chmod +x .git/hooks/*
Failed Quality Checks
uv run black --check .
uv run ruff check .
uv run black .
uv run ruff check --fix .
git commit -m "Your message"
Missing Tools
uv add --dev black ruff
which black
uv run black --version
Custom Hook Configuration
Modify pre-commit for Your Project
#!/bin/bash
FILES=$(git diff --cached --name-only --diff-filter=ACM | grep '\.py$')
if [ -n "$FILES" ]; then
uv run black --check $FILES || exit 1
uv run ruff check $FILES || exit 1
fi
exit 0
Hook Execution Order
- pre-commit - Before commit (code quality)
- commit-msg - Validates message format
- post-commit - After commit (notifications)
- pre-push - Before push (tests)
Best Practices
DO ✅
- Install secrets scanner on ALL projects
- Use commit-msg for consistent history
- Run tests in pre-push
- Test hooks after installation
DON'T ❌
- Skip hooks regularly
- Disable secrets scanning
- Ignore hook failures
- Commit without testing hooks first
Related Resources
See AgentUsage/pre_commit_hooks/ for:
setup_guide.md - Complete installation guide
examples.md - Custom hook examples
TROUBLESHOOTING.md - Common issues
- Individual hook scripts for reference