01 / Separate the storage
A package cache is not the project or the AI tool installation
An agent that creates projects, switches branches or installs JavaScript tools can trigger package downloads. The resulting cache belongs to the package manager and may also be used by ordinary development work. Its entire size cannot be attributed to one AI application.
| Storage | What it contains | Cleanup boundary |
|---|---|---|
| Package cache or store | Downloaded package data shared across installs; Yarn may also use cache archives directly at runtime. | Inspect the configured path and use the matching package manager command. |
| Project dependencies | A project’s node_modules, pnpm links or Yarn PnP setup. | Cache maintenance is not a project dependency uninstall. Do not delete these as part of this guide. |
| Installed tools and runtimes | Node.js, package managers and installed CLIs. | Manage them through their original installer. A cache clean is not an uninstall. |
| Models and AI tool state | Local model weights, sessions, settings and application caches. | Measure them separately; npm, Yarn and pnpm cache commands do not clean these locations. |
Keep package.json, package-lock.json, yarn.lock, pnpm-lock.yaml and project configuration. A lockfile records dependency resolution; it does not contain the package bytes needed for an offline reinstall. With Yarn PnP or Zero-Installs, cache archives may be required project data.
02 / Locate and measure
Check versions and actual paths from the relevant project
Save work and let installs, builds and agent tasks finish before maintenance. Run only the commands for package managers you already use; a missing command is not a reason to install another manager. Run them from the relevant project because project configuration and version selection can change the result.
npm --version
yarn --version
pnpm --versionnpm config get cache
pnpm store pathFor Yarn, use the version-specific commands in the Yarn section. Avoid assuming a default home-directory path: configuration, package manager versions and different disks can produce different locations. Record the exact path you intend to maintain.
cache_dir='/absolute/path/to/confirmed-cache'
du -sk "$cache_dir"
df -k "$cache_dir"Replace the example path with the full path returned by the package manager, keeping the quotes. du -sk reports directory usage and df -k reports the containing volume, both in 1,024-byte blocks. Record the Available value and repeat the same measurements after cleanup. Permission or path errors mean the measurement is incomplete, not zero.
03 / npm cache clean
For npm, verify first and clean only when you need the space
npm verifies cached data when inserting and extracting it, and can refetch corrupted data. Routine cache deletion is usually unnecessary. Verification checks integrity and garbage-collects unneeded data; it does not promise to empty the cache.
npm cache verifyIf you have measured a large cache and deliberately want to reclaim that space, the following command clears npm’s package cache. The required --force acknowledges this exceptional operation. Expect future installs to download packages again, and retain the cache if you need an offline reinstall.
npm cache clean --forceThe command does not remove a project’s node_modules, uninstall a globally installed CLI or remove Node.js. Other data under npm’s configured directory, including separately managed execution caches in some versions, may remain. Measure again rather than assuming the whole directory became empty.
04 / yarn cache clean
Yarn Classic and modern Yarn have different cache rules
First check yarn --version. Yarn 1 is Classic; Yarn 2 and later use modern configuration. Do not transfer Classic cache paths or flags to a modern project.
Yarn Classic: inspect the global package cache
yarn cache dirAfter measuring the reported directory and deciding you can download packages again, yarn cache clean clears Classic’s global package cache. The next install repopulates it. It does not remove the project’s existing node_modules.
yarn cache cleanModern Yarn: check project and global cache settings
yarn config get cacheFolder
yarn config get enableGlobalCache
yarn config get globalFolderWhen enableGlobalCache is true, Yarn stores package archives under globalFolder instead of using a separate project cache. When it is false, check the configured cacheFolder; a global mirror may also exist. Inspect the actual package-cache subdirectory, not all of globalFolder.
| Command | Scope and consequence |
|---|---|
yarn cache clean | Removes cache files for the current cache configuration. Check the effective path first; a shared global cache may be in use. |
yarn cache clean --mirror | Targets the global cache or mirror rather than only local project archives; other projects may need those downloads. |
yarn cache clean --all | Removes both global and current-project cache files. It deliberately broadens the cleanup scope. |
Yarn PnP can load packages directly from cache archives, so removing an active cache can break project execution until it is restored. Zero-Installs may track .yarn/cache in Git. Preserve required archives and check project policy before cleaning. yarn install --immutable protects the lockfile; it does not protect cache files. --immutable-cache or enableImmutableCache makes an install fail if it must add or remove cache files. Do not disable these safeguards just to hide a missing cache.
05 / pnpm store prune
Prune unreferenced pnpm packages without deleting the store
Use pnpm store path to locate the active store and measure it first. pnpm can retain older package versions after dependency updates. Pruning removes packages that are no longer referenced, rather than uninstalling the dependencies of active projects.
pnpm store pruneRun this occasionally after installs have finished, not concurrently with installs or other store maintenance. If your pnpm version uses a store server, stop it through that version’s documented workflow first: pnpm 10 documentation prohibits pruning while a store server is running. Check the documentation matching your installed version.
Switching branches or rebuilding an older project can require pruned packages again. pnpm will download them on a future install, which takes time and needs access to the registry. An offline reinstall may fail after pruning. Keep lockfiles and do not replace this command with manual deletion of the store or project links.
06 / Check the result
Compare the same path and disk, then investigate what remains
- Repeat the directory and volume measurements from the inspection step. If a cache directory was removed, use its existing parent on the same volume for the disk check; do not interpret a missing path as a successful measurement.
- Compare available space on that same disk. Hard links, APFS clones or snapshots and background writes can make the directory-size difference differ from the newly available space. Do not add overlapping cache paths or shared storage totals together.
- Run the project’s usual checks when you next work on it. Follow its existing installation workflow if packages need restoring; a fresh install can rebuild the cache, so do not use one merely to prove space was reclaimed.
- If the disk is still full, measure project dependencies, working copies, model downloads and AI tool state separately. Cache cleanup cannot resolve every storage category.
Other AI tool data
Review tool data separately from package caches
AgentClean brings together cleanup candidates covered by its rules for supported AI tools. Use the package manager commands in this guide to assess shared dependency caches.
For npm, Yarn and pnpm, follow the manual steps in this guide. Before using AgentClean for other local AI tool data, check its supported tools and paths.
Stay tuned
AgentClean is currently available only for Mac. Other platforms aren’t available yet. Visit this site on a Mac to download.
See supported tools · Check coverage before deciding how to manage each data location.
Frequently asked questions
A few more things to check
Should I run npm cache clean --force regularly?
Usually no. npm’s package cache verifies integrity and can recover from corrupt data. Prefer npm cache verify for routine maintenance. Use clean --force when you have a specific reason such as reclaiming measured cache space and can accept later downloads.
Does cache cleanup remove node_modules or uninstall my AI CLI?
npm cache clean and Yarn Classic cache clean do not uninstall existing node_modules or global CLIs, and pnpm store prune targets unreferenced store packages. Modern Yarn PnP is different: it can use cache archives at runtime, so cleaning an active cache may require restoring packages before the project works again.
Why does yarn cache clean behave differently between projects?
Projects can select different Yarn versions and cache settings. Yarn 1 uses Classic’s global cache. Modern Yarn can use project or shared global archives, and --mirror or --all changes the cleanup scope. Check yarn --version and the effective configuration in each relevant project before cleaning.
Can I reinstall offline after pnpm store prune or another cache clean?
Not necessarily. A lockfile identifies packages but does not hold their contents. If required cached packages were removed, the next install needs downloads and may fail offline. Preserve caches needed for upcoming offline work and expect old branches to need packages again.