How to clear the Yarn cache

Yarn 1 (classic) keeps one global cache. Yarn 2+ (Berry) keeps a global mirror and, depending on settings, a per-project .yarn/cache. Same command name, different folders, so check yarn --version first.

These commands permanently delete files. Most are caches the tool rebuilds on its own (the next build or install is slower and may need internet). Anything that can hold data you cannot re-download is flagged on the page. Read each command, then copy and run it yourself. devdisk never runs cleanup commands for you.

Yarn 1 (classic)

Any OS
yarn cache dir
yarn cache clean            # everything
yarn cache clean lodash     # one package

Yarn 2+ (Berry)

Any OS
yarn cache clean            # this project's cache
yarn cache clean --mirror   # the global mirror
yarn cache clean --all      # both

The global mirror lives at ~/.yarn/berry/cache on macOS and Linux (%USERPROFILE%\.yarn\berry\cache on Windows).

If your repo commits .yarn/cache for zero-installs, cleaning it shows up as deleted files in git. Don’t commit that change.

Measure with devdisk

devdisk is a free, read-only scanner. It lists the Yarn 1 cache under Safe to regenerate with yarn cache clean. It never deletes anything; it only shows sizes and writes a cleanup script you read and run yourself. The Berry mirror is not scanned yet; check it with du -sh ~/.yarn/berry/cache.

macOS / Linux
curl -fsSLO https://disk.sadana.app/devdisk.py && python3 devdisk.py
Windows (PowerShell)
iwr https://disk.sadana.app/devdisk.py -OutFile devdisk.py; py devdisk.py

Run free scannerSample report

Want one-click cleanup?

A planned devdisk desktop app for Mac and Windows: live treemap, cleanup that moves files to the Trash, scheduled scans. One email when it launches, with an early-supporter price. Your address is used only for that, and every email has an unsubscribe link.

FAQ

Is clearing the Yarn cache safe?

Yes. Packages are downloaded again on the next install. Avoid running it while an install is in progress.

Why is my cache still big after yarn cache clean?

You may be on Berry, where the global mirror needs yarn cache clean --mirror, or have several Yarn versions with separate caches.

Does devdisk clear the cache for me?

No. It is read-only and only suggests the command.

More cleanup guides