Skip to content
Latchkey

pre-commit "An unexpected error has occurred: CalledProcessError" in CI

pre-commit ran an external command (git, a language install, or a hook) and it exited non-zero, so pre-commit wraps it in CalledProcessError and points you at a log file with the captured output.

What this error means

The run stops with "An unexpected error has occurred: CalledProcessError:" and "Check the log at /root/.cache/pre-commit/pre-commit.log". The command and its return code are in that log.

pre-commit
An unexpected error has occurred: CalledProcessError: command:
('/usr/bin/git', 'fetch', 'origin', '--tags')
return code: 128
Check the log at /root/.cache/pre-commit/pre-commit.log

Common causes

A subprocess pre-commit invoked exited non-zero

The wrapped command (a git fetch of a hook repo, a language environment build, or the hook itself) failed, and pre-commit surfaces it as CalledProcessError.

A broken or partial cache under PRE_COMMIT_HOME

A previous interrupted run left a corrupt hook environment, so re-running the same setup command fails again.

How to fix it

Read the referenced log

  1. Print the log path pre-commit named (for example cat ~/.cache/pre-commit/pre-commit.log).
  2. Find the exact command and return code that failed.
  3. Fix that specific cause (network, missing runtime, or hook error).
.github/workflows/ci.yml
- run: pre-commit run --all-files
- if: failure()
  run: cat ~/.cache/pre-commit/pre-commit.log

Clear a corrupt cache and retry

If the failure is inside env setup, wipe the pre-commit cache so environments rebuild cleanly.

Terminal
pre-commit clean
pre-commit run --all-files

How to prevent it

  • Always surface the pre-commit.log on failure so the real error is visible.
  • Key the cache on .pre-commit-config.yaml so a config change rebuilds envs.
  • Pin hook revs so environment builds are deterministic.

Related guides

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