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 (Trim trailing whitespace)check-added-large-files (Prevent committing large files)check-case-conflict (Check for files that would conflict in case-insensitive filesystems)end-of-file-fixer (Ensure newline at EOF)file-contents-sorter (Sort lines in explicitly targeted files)fix-byte-order-marker (Remove UTF-8 byte order marker)forbid-new-submodules (Prevent addition of new git submodules.)check-json (Validate JSON files)check-toml (Validate TOML files)check-vcs-permalinks (Check that VCS links are permalinks)check-yaml (Validate YAML files)check-xml (Validate XML files)mixed-line-ending (Normalize or check line endings)check-symlinks (Check for broken symlinks)destroyed-symlinks (Detect destroyed symlinks)check-merge-conflict (Check for merge conflicts)detect-private-key (Detect private keys)no-commit-to-branch (Prevent committing to protected branches)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 (Trim trailing whitespace)check-added-large-files (Prevent committing large files)check-case-conflict (Check for files that would conflict in case-insensitive filesystems)check-illegal-windows-names (Check for filenames invalid on Windows)end-of-file-fixer (Ensure newline at EOF)file-contents-sorter (Sort lines in explicitly targeted files)fix-byte-order-marker (Remove UTF-8 byte order marker)check-json (Validate JSON files)check-json5 (Validate JSON5 files)pretty-format-json (Pretty format JSON files)check-toml (Validate TOML files)check-vcs-permalinks (Check that VCS links are permalinks)check-yaml (Validate YAML files)check-xml (Validate XML files)mixed-line-ending (Normalize or check line endings)check-symlinks (Check for broken symlinks)destroyed-symlinks (Detect destroyed symlinks)check-merge-conflict (Check for merge conflicts)detect-private-key (Detect private keys)no-commit-to-branch (Prevent committing to protected branches)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$
fix-byte-order-markerRemoves a UTF-8 byte order marker (BOM) from the beginning of a file.
Supported arguments
Caveats
EF BB BF).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
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.