This repo is a companion piece to the blog post Why Pre-Commit Hooks Are Essential (Even If You Hate Them At First) on bearblog.
A minimal Python project that demonstrates pre-commit hooks, including a custom hook that uses an LLM to review your changes.
This project uses uv for dependency management.
# Sync dependencies
uv sync
# Install pre-commit hooks (anthropic library will be auto-installed by pre-commit)
uv run pre-commit installA custom pre-commit hook that calls an LLM to look at your staged changes and give a pass/fail score. Lives in hooks/llm_check.py.
Set your API key to enable it:
export ANTHROPIC_API_KEY="your-key-here"If the key is not set the hook will skip gracefully.
The .pre-commit-config.yaml demonstrates several useful patterns:
excludeonend-of-file-fixer- the fixed-width data file indata/must not have a trailing newline addedargsonmixed-line-ending- passes--fix=lfto enforce Unix-style line endingsrepo: local- defines thellm-checkhook as a local script rather than pulling from a remote repo