The npx cache was 2.4 GB of tools run once and never again
Every npx run of a package you have not installed leaves a full copy in ~/.npm/_npx. Measured at 2.4 GB across 44 entries, some over a year old.
npx create-something feels like it runs a tool and leaves nothing behind. It does not. npx installs the package and every one of its dependencies into a folder under ~/.npm/_npx, and that folder is never cleaned up.
Why it grows
- Each distinct package, and each distinct version of it, gets its own folder named by a hash.
- The folder holds a complete
node_modules, so a scaffolding tool with a heavy dependency tree costs hundreds of megabytes the first time you run it. - Nothing expires. A tool you ran once for a tutorial eighteen months ago is still there.
See what is in it
du -sh ~/.npm/_npx/* | sort -h | tail -10
# Which package a folder is for
cat ~/.npm/_npx/<folder>/package.jsonClearing it
Everything in _npx is a copy of something on the registry, so removing it costs one download the next time you run that tool.
rm -rf ~/.npm/_npxnpm cache clean --force does not touch this folder. It empties ~/.npm/_cacache, the download cache, which sits next to it, and that is covered in npm cache taking up space. The two are separate, which is why a Mac can have run the clean command and still carry gigabytes here.
Keeping it small
- For a tool you run weekly, a global install is one copy you can see and update:
npm install -g <tool>. The cost of those is in global npm packages. - For a one-off,
npxis still the right call. Clear the folder every few months. - Project dependencies are a different, larger problem, measured in node_modules taking up space.
Common questions
Where is the npx cache on a Mac?
In ~/.npm/_npx. Each subfolder is one package that npx installed, with its full dependency tree.
Is it safe to delete ~/.npm/_npx?
Yes. It only holds copies of packages from the registry. The next npx run of a tool downloads it again.
Does npm cache clean clear the npx cache?
No. npm cache clean empties ~/.npm/_cacache. The _npx folder is separate and has to be removed on its own.
How big does the npx cache get?
It depends on how many different tools you have run. On the Mac measured it was 2.4 GB across 44 packages, the oldest over a year old.