prettier --cache: Skip Unchanged Files
prettier --cache stores results so a second run only processes files that changed.
Introduced in Prettier 2.7, --cache cuts the time of repeated runs. Combined with a CI cache of the cache file, format checks get noticeably faster.
What it does
prettier --cache writes a cache (by default node_modules/.cache/prettier/.prettier-cache) recording which files were already formatted. On the next run it skips files that have not changed, by metadata or content. --cache-location sets the file path and --cache-strategy chooses metadata or content based change detection.
Common usage
prettier --check --cache .
prettier --write --cache --cache-strategy content "src/**/*.ts"Flags
| Flag | What it does |
|---|---|
| --cache | Enable caching of formatted file results |
| --cache-location <path> | Where to store the cache file |
| --cache-strategy metadata|content | How to detect changes (default metadata) |
| --no-cache | Disable caching for this run |
In CI
Persist the cache file across runs using your CI cache (key it on the lockfile and Prettier version). Always include the Prettier version in the cache key, because a Prettier upgrade can change output and a stale cache would let unformatted files pass. The metadata strategy is fastest but content is safer when timestamps are unreliable on the runner.
Common errors in CI
If a file that is actually misformatted passes --check, the cache is likely stale after a Prettier or config change; clear it or bust the CI cache key, which is why the version belongs in the key. "[error] ... cache" path issues mean --cache-location points at an unwritable directory; choose a writable path. Note --cache cannot be combined with reading from stdin.