Files
Holocron/plugins/git/docs/research/docs/pre-commit/hooks-reference.md
T

6.0 KiB

topic, source_keys
topic source_keys
hooks-reference
context7-pre-commit-hooks
pre-commit-hooks-github

pre-commit-hooks (official collection)

Repo: https://github.com/pre-commit/pre-commit-hooks Latest version: v6.0.0 Pinned in this repo: v4.5.0 — consider running pre-commit autoupdate

- repo: https://github.com/pre-commit/pre-commit-hooks
  rev: v6.0.0
  hooks:
    - id: <hook-id>

File syntax / content checks

Hook ID What it does Key args
check-ast Validates Python files parse as valid AST —
check-json Validates JSON parses correctly —
check-toml Validates TOML parses correctly —
check-xml Validates XML parses correctly —
check-yaml Validates YAML parses correctly --allow-multiple-documents, --unsafe (syntax-only, enables custom tags)
check-merge-conflict Detects unresolved merge markers (<<<<<<<) --assume-in-merge

Filesystem / naming / encoding checks

Hook ID What it does Key args
check-added-large-files Blocks files over size threshold --maxkb=N (default 500), --enforce-all
check-case-conflict Detects filenames differing only by case (macOS/Windows hazard) —
check-executables-have-shebangs Ensures executable files have a shebang —
check-shebang-scripts-are-executable Ensures files with shebangs are executable —
check-illegal-windows-names Detects filenames illegal on Windows —
check-symlinks Detects broken symlinks —
destroyed-symlinks Catches symlinks converted to regular files (common on Windows) —
fix-byte-order-marker Removes UTF-8 BOM —

Security

Hook ID What it does Key args
detect-private-key Blocks PEM private key material —
detect-aws-credentials Blocks AWS credentials (reads ~/.aws/credentials) --credentials-file PATH (repeatable), --allow-missing-credentials

Hook ID What it does Key args
no-commit-to-branch Blocks commits to protected branches -b/--branch NAME (repeatable, default: main+master), -p/--pattern REGEX
check-vcs-permalinks Ensures GitHub links are SHAs not branch refs --additional-github-domain DOMAIN
forbid-new-submodules Blocks adding new git submodules —
forbid-submodules Blocks any submodule in the repo —

Note: no-commit-to-branch runs with always_run: true by default — it ignores files/types filters.


Whitespace / line-ending fixers

Hook ID What it does Key args
end-of-file-fixer Ensures files end with exactly one newline —
trailing-whitespace Removes trailing whitespace --markdown-linebreak-ext=md (preserve line breaks), --chars
mixed-line-ending Normalises line endings --fix=auto (default), --fix=lf, --fix=crlf, --fix=no (check only)

Formatters / sorters

Hook ID What it does Key args
pretty-format-json Formats JSON; fails if not already formatted --autofix (fix in place), --indent N, --no-sort-keys, --no-ensure-ascii, --top-keys k1,k2
requirements-txt-fixer Sorts and deduplicates requirements.txt and constraints.txt —
file-contents-sorter Sorts lines in user-specified files alphabetically --ignore-case, --unique; no files matched by default — must set files:
sort-simple-yaml Sorts top-level keys in simple YAML files No files matched by default — must set files:

Python-specific

Hook ID What it does Key args
check-builtin-literals Requires literal syntax for empty built-ins ([] not list()) --ignore=type1,type2, --no-allow-dict-kwargs
debug-statements Detects import pdb, breakpoint(), etc. —
double-quote-string-fixer Converts double-quoted strings to single-quoted —
name-tests-test Enforces test file naming convention --pytest (default: .*_test.py), --pytest-test-first (test_.*.py), --django/--unittest

Deprecated hooks

Hook ID Replacement
check-byte-order-marker Use fix-byte-order-marker
fix-encoding-pragma Use pyupgrade
check-docstring-first Deprecated without replacement

Argument examples

check-yaml with Kubernetes manifests

- id: check-yaml
  args: ['--unsafe']   # needed for !Tag syntax used by k8s/Helm

no-commit-to-branch

- id: no-commit-to-branch
  args: [--branch, main, --branch, master, --branch, production]

pretty-format-json auto-fix

- id: pretty-format-json
  args: [--autofix, --indent, '2', --no-sort-keys]

sort-simple-yaml opt-in (no files matched by default)

- id: sort-simple-yaml
  files: ^config/simple/

trailing-whitespace preserving Markdown line breaks

- id: trailing-whitespace
  args: ['--markdown-linebreak-ext=md']

Hooks in this repo (.pre-commit-config.yaml)

From pre-commit/[email protected] (latest is v6.0.0):

Hook Stage Notes
end-of-file-fixer pre-commit
check-json pre-commit
pretty-format-json pre-commit No --autofix — fails on unformatted JSON, does not fix
check-yaml pre-commit
trailing-whitespace pre-commit

Local hooks in this repo:

Hook Stage Entry
run-tests pre-push bash tests/run-tests.sh
check-manifests pre-push bash scripts/check-manifests.sh
validate-plugins pre-push claude plugin validate --strict per plugin dir
validate-marketplace pre-push claude plugin validate --strict .claude-plugin/marketplace.json
skill-frontmatter pre-commit Validates SKILL.md has name: and description: