Git Hooks

8 Best Tools for Running Linters and Formatters as Git Hooks in 2026

Compare 8 tools for running linters as git hooks in 2026, from Husky and lint-staged to Lefthook, pre-commit, ESLint, Prettier, Ruff and golangci-lint.

On this page
  1. Key takeaways
  2. What linters as git hooks are for
  3. Quick comparison
  4. The best tools for running linters and formatters as git hooks
  5. How to choose
  6. How we chose
  7. FAQ
  8. Sources

Key takeaways

  • Hook runners and linters are two layers: the runner triggers checks, the linter enforces rules.
  • lint-staged and pre-commit limit work to changed files, which keeps commits fast.
  • Husky fits JavaScript projects, Lefthook spans many languages, pre-commit suits Python teams.
  • ESLint, Prettier, Ruff, and golangci-lint are the engines most hooks call.
  • Keep hooks short and move slow checks to pre-push so developers do not bypass them.

What linters as git hooks are for

Linters as git hooks means wiring style and correctness checks into Git events, usually pre-commit and pre-push. A hook runner fires a command when you commit or push, then the linter or formatter inspects the files you touched. Problems get caught on your machine instead of in review.

This setup fits teams that want consistent formatting and fewer nitpicks in pull requests. It is less useful for solo prototypes, for repos with no shared style rules, or when the checks are slow enough that people start using the no-verify flag to skip them.

Quick comparison

ToolBest forStarting priceFree plan
HuskyJavaScript projects needing simple Git hooksNot includedNot included
lint-stagedRunning tasks only on staged filesNot includedNot included
LefthookMulti-language hook managementNot includedNot included
pre-commitPython-centric hook orchestrationNot includedNot included
ESLintJavaScript and TypeScript lintingNot includedNot included
PrettierOpinionated code formattingNot includedNot included
RuffFast Python linting and formattingNot includedNot included
golangci-lintGo linting across many analyzersNot includedNot included

The best tools for running linters and formatters as git hooks

1. Husky

  • Official site: https://typicode.github.io/husky/
  • Best for: JavaScript projects needing simple Git hooks
  • Starting price: Not included
  • Free plan: Not included
  • Pros: Simple setup through package scripts; works well with lint-staged
  • Cons: Tied to the Node toolchain; limited to hook wiring

Husky is a hook manager for JavaScript projects. You install it in a repo, add a hook file, and Husky runs your command when Git fires that event. Most teams pair it with lint-staged so only staged files get checked. It is small and does one job: making Git hooks easy to install and share across a team.

It fits front-end and Node projects where package.json already drives scripts. Compared with multi-language runners, Husky stays close to npm scripts, which keeps configuration readable. The honest limit is scope: Husky does not lint or format anything itself, so you still need ESLint, Prettier, or another engine behind it.

2. lint-staged

  • Official site: https://github.com/lint-staged/lint-staged
  • Best for: Running tasks only on staged files
  • Starting price: Not included
  • Free plan: Not included
  • Pros: Checks only changed files for speed; configurable per file pattern
  • Cons: Needs a hook runner to trigger it; JavaScript ecosystem focus

lint-staged runs commands against files staged for commit. Instead of linting the whole repo, it passes the changed file list to your tools, so commits stay quick even in large projects. You map glob patterns to commands, which lets you run ESLint on scripts and Prettier on styles in the same hook.

It fits teams that already use Husky or another runner and want faster checks. Its strength is the staged-file filter, which keeps hooks practical as a codebase grows. The limit is that it is a task dispatcher, not a linter, and it assumes a Node environment for its own execution.

3. Lefthook

  • Official site: https://lefthook.dev
  • Best for: Multi-language hook management
  • Starting price: Not included
  • Free plan: Not included
  • Pros: Single binary with parallel task execution; one config for many hook types
  • Cons: Config syntax takes time to learn; another tool to install per machine

Lefthook is a Git hook manager distributed as a standalone binary. You describe hooks in a YAML file, and it runs commands for pre-commit, pre-push, and other events. It can run tasks in parallel and filter by file globs, which helps in repos that mix languages.

It fits polyglot teams that want one runner instead of separate tools per stack. Compared with Husky, Lefthook is language-neutral and does not depend on Node. The tradeoff is a config format you have to learn, and developers need the binary available locally or through a package manager.

4. pre-commit

  • Official site: https://pre-commit.com
  • Best for: Python-centric hook orchestration
  • Starting price: Not included
  • Free plan: Not included
  • Pros: Manages hook environments automatically; large catalog of ready hooks
  • Cons: Python dependency for the framework; hook setup can feel indirect

pre-commit is a framework for managing and running Git hooks, written in Python. You list hooks in a config file, and it installs and runs each one in an isolated environment. It supports hooks for many languages, not just Python, through community-provided definitions.

It fits teams that want reproducible hook environments without manual setup on each machine. Its strength is that hook dependencies are managed for you, so results stay consistent. The limit is that the framework itself needs Python, and debugging a failing hook sometimes means reading through its environment handling.

