Lefthook

2.1.6 · active · verified Thu Apr 16

Lefthook is a fast, powerful, and simple Git hooks manager. Written in Go, it streamlines development workflows by automating tasks like linting and testing during Git operations. It is actively maintained with frequent releases, currently at version 2.1.6, often seeing updates on a monthly or bi-monthly cadence.

Common errors

Warnings

Install

Quickstart

After installing, create a `lefthook.yml` file in your project root to define hooks. Then, run `lefthook install` to set up the Git hooks. The provided `lefthook.yml` snippet demonstrates a `pre-commit` hook that runs `flake8` for linting and `black` for formatting on staged Python files, automatically staging `black`'s fixes. Lefthook runs commands in parallel by default, improving efficiency.

#!/bin/bash
# .github/workflows/verify-hooks.yml (example for CI)

# Install lefthook (e.g., in CI or dev setup)
pip install lefthook

# Initialize lefthook configuration
lefthook install

# Example lefthook.yml content (create this file in your project root)
# pre-commit:
#   parallel: true
#   commands:
#     lint:
#       glob: "*.py"
#       run: flake8 {staged_files}
#     format:
#       glob: "*.py"
#       run: black {staged_files}
#       stage_fixed: true

# To run hooks manually (e.g., for testing):
# lefthook run pre-commit

view raw JSON →