prek is a high-performance, ultra-fast Git hook manager written in Rust.
It serves as a drop-in, dependency-free replacement for the standard Python pre-commit framework.
By utilizing Rust's concurrency, sharing toolchains globally, and integrating with uv for environment management,
prek drastically reduces installation times and cache footprints while natively interpreting your
.pre-commit-config.yaml files.
You can install prek using any of the following methods:
The most direct way to install prek is via Homebrew:
brew install prekIf you use uv, you can install it as a standalone tool:
uv tool install prekFor an isolated Python-based binary environment installation:
pipx install prekYou can download pre-compiled execution assets directly from the prek GitHub Releases page.
pip install prekManage your Git lifestyle checks using these essential commands:
- Install Hooks: Sets up the necessary Git hooks infrastructure inside your local workspace. Ensure you run this command directly from the root of your repository:
prek install - Run Hooks on Staged Files: Automatically checks files currently staged in your index before committing.
prek run - Run Hooks on All Files: Evaluates the full repository layout—ideal for initial setups or CI pipelines.
prek run --all-files - Run a Specific Hook: Execute only one hook directly by appending its explicit identifier.
prek run <hook_id> --all-files - Uninstall Hooks: Safely unregisters and removes the hooks path settings from your local Git workspace.
prek uninstall
prek optimizes how your pipeline resolves rules by establishing a clear hierarchy:
- CLI Runtime Flags: Command arguments provided explicitly (like
--filesor--directory) instantly override underlying configuration rules. - Built-in Native Overrides:
prekreplaces common, resource-heavy Python hooks (liketrailing-whitespace) with native Rust implementations. These run instantly with zero overhead, taking priority over traditional process invocation. - Workspace-Aware Scheduling: In complex monorepos,
prekdynamically discovers multi-project folders. Independent folders at identical file depths are processed concurrently to finish tasks faster without overlapping file scopes. - Strict File Extension Rules: To keep validations accurate, file type discovery uses exact suffix matches. For instance, a file named
sample.pdf.txtevaluates strictly as a text asset rather than tripping binary filters.
- Arrange Modifiers First: Position hooks that actively alter files (such as code formatters and whitespace trimmers) above validation linters in your
.pre-commit-config.yaml. This ensures checks validate finished formatting. - **Leverage
--dry-run**: Test pattern match filters or complex configuration additions cleanly withprek run --dry-runto trace file targeting without executing changes. - Cooling-off Periods for Safety: Run
prek update --cooldown-days 7to avoid downloading breaking changes instantly, keeping newly published upstream dependencies on hold for a week. - CI Build Verification: In automated jobs, run
prek update --checkto flag mismatching pins or frozen tags instantly without altering workspace configurations during execution.