5. ESLint

  • Official site: https://eslint.org
  • Best for: JavaScript and TypeScript linting
  • Starting price: Not included
  • Free plan: Not included
  • Pros: Pluggable rules and shareable configs; strong editor and CLI integration
  • Cons: Configuration can grow complex; rule choices need team agreement

ESLint is a linter for JavaScript and related languages. It parses your code, applies rules, and reports problems, with support for plugins and shared configurations. In a hook setup, ESLint is usually the command that lint-staged or Husky calls on staged files.

It fits projects that want enforceable style and correctness rules rather than ad hoc review comments. Compared with formatters, ESLint handles logic and pattern checks, not just whitespace. The honest limit is configuration drift: without a shared config, rule sets diverge and hooks produce noisy results.

6. Prettier

  • Official site: https://prettier.io
  • Best for: Opinionated code formatting
  • Starting price: Not included
  • Free plan: Not included
  • Pros: Consistent output with minimal options; supports many languages
  • Cons: Few style choices by design; can conflict with lint rules if uncoordinated

Prettier is a code formatter that rewrites files into a consistent style. It supports JavaScript, TypeScript, CSS, Markdown, and other formats. In hooks, it usually runs with a write flag so staged files are reformatted before the commit lands.

It fits teams that want to end formatting debates and keep diffs clean. Its value is that it makes few decisions for you, which keeps output predictable across editors. The limit is that Prettier and a linter can disagree on style, so teams often disable overlapping lint rules to avoid conflicts.

7. Ruff

  • Official site: https://docs.astral.sh/ruff/
  • Best for: Fast Python linting and formatting
  • Starting price: Not included
  • Free plan: Not included
  • Pros: Combines linting and formatting in one tool; quick to run in hooks
  • Cons: Rule coverage differs from older tools; config migration takes effort

Ruff is a Python linter and formatter. It checks code for errors and style issues and can also reformat files. Because it is quick, it works well as a pre-commit step, either called directly or through a hook framework like pre-commit.

It fits Python teams that want one tool for both linting and formatting instead of stitching several together. Compared with older Python linters, Ruff consolidates common checks in a single binary. The limit is that projects with long-standing rule sets may need to map or adjust configs during migration.

8. golangci-lint

  • Official site: https://golangci-lint.run
  • Best for: Go linting across many analyzers
  • Starting price: Not included
  • Free plan: Not included
  • Pros: Runs many Go analyzers in one pass; configurable rule selection
  • Cons: Slower on large repos; analyzer defaults need tuning

golangci-lint is a Go linter that runs multiple analyzers together and reports combined results. You configure which linters are active and which paths to skip. In a hook setup it typically runs on changed packages, either directly or through a runner.

It fits Go projects that want broad static checks without calling each analyzer separately. Compared with single-purpose linters, it centralizes configuration in one file. The limit is runtime: on big repos it can be slow enough that teams move it to pre-push rather than pre-commit.

How to choose

Start with your stack. JavaScript projects get the least friction from Husky plus lint-staged, while Python teams often prefer pre-commit and Go teams lean on golangci-lint behind a runner.

Then think about scope and speed. Checking only staged files keeps pre-commit fast, and slower whole-repo checks belong in pre-push. If your repo mixes languages, a neutral runner like Lefthook avoids installing a separate hook tool per stack.

Finally, weigh maintenance and lock-in. Hook configs live in the repo, so pick a format your team can read and keep updated. Isolated environments reduce setup drift, while plain package scripts are easier to debug when something fails.

How we chose

These tools were selected from official product pages and documentation, focusing on fit for hook-driven linting and formatting, active maintenance signals, and clear use cases. Each entry describes what the vendor documents in general terms, such as platforms, open source status, and main features. No documentation review was performed, and no benchmark results are reported.

FAQ

Do I need both a hook runner and a linter?

Yes, in most setups. The runner triggers commands on Git events, and the linter or formatter does the actual checking. Some tools combine parts of both roles, but separating them keeps configuration easier to reason about.

Should hooks run on pre-commit or pre-push?

Put fast checks on pre-commit so problems are caught early. Move slow checks, like whole-repo analysis, to pre-push. If a hook takes too long, developers will skip it, which defeats the purpose.

Can I run formatters and linters in the same hook?

Yes. A common pattern is to format staged files first, then lint them, so the linter sees the final content. Take care that formatting rules and lint rules do not contradict each other.

What if a hook fails on files I did not change?

That usually means the hook is checking the whole repo instead of staged files. Filtering by changed files, or scoping commands to specific paths, keeps failures relevant to your commit.

Are Git hooks shared with the whole team?

Only if the hook setup is committed and installed through a tool. Plain hook files in .git/hooks stay local. Runners like Husky, Lefthook, and pre-commit exist to make hook installation repeatable for everyone.

Sources