LinuxmacOSWindows

Where Does pre-commit Cache Hook Environments?

Where pre-commit caches hook environments under PRE_COMMIT_HOME, and the commands that clean them.

Last updated

pre-commit builds each hook an isolated environment and caches it under ~/.cache/pre-commit (PRE_COMMIT_HOME overrides). Repos share the cache by content hash, so ten Python repos reuse one flake8 install instead of building ten.

Stale environments are the classic mystery failure: a hook that worked yesterday breaks after an upstream release because the cache holds the old build. pre-commit clean plus a fresh run resolves most of it. The gc variant (pre-commit gc) prunes only environments no current config references.

Where pre-commit stores this, by platform

Linux
~/.cache/pre-commit

Respects $XDG_CACHE_HOME. Override with PRE_COMMIT_HOME. Clean with pre-commit clean, prune unreferenced with pre-commit gc. Same layout on every OS, home prefix aside.

macOS
~/.cache/pre-commit

Same cache and commands as Linux. Finder hides Library, but the cache sits in home .cache regardless.

Windows
%USERPROFILE%\.cache\pre-commit

Git Bash and WSL builds use their own home-relative .cache. Same PRE_COMMIT_HOME override and clean commands.

Frequently asked questions

How do I clear the pre-commit cache?

Run pre-commit clean. It empties the hook environment cache while leaving your config and installed git hooks in place. Next run rebuilds whatever hooks still trigger. Deleting the folder by hand works identically when the command is unavailable.

Can I share one hook cache across repos?

Set PRE_COMMIT_HOME to a shared path before running hooks. Environments are content addressed and safe to share across checkouts, which speeds CI matrices enormously. Per project isolation is the default only because sharing needs explicit opt in.

Notice an outdated path? Let us know.