macOS cleanup guides / Package manager caches

npm, Yarn and pnpm caches on Mac: find the space before cleaning

Repeated dependency installs during AI coding tasks can grow npm, Yarn or pnpm storage outside the AI tool’s own folders. These caches may serve many projects and tools. Identify the package manager, its version and its actual cache before choosing a command.

Measure first; use the package manager’s own maintenance command

For npm, start with npm cache verify. Use npm cache clean --force only for a specific reason such as reclaiming measured cache space. Check the Yarn version and cache scope before cleaning; use pnpm store prune for unreferenced store packages. Keep lockfiles and plan for downloads on future installs.

Shared package caches need their own checks

Follow the manual steps below for npm, Yarn and pnpm. Separately, AgentClean can help review cleanup candidates for supported AI tools.

Check package caches

Maintain shared package caches with the commands below. For other local AI tool data, check the paths AgentClean supports.

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.

Four storage types that need different treatment
StorageWhat it containsCleanup boundary
Package cache or storeDownloaded 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 dependenciesA 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 runtimesNode.js, package managers and installed CLIs.Manage them through their original installer. A cache clean is not an uninstall.
Models and AI tool stateLocal model weights, sessions, settings and application caches.Measure them separately; npm, Yarn and pnpm cache commands do not clean these locations.
Keep the installation instructions

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.

Check installed package manager versions
npm --version
yarn --version
pnpm --version
Locate the configured npm cache and active pnpm store
npm config get cache
pnpm store path

For 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.

Measure one confirmed directory and its volume
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.

Preferred npm cache maintenance
npm cache verify

If 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.

Clear the npm package cache after confirming the reason
npm cache clean --force
This does not uninstall dependencies

The 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 1 only: locate the cache
yarn cache dir

After 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 1 only: clear the global package cache
yarn cache clean

Modern Yarn: check project and global cache settings

Yarn 2 and later: inspect cache configuration
yarn config get cacheFolder
yarn config get enableGlobalCache
yarn config get globalFolder

When 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.

Modern Yarn cleanup scope: choose deliberately
CommandScope and consequence
yarn cache cleanRemoves cache files for the current cache configuration. Check the effective path first; a shared global cache may be in use.
yarn cache clean --mirrorTargets the global cache or mirror rather than only local project archives; other projects may need those downloads.
yarn cache clean --allRemoves both global and current-project cache files. It deliberately broadens the cleanup scope.
PnP, Zero-Installs and immutable installs need extra care

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.

Remove unreferenced packages from the pnpm store
pnpm store prune

Run 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.

Unused now may be needed on another branch

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

  1. 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.
  2. 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.
  3. 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.
  4. 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.

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.