Automated quality checks that run before every commit, catching issues before they reach your repository.
Pre-commit hooks execute automatically:
git commitPre-commit hooks are your first line of defense against:
By running checks before commit, you catch problems early - before they enter your repository, before CI fails, before code review, and before production.
These hooks automatically format your code to match project standards.
These hooks automatically modify files. After running:
git statusgit diffgit add .git commitThese hooks analyze code for errors, style issues, and potential bugs.
Example Error:
shellcheck detected issues in script.sh:
Line 5: rm -rf $USER_DIR/temp
^-------^ SC2086: Quote this to prevent word splitting
Fix: rm -rf "${USER_DIR}/temp"
These hooks prevent committing sensitive information.
If a hook finds secrets:
Example Detection:
detect-secrets....................................................Failed
- hook id: detect-secrets
Potential secret found in config.py:
Line 15: api_key = "sk-1234567890abcdef"
^-------^ Appears to be an API key
Fix: Move to environment variable
api_key = os.environ.get("API_KEY")
These hooks prevent corrupted or problematic files from being committed.
# Clone the Guardrails-AI repository
git clone https://github.com/christopherpaquin/Guardrails-AI .ai-guardrails
# Copy template infrastructure
./. ai-guardrails/template/bootstrap-guardrails.sh
# Run setup script
./scripts/setup-precommit.sh
# Test it works
pre-commit run --all-files
# Install pre-commit
pip install pre-commit
# Copy configuration
cp .ai-guardrails/.pre-commit-config.yaml .
# Install hooks
pre-commit install
pre-commit install --hook-type commit-msg
# Run on all files (first time)
pre-commit run --all-files
Test that pre-commit is working:
# Create a test file with issues
echo "api_key = 'sk-test123'" > test.py
# Try to commit (should fail)
git add test.py
git commit -m "test"
# Expected: detect-secrets hook should block the commit
# List all hooks
./scripts/manage-precommit-hooks.sh list
# Disable expensive hooks during development
./scripts/manage-precommit-hooks.sh disable shellcheck
./scripts/manage-precommit-hooks.sh disable pylint
# Re-enable later
./scripts/manage-precommit-hooks.sh enable shellcheck
# Show hook configuration
./scripts/manage-precommit-hooks.sh show detect-secrets
Edit .pre-commit-config.yaml to customize hooks:
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
# Exclude markdown files
exclude: '\\.md$'
- id: check-added-large-files
# Change size limit to 1MB
args: ['--maxkb=1000']
Not recommended! But if you must:
# Skip all hooks (use with caution!)
git commit --no-verify -m "emergency fix"
# Skip specific hook
SKIP=shellcheck git commit -m "skip shellcheck for this commit"
Install pre-commit hooks in your project and catch issues before they're committed.
Get Started