Skip to content
Latchkey

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

.pre-commit-config.yaml
- 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

KeyWhat it does
idWhich hook from the repo to enable
argsExtra command-line arguments for the hook
files / excludeRegex to include or exclude paths for this hook
types / types_orFilter by detected file type (python, yaml, ...)
additional_dependenciesExtra packages installed into the hook env
stagesStages 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.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →