This project uses lefthook for git hooks to ensure code quality and security.
The hooks automatically run on commit and provide fast feedback:
- ruff - Python linting with auto-fix
- ruff-format - Code formatting
- mypy - Type checking
- trufflehog - Secret scanning to prevent committed credentials
- commitizen - Commit message validation
- actionlint - GitHub Actions workflow validation (if installed)
Git hooks are automatically installed when you run:
uv run lefthook installThis should be done as part of the initial development setup. See CONTRIBUTING.md for full setup instructions.
You can run all pre-commit hooks manually without making a commit:
uv run lefthook run pre-commitTrufflehog scans your commits for secrets and API keys before they're pushed to the repository.
macOS:
brew install trufflehogLinux:
curl -sSfL https://raw.githubusercontent.com/trufflesecurity/trufflehog/main/scripts/install.sh | sh -s -- -b /usr/local/bin# Quick scan: commits since HEAD (excludes uv.lock to avoid false positives)
trufflehog git file://. --since-commit HEAD --exclude-globs=uv.lock
# Full two-pass scan (recommended for comprehensive checking):
# Pass 1: Scan everything except uv.lock
trufflehog git file://. --exclude-globs=uv.lock
# Pass 2: Scan uv.lock only, excluding SentryToken detector
trufflehog git file://. --include-paths=.github/trufflehog-include-lockfile.txt --exclude-detectors=SentryTokenWe use a defense-in-depth approach with two separate scans:
- Pass 1: Scans all files except
uv.lockwith all detectors enabled - Pass 2: Scans ONLY
uv.lockwith SentryToken detector disabled
This prevents false positives from Sentry SDK package hashes while still catching any real secrets that might somehow end up in lock files (e.g., credentials in package URLs).
Secret scanning prevents:
- Accidentally committing API keys
- Exposing authentication tokens
- Leaking database credentials
- Publishing private keys
- Committing sensitive configuration
If trufflehog finds a potential secret, it will:
- Block the commit
- Show you what was detected
- Give you a chance to remove it before it enters git history
Actionlint validates GitHub Actions workflow files to catch errors before you push.
macOS:
brew install actionlintLinux/macOS (direct download):
curl -sSfL https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash | bashGo install:
go install github.com/rhysd/actionlint/cmd/actionlint@latest- Syntax errors in workflow files
- Invalid action references
- Type errors in expressions
- Invalid step configurations
- Deprecated GitHub Actions features
In rare cases, you may need to bypass hooks. Use with caution:
# Bypass all hooks
LEFTHOOK=0 git commit -m "your message"
# Or use git's built-in flag
git commit --no-verify -m "your message"Warning: Bypassing hooks skips:
- Secret scanning (security risk)
- Commit message validation (breaks CI)
- Code formatting (creates inconsistencies)
- Type checking (may introduce bugs)
Only bypass hooks if you have a specific reason and understand the implications.
The hook configuration is defined in lefthook.yml at the project root. This file specifies:
- Which hooks to run
- When they run (pre-commit, commit-msg, pre-push, etc.)
- Commands to execute
- File patterns to target
If hooks aren't running:
# Reinstall hooks
uv run lefthook install
# Verify installation
uv run lefthook versionIf a hook fails:
- Read the error message - It will tell you what failed
- Fix the issue - Apply the suggested fix
- Test manually - Run the failing command directly
- Try again - Make a new commit
If hooks are slow:
- Trufflehog scans can take time on large repos
- First-time mypy checks are slower (subsequent runs use cache)
- Consider running specific tools manually during development
If trufflehog detects a false positive:
- Verify it's actually not a secret
- Check if it's a test fixture or example
- If legitimate, add to exclusion patterns in
lefthook.yml
- Don't bypass hooks unless absolutely necessary
- Run hooks manually (
uv run lefthook run pre-commit) before committing large changes - Keep hooks fast by committing smaller, focused changes
- Update tools regularly to get the latest security checks
- Report issues if a hook gives incorrect results