Lefthook is a high-performance Git hook manager developed on the Go language for projects on Node.js, Ruby, Python, and other technology stacks. You can easily install it with Go tools, NPM, gem, or pipx package managers, then define hook rules in a clean lefthook.yml configuration file and run the lefthook install command to enable them.
This tool supports parallel execution of hook commands, filters specified files through wildcards/regular expressions, is compatible with script execution, tag grouping, Docker container running, and also supports local configuration overrides. These features combine execution speed with flexibility, giving you complete control over your code inspection process.
With Lefthook, you can automate code syntax checks and compliance checks during code commits and pushes, with efficient and no additional dependencies, saving significant development time and effortlessly maintaining the cleanliness of your project code.
In teamwork, Git hooks often have high hopes:
Run formatting before committing, check code style, and block obvious errors.
But the reality is often that the configuration is scattered, the execution is slow, the environment of different members is inconsistent, and finally bypassed or abandoned.
Lefthook was born to solve these problems.
What is Lefthook?
Lefthook is a high-performance Git hook manager developed based on Go language, which is used to unify the management pre-commitand execution logic of Git hooks.pre-push
It doesn’t care what language or framework your project uses, Node.js, Ruby, Python, and even script-only projects can be used directly.
The project is maintained by Evil Martians and has a very engineering-oriented design with clear goals:
Make local code checking fast and reliable.
Why do you need a lefthook?
There are several long-standing problems with native Git hooks:
- hooks are local files and are not subject to version control
- Team member configurations are prone to inconsistencies
- The script is complex, and the execution speed is significantly slower than the commit
- Cross-language projects are difficult to manage in a unified manner
Lefthook’s idea is straightforward:
Treat hooks as part of a project, describe them uniformly in configuration files, and schedule them with high-performance executors.
Overview of core features
High-performance execution (Go implementation)
Lefthook ontology is written in Go and has a very low startup cost.
Compared with scripted solutions, the difference is commit very obvious in frequent scenarios.
Simple, centralized configuration
All hooks are written in one lefthook.yml , for example:
pre-commit:
parallel: true
commands:
lint:
run: npm run lint
test:
run: npm test
The configuration is clear, readable, and reviewable, and goes directly to the Git repository.
Execute in parallel to reduce wait times
Multiple inspections can run in parallel instead of serial blocking.
This is very critical in projects that include lint + test + typecheck.
Accurate document screening capabilities
Support wildcards and regular expressions to trigger checks only for relevant files, such as:
- Only changed
.jsthe file, no Python tests - Only the documentation has been changed, and the build process has not been taken
This makes hooks “smart” rather than “violent”.
Scripts, tags, and Docker are fully supported
Lefthook doesn’t limit how you can run commands:
- Local script
- npm / pip / bundle command
- Docker container
- Tasks are grouped and reused by tags
Complex projects can also be structured clearly.
Local Override
On top of the team’s unified rules, individuals are allowed to make local adjustments.
Taking into account the consistency and the difference in the real environment.
Flexible installation
Lefthook supports multiple installation channels:
- Go toolchain
- npm
- Ruby gem
- pipx
Once installed, all you need to do is:
lefthook install
to enable the hooks configuration in your project.
Github:https://github.com/evilmartians/lefthook
Tubing: