Lefthook Configuration Patterns
Beginnerv1.0.0
Design lefthook.yml configurations with parallel execution, glob filtering, staged file targeting, and multi-hook orchestration for fast, focused Git hook workflows.
Content
Overview
Lefthook's configuration file (lefthook.yml) defines what runs at each Git hook stage. Well-designed configurations run checks in parallel, target only relevant files, and keep execution under 10 seconds.
How It Works
Basic Configuration
Glob Filtering
Root and Subdirectory Filtering
Scripts Instead of Inline Commands
Conditional Execution
Best Practices
- -Use
parallel: truefor independent checks in the same hook stage - -Use
{staged_files}in pre-commit to check only staged files - -Keep pre-commit under 10 seconds — move slow checks to pre-push
- -Use
globto run tools only on relevant file types - -Use
rootfor monorepo subdirectory scoping - -Skip hooks during merge/rebase to avoid blocking conflict resolution
Common Mistakes
- -Not using
parallel: true(checks run sequentially, twice as slow) - -Checking all files instead of
{staged_files}(lints entire codebase) - -Running tests in pre-commit (too slow, belongs in pre-push)
- -Not using
globfiltering (ESLint runs on .md files, Prettier on .go files)
FAQ
Discussion
Loading comments...