description: Use when setting up or running hooks with prek in any repository. prek is a Rust drop-in alternative to pre-commit for running Git hooks that check, format, lint, and validate code and repository files. Prefer it when speed, workspace mode, built-in hooks, shared toolchains, or native TOML configuration matter. metadata: github-path: skills/prek github-ref: refs/tags/v0.3.13 github-repo: https://github.com/j178/prek github-tree-sha: 63e8d158f48892cd9555eb59bf4045db4c463c2c internal: true
name: prek
prek
Use this skill when the user wants to set up or run Git hooks with prek.
prek is a Rust reimplementation of pre-commit. Its main job is to run hooks that check code and repository files before commit or on demand: formatters, linters, validators, security checks, and custom project checks.
Start with the public docs
Use the LLM-oriented index first:
Per that file, prefer explicit markdown docs when you need details:
- Introduction
- Installation
- Quickstart
- Common Workflows
- Configuration
- Workspace Mode
- Language Support
- Built-in Hooks
- CLI Reference
- Configuration Reference
- Environment Variable Reference
- Differences from pre-commit
- Benchmark
What prek is for
Use prek to:
- run hooks that check source code and repo contents
- install Git hook shims such as
pre-commit,pre-push, andcommit-msg - run the same hook ecosystem used by
pre-commit - manage hook runtimes and toolchains for supported languages
- validate configs, update pinned hook revisions, and inspect configured hooks
Typical jobs for hooks run by prek:
- formatting and linting code
- validating YAML, JSON, TOML, XML, and similar files
- preventing merge-conflict markers, private keys, oversized files, and bad line endings
Authoring configs
For new configs, prefer prek.toml.
Important repo types:
- remote repo: normal hook repository such as
https://github.com/astral-sh/ruff-pre-commit repo = "local": hooks defined in the current repositoryrepo = "meta": config-checking hooks likecheck-hooks-apply,check-useless-excludes, andidentityrepo = "builtin":prek's offline Rust-native hooks
Minimal examples:
[[repos]]
repo = "https://github.com/astral-sh/ruff-pre-commit"
rev = "v0.14.3"
hooks = [
{ id = "ruff" },
{ id = "ruff-format" },
]
[[repos]]
repo = "local"
hooks = [
{
id = "cargo-fmt",
name = "cargo fmt",
language = "system",
entry = "cargo fmt --",
files = "\\.rs$",
},
]
[[repos]]
repo = "builtin"
hooks = [
{ id = "trailing-whitespace" },
{ id = "check-yaml" },
]
These examples use TOML 1.1 multiline inline tables. Use [[repos.hooks]] array-of-tables if an editor or parser in the toolchain does not support that syntax yet, or when a hook has many fields such as env, pass_filenames = false, or priority.
Filtering patterns:
- regex is the most portable choice:
files = "\\.rs$" prekalso supports globs:files = { glob = "src/**/*.rs" }- use glob lists for multiple roots:
exclude = { glob = ["target/**", "dist/**"] }
Scheduling:
- smaller
priorityvalues run earlier - hooks with the same
prioritycan run concurrently priorityis evaluated within one config file, not across workspace projects
Useful prek-specific hook/config fields when editing TOML:
envfor per-hook environment variablespriorityfor hook ordering and concurrencyminimum_prek_versionfor gating newer config featuresorphan = trueto isolate a nested workspace project from parent configs
Default workflow
When adopting prek in a repository:
- Check whether the repo already has
.pre-commit-config.yamlor.pre-commit-config.yml. - If it does, usually keep that config and switch the commands from
pre-committoprek. - If migrating from
pre-commit, reinstall the Git shims withprek install -f. - If it does not, prefer creating
prek.tomlfor a fresh setup. - Install
prek. - Validate the config with
prek validate-config. - Install the Git shims and prepare hook environments with
prek install --prepare-hooks. - Run everything once with
prek run --all-files. - For monorepos, consider nested configs,
.prekignore, andorphan: true.
If the user explicitly wants maximum upstream portability, stay with .pre-commit-config.yaml and avoid prek-only keys.
Install and run
Common install methods:
uv tool install prekbrew install prekmise use prekcargo binstall prekcargo install --locked prek
Command guide
prek install: install Git hook shims into the repo's effective hooks directoryprek prepare-hooks: prepare hook environments without installing Git shimsprek install --prepare-hooks: install shims and prepare environments in one stepprek run: run hooks for the current staged file selectionprek run --all-files: run hooks across the whole repositoryprek run <hook-id>: run only one hookprek list: list discovered hooks and projectsprek validate-config: validateprek.tomlor.pre-commit-config.yamlprek auto-update: update pinned hook revisionsprek util yaml-to-toml: convert an existing YAML config toprek.tomlprek util identify <path>: inspect file tags whentypes,types_or, orexclude_typesdo not match as expected
Useful quality-of-life commands and options mentioned in the docs:
prek run --dry-runprek run --directory <dir>prek run --last-commitprek run --skip <hook-or-project>prek -C <dir> ...
For debugging:
prek run -vvvPREK_NO_FAST_PATH=1 prek run: compare builtin fast-path behavior against the standard execution path- Check the Environment Variable Reference for
PREK_*controls such asPREK_HOME,PREK_SKIP, and concurrency limits.
Built-in hook guidance
prek has two important builtin paths:
- automatic fast path for supported hooks from
https://github.com/pre-commit/pre-commit-hooks - explicit
repo: builtinfor offline, zero-setup built-in hooks
Reach for repo: builtin when speed, no-network setup, or minimal bootstrapping matters more than upstream pre-commit compatibility.
Builtin hooks called out by the docs include:
trailing-whitespacecheck-added-large-filescheck-case-conflictcheck-illegal-windows-namesend-of-file-fixerfile-contents-sorterfix-byte-order-markercheck-jsoncheck-json5pretty-format-jsoncheck-tomlcheck-vcs-permalinkscheck-yamlcheck-xmlmixed-line-endingcheck-symlinksdestroyed-symlinkscheck-merge-conflictdetect-private-keyno-commit-to-branchcheck-shebang-scripts-are-executablecheck-executables-have-shebangs
Practical guidance for agents
- Prefer
prek.tomlfor new setups. - Prefer existing
.pre-commit-config.yamlfor migrations unless the user asks for TOML. - Reach for workspace mode in monorepos instead of forcing one giant root-only config.
- Consider
repo: builtinwhen offline or zero-setup hooks are useful. - If the repo already uses
pre-commit-hooks, remember thatprekcan use built-in Rust implementations for some common hooks. - Start with a small default hook set, then add language-specific hooks the project already uses.
- Use
prek util yaml-to-tomlinstead of hand-converting YAML when migrating. - Before promising parity for a specific hook language, verify it in Language Support.