コンテンツへスキップ
LatchkeyLatchkey home

Lefthook vs pre-commit: Hookマネージャの比較

Lefthookはhooksを並列実行する高速な単一のGoバイナリです。pre-commitは、すぐに使えるhooksの大きなレジストリを持つPythonフレームワークです。

LefthookはhooksをYAMLで設定し並列実行し、依存関係のない単一バイナリとして配布されるため、高速で言語非依存です。Pythonで書かれたpre-commitは、隔離されたhook環境を管理し、バージョンで固定された共有可能なhooksの巨大なエコシステムを提供します。これはリポジトリ間でチェックを標準化するのに優れています。Lefthookは速度とシンプルさを、pre-commitは豊かで再現可能なhookカタログを優先します。

Lefthookpre-commit
ランタイム単一のGoバイナリPythonフレームワーク
hookエコシステムコマンドを自分で定義大きな共有レジストリ
並列性組み込み限定的
環境の隔離なしhookごとの環境
最適な用途速度、シンプルさ共有・固定されたhooks

CIでの利用

pre-commitは、多くのリポジトリで再利用される、キュレーションされバージョン固定されたコミュニティのhooksが欲しいときに輝き、クリーンなCIモードを備えています。Lefthookはより高速で依存関係がなく、主に自分のコマンドを実行し並列性が欲しいときに理想的です。ローカルのhookを超えてチェックが強制されるよう、どちらもCIでも実行すべきです。

高速化する

hook環境(pre-commit)または依存関係をキャッシュして、CIのチェックがウォームな状態で始まるようにします。チェックはランナー上で実行され、より高速なマネージドランナーはhookとlintの実行を短縮します。

Benchmark on your repository before choosing

Build-tool benchmarks published by vendors use repositories chosen to show a difference. Yours is the only one that matters, and both a cold and a warm measurement are needed because CI mostly runs cold.

Terminal
# cold: no cache, the CI condition
rm -rf node_modules/.cache dist && time <tool> build

# warm: the local development condition
time <tool> build

# and the one people forget: incremental after a one-line change
echo "// touch" >> src/index.ts && time <tool> build

結論

リポジトリ間で標準化された、共有可能でバージョン固定されたhooksの大きなレジストリが欲しい場合: pre-commit。自分のコマンドを並列で実行する高速で依存関係のないバイナリが欲しい場合: Lefthook。共有hookカタログを重視するチームはpre-commitに、速度重視のチームはLefthookに傾きます。

よくある質問

Lefthook vs pre-commit: Hook Managers Compared?
Lefthook configures hooks in YAML, runs them in parallel, and ships as one dependency-free binary, making it quick and language-agnostic. pre-commit, written in Python, manages isolated hook environments and offers a huge ecosystem of shareable hooks pinned by version, which is excellent for standardizing checks across repos.
In CI?
pre-commit shines when you want a curated, version-pinned set of community hooks reused across many repos, and it has a clean CI mode. Lefthook is faster and dependency-free, ideal when you mostly run your own commands and want parallelism. Both should also run in CI so checks are enforced beyond local hooks.
Speed it up?
Cache the hook environments (pre-commit) or dependencies so CI checks start warm. The checks run on runners; faster managed runners shorten hook and lint execution.
Which should I choose?
Wanting a large registry of shareable, version-pinned hooks standardized across repos: pre-commit. Wanting a fast, dependency-free binary running your own commands in parallel: Lefthook. Teams that value a shared hook catalog lean pre-commit; speed-focused ones lean Lefthook.

関連ガイド