docs/builtin.md
prek includes fast, Rust-native implementations of popular hooks for speed and low overhead. These hooks are bundled directly into the prek binary, eliminating the need for external interpreters like Python for these specific checks.
Built-in hooks come into play in two ways:
repo: builtin for offline, zero-setup hooks.When you use a standard configuration pointing to a supported repository (like https://github.com/pre-commit/pre-commit-hooks), prek automatically detects this and runs its internal Rust implementation instead of the Python version defined in the repository.
The fast path is activated when the repo URL matches https://github.com/pre-commit/pre-commit-hooks. No need to change anything in your configuration.
Note that the rev field is ignored for detection purposes.
This provides a speed boost while keeping your configuration compatible with the original pre-commit tool.
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks # Enables fast path
rev: v4.5.0 # This is ignored for fast path detection
hooks:
- id: trailing-whitespace
!!! note
In this mode, `prek` will still clone the repository and create the environment (e.g., a Python venv) to ensure full compatibility and fallback capabilities. However, the actual hook execution bypasses the environment and runs the native Rust code.
Currently, only part of hooks from https://github.com/pre-commit/pre-commit-hooks is supported. More popular repositories may be added over time.
trailing-whitespace (Trims trailing whitespace.)check-added-large-files (Prevents giant files from being committed.)check-case-conflict (Checks for files that would conflict in case-insensitive filesystems.)check-illegal-windows-names (Checks for filenames which cannot be created on Windows.)end-of-file-fixer (Ensures that a file is either empty, or ends with one newline.)file-contents-sorter (Sorts the lines in specified files (defaults to alphabetical).)requirements-txt-fixer (Sorts entries in requirements.txt.)fix-byte-order-marker (Removes UTF-8 byte order marker.)forbid-new-submodules (Prevents the addition of new Git submodules.)check-json (Checks JSON files for parseable syntax.)check-toml (Checks TOML files for parseable syntax.)check-vcs-permalinks (Ensures that links to VCS websites are permalinks.)check-yaml (Checks YAML files for parseable syntax.)check-xml (Checks XML files for parseable syntax.)mixed-line-ending (Replaces or checks mixed line endings.)check-symlinks (Checks for symlinks which do not point to anything.)destroyed-symlinks (Detects symlinks that were replaced with regular files whose contents are the original symlink target path.)check-merge-conflict (Checks for files that contain merge conflict strings.)detect-private-key (Detects the presence of private keys.)no-commit-to-branch (Protects specific branches from direct commits.)check-shebang-scripts-are-executable (Ensures that (non-binary) files with a shebang are executable.)check-executables-have-shebangs (Ensures that (non-binary) executables have a shebang.)check-yaml fast path does not yet support the --unsafe flag; for those cases, the automatic fast path is skipped.pretty-format-json is currently available only via repo: builtin while parity coverage against upstream Python behavior is still being expanded.If you need to compare with the original behavior or encounter differences:
PREK_NO_FAST_PATH=1 prek run
This forces prek to fall back to the standard execution path.
You can explicitly tell prek to use its internal hooks by setting repo: builtin.
This mode has significant benefits:
Note: Configurations using repo: builtin are not compatible with the standard pre-commit tool.
repos:
- repo: builtin
hooks:
- id: trailing-whitespace
- id: check-added-large-files
For repo: builtin, the following hooks are supported:
trailing-whitespace (Trims trailing whitespace.)check-added-large-files (Prevents giant files from being committed.)check-case-conflict (Checks for files that would conflict in case-insensitive filesystems.)check-illegal-windows-names (Checks for filenames which cannot be created on Windows.)end-of-file-fixer (Ensures that a file is either empty, or ends with one newline.)file-contents-sorter (Sorts the lines in specified files (defaults to alphabetical).)requirements-txt-fixer (Sorts entries in requirements.txt.)fix-byte-order-marker (Removes UTF-8 byte order marker.)forbid-new-submodules (Prevents the addition of new Git submodules.)check-json (Checks JSON files for parseable syntax.)check-json5 (Checks JSON5 files for parseable syntax.)pretty-format-json (Checks that JSON files are pretty-formatted.)check-toml (Checks TOML files for parseable syntax.)check-vcs-permalinks (Ensures that links to VCS websites are permalinks.)check-yaml (Checks YAML files for parseable syntax.)check-xml (Checks XML files for parseable syntax.)deny-pattern (Fails if any file contains a matching regular expression.)require-pattern (Fails if any file does not contain a matching regular expression.)mixed-line-ending (Replaces or checks mixed line endings.)check-symlinks (Checks for symlinks which do not point to anything.)destroyed-symlinks (Detects symlinks that were replaced with regular files whose contents are the original symlink target path.)check-merge-conflict (Checks for files that contain merge conflict strings.)detect-private-key (Detects the presence of private keys.)no-commit-to-branch (Protects specific branches from direct commits.)check-shebang-scripts-are-executable (Ensures that (non-binary) files with a shebang are executable.)check-executables-have-shebangs (Ensures that (non-binary) executables have a shebang.)This section documents the built-in (Rust) implementations used by repo: builtin.
args: [...] just like pre-commit.repo: builtin, entry is not allowed and language must be system (it is fine to omit language).pre-commit-hooks, they typically exit non-zero after making changes so you can re-run the commit.Example:
repos:
- repo: builtin
hooks:
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
- id: check-added-large-files
args: [--maxkb=1024]
trailing-whitespaceTrims trailing whitespace from each line.
Supported arguments (compatible with pre-commit-hooks):
--markdown-linebreak-ext=<ext> (repeatable / comma-separated)
--markdown-linebreak-ext=* to treat all files as Markdown.--chars=<chars>
args: [--chars, " \t"] (space + tab).Caveats
--markdown-linebreak-ext values must be extensions only (no path separators).check-added-large-filesPrevents giant files from being committed.
Supported arguments (compatible with pre-commit-hooks):
--maxkb=<N> (default: 500)
--enforce-all
Caveats
filter=lfs (via git attributes) are skipped.check-case-conflictChecks for paths that would conflict on a case-insensitive filesystem (for example macOS / Windows).
Supported arguments
Caveats
check-illegal-windows-namesChecks for filenames that cannot be created on Windows.
Supported arguments
Behavior / caveats
CON, PRN, AUX, NUL, COM1, and LPT1.<, >, :, ", \, |, ?, *, and control characters.. or space.end-of-file-fixerEnsures files end in a newline and only a newline.
Supported arguments
Behavior / caveats
\n is appended (even if the file otherwise uses CRLF).file-contents-sorterSorts the non-empty lines in each matched file and rewrites the file when the normalized order changes.
Supported arguments (compatible with pre-commit-hooks):
--ignore-case
--unique.--unique
--ignore-case.Behavior / caveats
\n in the rewritten file.files: '^$', so you must configure files: explicitly to target specific files.Example:
repos:
- repo: builtin
hooks:
- id: file-contents-sorter
files: ^requirements(-dev)?\.txt$
requirements-txt-fixerSorts entries in Python requirements*.txt and constraints*.txt files by their case-insensitive requirement name.
Behavior / caveats
(requirements|constraints).*\.txt$.pkg-resources==0.0.0 and pkg_resources==0.0.0 entries are removed, matching upstream.pre-commit-hooks.fix-byte-order-markerRemoves a UTF-8 byte order marker (BOM) from the beginning of a file.
Supported arguments
Caveats
EF BB BF).forbid-new-submodulesPrevents the addition of new Git submodules.
Supported arguments
Behavior / caveats
PRE_COMMIT_FROM_REF and PRE_COMMIT_TO_REF are both set, their revision range is checked instead.check-jsonAttempts to load all JSON files to verify syntax.
Supported arguments
Caveats / differences
duplicate key ...).check-json5Attempts to load all JSON5 files to verify syntax.
Supported arguments
Caveats / differences
duplicate key ...).pretty-format-jsonChecks that JSON files are pretty-formatted and can optionally rewrite them in place.
Supported arguments (compatible with pre-commit-hooks):
--autofix
--indent=<indent> (default: 2)
<indent> for each indentation level.--indent=\t uses tabs.--no-ensure-ascii
\uXXXX.--no-sort-keys
--top-keys=<k1,k2,...>
--no-sort-keys is set.Caveats
repo: builtin; automatic fast-path replacement of the upstream Python hook remains disabled until parity coverage is broader.\n) line endings and end with exactly one trailing newline.check-tomlAttempts to load all TOML files to verify syntax.
Supported arguments
Caveats
check-vcs-permalinksEnsures that links to VCS websites are permalinks.
Supported arguments (compatible with pre-commit-hooks):
--additional-github-domain=<domain> (repeatable)
github.com.Behavior / caveats
https://<domain>/<owner>/<repo>/blob/<branch>/...#L....<branch> is already a 4-64 character hexadecimal revision.check-yamlAttempts to load all YAML files to verify syntax.
Supported arguments (partially compatible with pre-commit-hooks):
-m, --allow-multiple-documents (alias: --multi)
---).Caveats / differences
--unsafe is not supported.
repo: builtin, passing --unsafe is treated as an unknown argument.check-xmlAttempts to load all XML files to verify syntax.
Supported arguments
Caveats
deny-patternFails when any selected text file matches a configured regular expression.
Patterns use the Rust regex syntax.
When multiple patterns are provided, matching any one of them is sufficient.
Supported arguments
PATTERN... (required)
-- before a pattern that begins with -.-i, --ignore-case
-m, --multiline
^ and $ matching line boundaries and . matching newlines.By default, each matching line is reported as path:line:contents. A line matching more than one pattern is reported only once. With --multiline, the earliest match in each file is reported as path:start-line:matched-block.
repos:
- repo: builtin
hooks:
- id: deny-pattern
name: disallow wildcard imports
args: ['^\s*#import\s+.+:\s*\*']
files: \.typ$
require-patternFails when any selected text file does not match at least one configured regular expression. This is a per-file requirement: every file must match, while different files may match different patterns.
require-pattern supports the same positional PATTERN..., -i / --ignore-case, and --multiline arguments as deny-pattern. Files without a match are reported as path: no pattern matched.
repos:
- repo: builtin
hooks:
- id: require-pattern
name: require a copyright notice
args: [--ignore-case, copyright]
files: '\.(rs|py)$'
mixed-line-endingReplaces or checks mixed line endings.
Supported arguments (compatible with pre-commit-hooks, plus one extra mode):
--fix=<mode> (default: auto)
auto: replace with the most frequent line ending in the file.no: check only (do not modify files).lf: convert to LF (\n).crlf: convert to CRLF (\r\n).cr: convert to CR (\r) (extra mode in prek).Caveats
lf / crlf may not behave as expected with git CRLF conversion settings (for example core.autocrlf).check-symlinksChecks for symlinks which do not point to anything.
Supported arguments
Caveats
destroyed-symlinksDetects files staged as regular files whose HEAD version is a symlink, which usually happens when a repository is checked out in an environment without symlink support.
Supported arguments
Caveats
pre-commit-hooks behavior: it only checks tracked entries reported by git status --porcelain=v2.check-merge-conflictChecks for merge conflict markers.
Supported arguments (compatible with pre-commit-hooks):
--assume-in-merge
Caveats
<<<<<<<, =======, >>>>>>>) and diff3 ancestor markers (|||||||).======= is only reported after a preceding <<<<<<<, which avoids false positives for content such as reStructuredText headings.detect-private-keyDetects the presence of private keys.
Supported arguments
Caveats
BEGIN RSA PRIVATE KEY, BEGIN OPENSSH PRIVATE KEY, BEGIN PGP PRIVATE KEY BLOCK, etc.).
It can produce false positives/negatives.no-commit-to-branchProtects specific branches from direct commits.
Supported arguments (compatible with pre-commit-hooks):
-b, --branch <branch> (repeatable, default: main, master)-p, --pattern <regex> (repeatable)Caveats
always_run: true by default, and does not take filenames.
As a result, files, exclude, types, etc. are ignored unless you explicitly set always_run: false.check-executables-have-shebangsChecks that non-binary executables have a proper shebang.
Supported arguments
Caveats
#!.prek consults git’s staged mode bits.check-shebang-scripts-are-executableChecks that non-binary files with a shebang are marked executable.
Supported arguments
Caveats
#!.prek consults git’s staged mode bits.