Difference from pre-commit¶
General differences¶
preksupports both.pre-commit-config.yamland.pre-commit-config.ymlconfiguration files.prekimplements some common hooks frompre-commit-hooksin Rust for better performance.prekuses~/.cache/prekas the default cache directory for repos, environments and toolchains.prekdecoupled hook environment from their repositories, allowing shared toolchains and environments across hooks.preksupportslanguage_versionas a semver specifier and automatically installs the required toolchains.
Workspace mode¶
prek supports workspace mode, allowing you to run hooks for multiple projects in a single command. Each subproject can have its own .pre-commit-config.yaml file.
See Workspace Mode for more information.
Language support¶
Python¶
Dependency Management with uv¶
prek uses uv for creating virtual environments and installing dependencies:
- First tries to find
uvin the system PATH - If not found, automatically installs
uvfrom the best available source (GitHub releases, PyPI, or mirrors) - Automatically installs the required Python version if it's not already available
PEP 723 Inline Script Metadata Support¶
For Python hooks without additional_dependencies, prek can read PEP 723 inline metadata from the script specified in the entry field.
Example:
.pre-commit-config.yaml:
echo.py:
# /// script
# requires-python = ">=3.13"
# dependencies = [
# "pyecho-cli",
# ]
# ///
from pyecho import main
main()
Important Notes:
- The first part of the
entryfield must be a path to a local Python script - If
additional_dependenciesis specified in.pre-commit-config.yaml, script metadata will be ignored - When both
language_version(in config) andrequires-python(in script) are set,language_versiontakes precedence - Only
dependenciesandrequires-pythonfields are supported; other metadata liketool.uvis ignored
Command line interface¶
prek run¶
prek run [HOOK|PROJECT]...supports selecting or skipping multiple projects or hooks in workspace mode. See Running Specific Hooks or Projects for details.prekprovides dynamic completions of hook id.prek run --last-committo run hooks on files changed by the last commit.prek run --directory <DIR>to run hooks on a specified directory.
prek list¶
prek list command lists all available hooks, their ids, and descriptions. This provides a better overview of the configured hooks.
prek auto-update¶
prek auto-updateupdates all projects in the workspace to their latest revisions.prek auto-updatechecks updates for the same repository only once, speeding up the process in workspace mode.prek auto-updatesupports--dry-runoption to preview the updates without applying them.
prek sample-config¶
prek sample-configcommand has a--fileoption to write the sample configuration to a specific file.
prek cache¶
prek cache cleanto remove all cached data.prek cache gcto remove unused cached repositories, environments and toolchains.prek cache dirto show the cache directory.
prek clean and prek gc are also available but hidden, as prek cache is preferred.