DEV Community

Mayne
Mayne

Posted on

I reclaimed 12GB from my SSD with one terminal command (and you can too)

I've been a developer for over a decade, and if there's one thing I've learned, it's that our hard drives are basically landfills for build artifacts.

A few weeks ago, I was down to 2GB free on my main SSD. Not because I had tons of important files — but because I had years worth of node_modules folders, .next build caches, dist directories, and other junk scattered across dozens of old projects.

I tried reclaiming space manually. You know the drill — du -sh to find the culprits, then rm -rf them one by one. It works, but it's tedious. I tried npkill — it only handles node_modules. I tried wipe-modules — same limitation. I wanted something that could find everything at once and let me pick what to delete in one go.

So I built ZapDir.

What is ZapDir?

ZapDir is a terminal cleanup tool that scans your projects for heavy build artifacts and lets you delete them through a beautiful interactive interface. It's completely free, open-source under MIT, and runs on Windows, macOS, and Linux with Node.js 18+.

npm install -g zapdir
zapdir
Enter fullscreen mode Exit fullscreen mode

Run that, and you'll see something like this:

⚡  ZapDir  —  Terminal Cleanup Tool

  🗑  Junk Found — Total recoverable:  1.47 GB

  ██████████  node_modules    /node_modules      245.23 MB
  ██████░░░░  .next           /.next               1.23 GB
  ██░░░░░░░░  dist            /dist                89.45 MB

  ✔  Delete 3 item(s) freeing 1.47 GB?  ·  Yes

  ✔  Freed 1.47 GB of disk space!
Enter fullscreen mode Exit fullscreen mode

The colored size bars make it obvious what's eating the most space at a glance — red for anything over 500MB, yellow for over 100MB, and green for the rest.

What makes it different from npkill or wipe-modules?

There are other cleanup tools out there, but most of them only handle one pattern. Here's how ZapDir compares:

Feature ZapDir npkill wipe-modules
Patterns detected 13+ 1 (node_modules) 1 (node_modules)
Interactive TUI
Color-coded sizes
Dry-run preview
Async scanner
Cross-platform

ZapDir detects: node_modules, .next, .nuxt, .turbo, dist, build, .cache, coverage, out, target, .parcel-cache, __pycache__, and .DS_Store.

What it found on my machine

I ran ZapDir across my development machine and here's what turned up:

Location What was there Space recovered
~/Projects/legacy-app node_modules + .next 1.8 GB
~/Projects/side-project node_modules + build 640 MB
~/Projects/old-tutorial node_modules 420 MB
~/.cache Various caches 340 MB
Various Rust projects target/ directories 2.1 GB
Old Next.js projects .next caches 3.4 GB
Abandoned monorepos node_modules × 5 2.2 GB
Python projects __pycache__ + .cache 180 MB

Total reclaimed: roughly 12 GB

That's 12 GB I got back without touching a single file I actually needed. The biggest wins were old Next.js projects with massive .next caches (some over 1 GB each) and Rust projects where target/ directories had accumulated to over 2 GB combined.

Is it safe?

Short answer: yes, if you use --dry-run first.

zapdir --dry-run ~/Projects
Enter fullscreen mode Exit fullscreen mode

This scans and shows you exactly what would be deleted without actually removing anything. The output shows every item with its size, path, and a visual bar so you know exactly what you're getting into.

When you're satisfied with the preview, run it without the flag. You'll be prompted to confirm before anything is deleted:

✔  Delete 3 item(s) freeing 1.47 GB?  ·  Yes / No
Enter fullscreen mode Exit fullscreen mode

The scanner uses fs.promises.readdir with async parallel traversal for speed, and deletion is done with Promise.allSettled so a permission error on one file won't crash the entire operation — it just skips that file and continues. I've been using it for weeks and haven't lost a single file I needed.

How the scanning works

The core logic is surprisingly straightforward. It walks directories recursively using Node.js's built-in fs.promises, matches directory names against a list of known artifact patterns, calculates sizes using a streaming iterator (to avoid memory issues on huge folders), and presents everything in an interactive selection menu powered by @clack/prompts.

Hidden directories like .git are skipped by default for speed. The entire scan of my home directory — thousands of folders — completes in under 10 seconds.

A practical tip

Here's what I do now: once a month, I run:

zapdir --dry-run ~/Projects
Enter fullscreen mode Exit fullscreen mode

This gives me a quick health check of how much junk has accumulated. When the number crosses 1 GB, I run it for real and reclaim the space. It's become part of my regular maintenance routine, right alongside brew update and npm outdated.

Give it a shot

If you're running low on disk space and have old projects lying around, try it:

npm install -g zapdir
zapdir
Enter fullscreen mode Exit fullscreen mode

It takes five seconds to install and could free up gigabytes. The code is open source under MIT, so you can inspect exactly what it does before running it.

⭐ Star the repo on GitHub if you find it useful — it helps other developers discover it too.


ZapDir is MIT licensed and open source. Contributions, feature requests, and bug reports are welcome on GitHub.

Top comments (0)