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.
/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
- Add a step that installs the framework with pip.
- Invoke it as a module (
python -m pre_commit) if PATH is unreliable. - Run the hooks after the install completes.
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- run: python -m pip install pre-commit
- run: pre-commit run --all-filesCall it through the interpreter
Invoking pre-commit as a module avoids any PATH lookup and always uses the Python you installed it into.
python -m pip install pre-commit
python -m pre_commit run --all-filesHow to prevent it
- Always install pre-commit explicitly in CI; it is never preinstalled.
- Prefer
python -m pre_commitso PATH is never the issue. - Pin the pre-commit version so runs are reproducible across runners.