Skip to content
Latchkey

pre-commit "command not found" in CI

The shell could not find a pre-commit executable on PATH. On a clean CI runner the framework is not preinstalled, so a bare pre-commit run fails until you pip install pre-commit first.

What this error means

A step calling pre-commit run --all-files exits 127 with "pre-commit: command not found", even though the config file is committed.

CI
/home/runner/work/_temp/script.sh: line 1: pre-commit: command not found
Error: Process completed with exit code 127.

Common causes

pre-commit was never installed on the runner

CI runners do not ship the pre-commit framework. Without an explicit pip install pre-commit, there is no executable to run.

It was installed under an interpreter not on PATH

A pip install --user or a venv that the step did not activate leaves the pre-commit script off PATH, so the shell cannot find it.

How to fix it

Install pre-commit before running it

  1. Add a step that installs the framework with pip.
  2. Invoke it as a module (python -m pre_commit) if PATH is unreliable.
  3. Run the hooks after the install completes.
.github/workflows/ci.yml
- uses: actions/setup-python@v5
  with:
    python-version: '3.12'
- run: python -m pip install pre-commit
- run: pre-commit run --all-files

Call it through the interpreter

Invoking pre-commit as a module avoids any PATH lookup and always uses the Python you installed it into.

Terminal
python -m pip install pre-commit
python -m pre_commit run --all-files

How to prevent it

  • Always install pre-commit explicitly in CI; it is never preinstalled.
  • Prefer python -m pre_commit so PATH is never the issue.
  • Pin the pre-commit version so runs are reproducible across runners.

Related guides

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