Skip to content
Latchkey

pre-commit/action and pre-commit.ci behaviour in CI

The official pre-commit/action installs pre-commit, restores its cache, and runs the hooks on GitHub Actions. The separate hosted pre-commit.ci service runs hooks on pull requests and auto-commits fixes instead of leaving the check red.

What this error means

Teams are unsure whether to fail on formatting changes in Actions or let pre-commit.ci auto-fix them, and how the action handles caching and installation for you.

.github/workflows/pre-commit.yml
# .github/workflows/pre-commit.yml
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: pre-commit/action@v3.0.1

Common causes

The action already handles install and cache

pre-commit/action installs pre-commit and caches ~/.cache/pre-commit for you, so a manual pip install and cache step are redundant with it.

pre-commit.ci changes the failure model

The hosted bot auto-commits formatter fixes to the PR branch, so the "files were modified" failure becomes an automatic commit instead of a red check.

How to fix it

Use the action for a self-managed workflow

  1. Check out the repo and set up Python.
  2. Add pre-commit/action, which installs, caches, and runs the hooks.
  3. Fail the job on any modification so contributors format before pushing.
.github/workflows/pre-commit.yml
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: pre-commit/action@v3.0.1

Enable pre-commit.ci to auto-fix PRs

Configure the ci block so the hosted bot autoupdates and auto-commits fixes on pull requests.

.pre-commit-config.yaml
ci:
  autofix_prs: true
  autoupdate_schedule: weekly

How to prevent it

  • Pick one model: fail-and-fix-locally with the action, or auto-fix with pre-commit.ci.
  • Do not double up manual install/cache steps with pre-commit/action.
  • Pin the action and hook revs so runs stay reproducible.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →