This section documents version-specific API changes — prioritize recent major/minor releases.
-
Configure refetch_frequency for remotes with mutable references to ensure up-to-date configurations, using a frequency appropriate for the project, rather than relying on never or not setting it. source
-
Avoid setting both follow: true and parallel: true for commands or hooks, as this can lead to messy and unreadable output. source
-
When a command or script requires user interaction, explicitly set interactive: true to ensure Lefthook connects to the TTY and forwards stdin/stdout, enabling proper user input. source
-
When a command or script needs to read data from stdin (e.g., from Git for pre-push hooks), explicitly set use_stdin: true to ensure the data is correctly piped. source
-
Utilize lefthook-local.yml for local-only overrides and extensions of your main lefthook.yml configuration, and add it to .gitignore to prevent committing local-specific changes. source
-
For monorepos with multiple independent projects, centralize hook configurations in the root lefthook.yml by extending project-specific lefthook.yml files, and use the root option within jobs or groups to define the working directory for project-specific commands. source
-
To ensure a Git commit fails if any individual command within a parallel execution fails, organize your commands into jobs within a group. The group will collectively fail if any of its jobs do, preventing the commit. source
-
To execute platform-specific scripts, use the only option within a job, conditionally running a simple command (e.g., uname for Unix-like systems or cmd /c ver for Windows) to detect the operating system and then run the appropriate script. source
-
To ensure a hook fails if files are modified during its execution, especially when using auto-fixing linters, configure fail_on_changes: ci for CI environments to enforce clean states while maintaining a smoother local developer experience, and use a grouped job with git diff --exit-code after all other potential file-modifying jobs for local checks. source and source
-
To prevent Lefthook from automatically installing or synchronizing Git hooks (e.g., in CI environments or for developers who prefer manual control), set no_auto_install: true in your lefthook.yml. source
-
When using the lefthook NPM package in a CI environment, ensure CI=true is set during package installation (npm install, yarn install, pnpm install) to prevent automatic installation of Git hooks via postinstall scripts, unless you specifically intend to override this behavior with LEFTHOOK=true. source
-
To mitigate slow startup times in projects utilizing Git LFS, especially if LFS hooks are not critical for your specific lefthook configuration, consider setting skip_lfs: true in your lefthook.yml. source and source
-
To reduce redundancy in command definitions and facilitate local overrides, utilize the templates configuration option. Define reusable command snippets or wrappers that can be referenced in run values, allowing for cleaner configurations and easy customization via lefthook-local.yml. source
-
When defining scripts within Lefthook, explicitly specify a runner for each script. This ensures the script is executed correctly with the appropriate interpreter or command (e.g., node for JavaScript, go run for Go), providing clarity and preventing execution issues. source