pre-commit hooks id: Selecting and Tuning Hooks
Each item in a repo hooks list is selected by id and can override how that hook runs.
A hook id picks one hook from the repo. Per-hook keys let you pass args, narrow the file set, or add extra dependencies without forking the hook.
What it does
The id must match an id in the source repo .pre-commit-hooks.yaml. Optional keys override the defaults: args adds command-line arguments, files/exclude narrow the matched paths, types filters by file type, and additional_dependencies installs extra packages into the hook environment.
Common usage
- repo: https://github.com/PyCQA/flake8
rev: 7.1.0
hooks:
- id: flake8
args: ["--max-line-length=100"]
additional_dependencies: ["flake8-bugbear"]
exclude: "^tests/fixtures/"Per-hook keys
| Key | What it does |
|---|---|
| id | Which hook from the repo to enable |
| args | Extra command-line arguments for the hook |
| files / exclude | Regex to include or exclude paths for this hook |
| types / types_or | Filter by detected file type (python, yaml, ...) |
| additional_dependencies | Extra packages installed into the hook env |
| stages | Stages this hook runs at |
Common errors in CI
"No hook with id <x> in repo <url>" means the id is wrong for that rev (the hook was renamed or removed). After editing additional_dependencies you may need pre-commit clean, because the hook environment is cached by config and a stale env can keep the old dependency set. The meta hook check-hooks-apply flags hooks whose file filters match nothing.