A Git hooks manager for Node.js, Ruby, Python and many other types of projects, written in Go for speed and cross-platform compatibility.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Lefthook's hook execution engine provides powerful capabilities for running Git hooks with parallel execution, file filtering, and comprehensive error handling.
Execute multiple commands concurrently to improve performance:
pre-commit:
parallel: true # Enable parallel execution
commands:
lint:
run: eslint {staged_files}
test:
run: npm test
format:
run: prettier --write {staged_files}Execute commands one after another (default behavior):
pre-commit:
parallel: false # Sequential execution (default)
commands:
build:
run: npm run build
test:
run: npm test # Runs after build completesChain command outputs together:
pre-commit:
piped: true # Enable piped execution
commands:
generate:
run: generate-data
process:
run: process-data # Receives output from generate-dataProcess only Git staged files (default for pre-commit):
pre-commit:
commands:
lint:
glob: "*.js"
run: eslint {staged_files} # Only staged JS filesProcess all repository files:
# Via command line
lefthook run pre-commit --all-files
# Via configuration
pre-commit:
commands:
full-lint:
run: eslint {all_files}Use Git commands to select specific files:
pre-push:
commands:
test-changed:
files: git diff --name-only HEAD @{push}
glob: "*.js"
run: jest {files}# Single file type
glob: "*.js"
# Multiple file types
glob: "*.{js,ts,jsx,tsx}"
# Directory-specific
glob: "src/**/*.js"
# Complex patterns
glob: "{src,test}/**/*.{js,ts}"commands:
lint:
glob: "*.js"
exclude: "(test|spec)\.js$" # Regex pattern to exclude test files
run: eslint {files}# Available file templates
{files} # Files matched by glob after filtering
{staged_files} # All staged files (unfiltered)
{push_files} # Files being pushed
{all_files} # All repository filesControl execution order with priority values:
pre-commit:
commands:
format:
priority: 1 # Runs first
run: prettier --write {staged_files}
stage_fixed: true
lint:
priority: 2 # Runs second
run: eslint {staged_files}
test:
priority: 3 # Runs last
run: npm test# Skip during merge conflicts
skip: merge
# Skip during rebase
skip: rebase
# Only run during merge
only: merge
# Multiple conditions
skip: [merge, rebase]
only: [merge, rebase]pre-commit:
exclude_tags: [slow] # Exclude commands tagged as 'slow'
commands:
quick-lint:
tags: [fast, required]
run: quick-linter
slow-test:
tags: [slow]
run: comprehensive-test-suiteAllow commands to interact with user input:
pre-push:
commands:
confirm-deploy:
interactive: true
run: ./scripts/confirm-deployment.shProvide stdin to commands:
commit-msg:
commands:
validate-message:
use_stdin: true
run: ./scripts/validate-commit-msg.shAutomatically stage files modified by commands:
pre-commit:
commands:
format:
run: prettier --write {staged_files}
stage_fixed: true # Stage files after formatting
lint:
run: eslint --fix {staged_files}
stage_fixed: true # Stage files after lintingProvide helpful error messages:
pre-commit:
commands:
dependencies:
run: npm ci
fail_text: "Dependencies failed to install. Run 'npm install' to fix."
test:
run: npm test
fail_text: "Tests failed. Fix failing tests before committing."pre-commit:
follow: true # Continue execution even if commands fail
commands:
lint:
run: eslint {staged_files}
test:
run: npm test # Runs even if lint fails when follow: truepre-commit:
commands:
test:
env:
NODE_ENV: test
CI: true
DATABASE_URL: test-db-url
run: npm testpre-commit:
commands:
frontend-lint:
root: ./frontend # Change to frontend directory
run: npm run lint
backend-test:
root: ./backend # Change to backend directory
run: go test ./...Execute custom scripts with specific interpreters:
pre-commit:
scripts:
bash-script:
runner: bash
# Executes ./lefthook/pre-commit/bash-script
node-script:
runner: node
env:
NODE_ENV: development
# Executes ./lefthook/pre-commit/node-script
python-script:
runner: python
# Executes ./lefthook/pre-commit/python-script.lefthook/
├── pre-commit/
│ ├── bash-script # Bash script
│ ├── node-script.js # Node.js script
│ └── python-script.py # Python script
├── pre-push/
│ └── deployment-check.sh
└── commit-msg/
└── validate-format.rbpre-commit:
parallel: true # Enable parallel execution
commands:
# These run concurrently
lint: { run: "eslint {staged_files}" }
test: { run: "npm test" }
format: { run: "prettier --write {staged_files}" }pre-commit:
commands:
# Only process relevant files
js-lint:
glob: "*.{js,ts}" # Pre-filter files
run: eslint {staged_files}
# Use exclude for better performance
all-lint:
glob: "*"
exclude: "node_modules|dist|build" # Exclude large directories
run: generic-linter {files}# Enable verbose logging
lefthook run pre-commit --verbose
# Show execution details, timing, and file processingLefthook provides execution summaries showing:
# Control output verbosity
output:
- meta # Show metadata (default)
- success # Show success messages
- failure # Show failure messages (default)
- summary # Show execution summary (default)
- skips # Show skipped commands