Monorepo Hook Configuration
Intermediatev1.0.0
Configure Lefthook for monorepo projects with multiple languages and packages — root-scoped commands, per-package hooks, and selective execution based on changed directories.
Content
Overview
Monorepos contain multiple packages, often in different languages. Lefthook's root filtering and glob patterns let you run the right tool for each package — TypeScript linting for the frontend, Python linting for the backend — without checking unrelated files.
How It Works
Package-Scoped Commands
Using lefthook-local.yml for Developer Overrides
Pre-Push with Package-Specific Tests
Best Practices
- -Use
rootto scope commands to specific packages - -Run all package checks in parallel — they are independent
- -Include a shared secrets scan that runs on all files
- -Use
lefthook-local.yml(gitignored) for developer-specific overrides - -Group related commands by package for clarity
- -Only run tests for packages with changed files
Common Mistakes
- -Running all linters on all files (ESLint on Python, Ruff on TypeScript)
- -Not using
rootscoping (commands see files from wrong directory) - -Sequential execution in monorepos (each package check adds latency)
- -Not providing lefthook-local.yml for developer customization
FAQ
Discussion
Loading comments...