Skip to content

prek: Fast Pre-commit Hook Runner for Python

prek reimplements the pre-commit framework as a standalone binary. It reads existing .pre-commit-config.yaml files and shares supported hook environments between projects.

Key Features

Performance

prek shares toolchains and supported environments, prepares repositories concurrently, and schedules hooks according to priority. The upstream benchmarks distinguish runner overhead from hook execution; results depend on the workload and cache state.

Drop-In Compatibility

prek reads existing .pre-commit-config.yaml files. After adding prek to the project, the installed pre-commit shim can be replaced while keeping the configuration:

uv run prek install -f

Built-In Hooks

prek includes Rust-native implementations of common hooks, available through the repo: builtin configuration option. These hooks require no external toolchain installation.

Monorepo Support

prek provides built-in workspace and monorepo support, allowing multiple .pre-commit-config.yaml files across subprojects within a single repository.

Zero Runtime Dependencies

prek ships as a single binary with no Python or other runtime dependency requirements. It manages Python versions and virtual environments automatically when needed by hooks, integrating with uv for Python dependency handling.

Installation

For a uv-managed project, prek is installed as a development dependency:

uv add --dev prek
uv run prek --version

The --dev flag marks prek as a development dependencyA package needed during development (testing, linting, formatting) that is not shipped to users of your project. Installed with the --dev flag. , keeping it out of production installs. uv run executes the command inside the project’s virtual environment, ensuring all dependencies are installed first. The version command prints the installed prek version.

Persistent installation outside a project is also supported:

# Using uv tools
uv tool install prek

# Using pip or pipx
pip install prek
pipx install prek

# Using Homebrew
brew install prek

# Using Cargo (requires a compatible Rust toolchain)
cargo install --locked prek

# Using Conda
conda install conda-forge::prek

See the official installation guide for additional methods, and the build prerequisites before compiling with Cargo.

Command-Line Interface

Hook commands require a Git repository with a hook configuration. For a project dependency, prefix commands that start with prek with uv run, for example uv run prek run --all-files. Bare prek commands assume a persistent installation on PATH.

# Install git hooks
prek install

# Run all hooks against staged files
prek run

# Run all hooks against all files
prek run --all-files

# Run a configured hook by its ID
prek run ruff-check

# Run hooks against files in a specific directory
prek run --directory src/

# Run hooks against the last commit (requires a parent commit)
prek run --last-commit

# List all available hooks
prek list

# Update hook repositories
prek update

# Clean cached environments
prek cache clean

# Upgrade a project dependency through uv
uv lock --upgrade-package prek

# Self-update only a standalone-installer installation
prek self update

Language Support

prek supports hooks written in the following languages and toolchains:

  • Python
  • Node.js
  • Bun
  • Go
  • Rust
  • Ruby

See the language support documentation for current status.

Pros

  • Supports existing pre-commit YAML configurations
  • Single binary with no runtime dependencies
  • Shares supported toolchains and hook environments
  • Built-in monorepo and workspace support
  • Parallel hook execution

Cons

  • Native TOML configuration and prek-specific features such as built-in hooks are not portable to the original pre-commit runner
  • Hook dependencies still require their own runtimes even though prek itself is a standalone binary
Last updated on