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.
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.logCommon 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
- Print the log path pre-commit named (for example
cat ~/.cache/pre-commit/pre-commit.log). - Find the exact command and return code that failed.
- Fix that specific cause (network, missing runtime, or hook error).
- run: pre-commit run --all-files
- if: failure()
run: cat ~/.cache/pre-commit/pre-commit.logClear a corrupt cache and retry
If the failure is inside env setup, wipe the pre-commit cache so environments rebuild cleanly.
pre-commit clean
pre-commit run --all-filesHow to prevent it
- Always surface the pre-commit.log on failure so the real error is visible.
- Key the cache on
.pre-commit-config.yamlso a config change rebuilds envs. - Pin hook revs so environment builds are deterministic.