How to Clean node_modules, Cargo target, and AI Tool Caches on Windows
A Windows developer PC regularly loses 50 to 150 GB across C:\Users\<name> and repository folders without a single huge installer sitting in Downloads. Rust workspaces grow multi-gigabyte target\ directories, older JavaScript repos keep node_modules\, .next\, dist\, and build\ trees packed with hundreds of thousands of small files, package managers fill %LOCALAPPDATA%\npm-cache and %USERPROFILE%\.cargo\registry\cache, and auto-updating AI coding CLIs stack 250 to 480 MB of superseded binaries per release under %USERPROFILE%\.local\share\claude\versions and %USERPROFILE%\.codex. Reclaiming that space safely comes down to measuring size and last-modified dates first, separating rebuildable output and download caches from lockfile-less dependencies and AI chat transcripts, and sending idle project trees to the Recycle Bin rather than running Remove-Item -Recurse -Force blindly.
Measure node_modules, Cargo target, and package caches first
Before deleting anything, run a read-only PowerShell scan against your workspace directory (change $root if your repositories live on another path or drive) to list the 20 largest top-level node_modules and target folders alongside their last write date, without double-counting nested node_modules folders inside dependencies:
$root = "$HOME\source"
Get-ChildItem -Path $root -Directory -Recurse -ErrorAction SilentlyContinue |
Where-Object { $_.Name -in @('node_modules', 'target') -and $_.FullName -notmatch '\\(node_modules|target)\\.+\\(node_modules|target)$' } |
ForEach-Object {
$bytes = (Get-ChildItem -LiteralPath $_.FullName -File -Recurse -Force -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum
[PSCustomObject]@{
SizeMB = [math]::Round(($bytes / 1MB), 1)
LastWriteTime = $_.LastWriteTime.ToString('yyyy-MM-dd')
Path = $_.FullName
}
} | Sort-Object SizeMB -Descending | Select-Object -First 20 | Format-Table -AutoSize
Next, check where your package managers and Rust toolchain actually store their shared caches rather than guessing default paths:
npm config get cache
pnpm store path
uv cache dir
python -m pip cache info
Get-ChildItem "$HOME\.cargo\registry\cache", "$HOME\.cargo\registry\src", "$HOME\.rustup\toolchains" -ErrorAction SilentlyContinue |
ForEach-Object { "{0,-42} {1,8:N1} MB" -f $_.FullName, ((Get-ChildItem $_.FullName -Recurse -File -ErrorAction SilentlyContinue | Measure-Object Length -Sum).Sum / 1MB) }
Each tool documents its own layout in the Cargo home guide, npm cache reference, pnpm store reference, and uv cache documentation. For why package caches and project dependencies have different rebuild guarantees when you go offline, see Windows developer caches.
Safe vs destructive cleanup across projects, caches, and AI tools
Every folder below lives in a developer profile, yet losing the wrong one costs hours of broken builds or lost conversation context.
| Category | Typical Windows path | Rebuilds offline? | Safe cleanup path | Check before removing |
|---|---|---|---|---|
Rust build output (target\) |
<repo>\target next to Cargo.toml |
Yes, if crate sources remain cached | cargo clean or Recycle Bin |
No cargo or rustc process is building; keep Cargo.lock |
| Web and app build output | <repo>\.next, dist, build |
Yes (npm run build) |
Project clean script or Recycle Bin | Folder is not tracked by Git and holds no hand-copied assets |
Idle node_modules\ |
<repo>\node_modules |
Only if global cache or store still holds packages | Recycle Bin on inactive repos | Lockfile (package-lock.json, pnpm-lock.yaml, yarn.lock, or bun.lock) exists and no dev server or watcher is running |
| Shared package caches | %LOCALAPPDATA%\npm-cache, Cargo registry\cache, pnpm store, uv cache |
No (re-fetched from registry) | pnpm store prune, uv cache prune, or cache cleaner |
Avoid clearing right before offline travel; never delete %USERPROFILE%\.cargo\bin |
| AI CLI caches and old builds | %USERPROFILE%\.local\share\claude\versions, %USERPROFILE%\.codex\packages\standalone\releases, %LOCALAPPDATA%\cursor-agent\versions |
Active CLI binary stays untouched | Delete only superseded release binaries and cache directories | Keep the currently active version and config files |
| AI chat histories and sessions | %USERPROFILE%\.claude\projects, history.jsonl, %USERPROFILE%\.codex\sessions |
No (irreplaceable transcripts) | Keep by default; review by age separately | Separate from caches and uninstall leftovers (uninstalling Claude Code, Codex CLI, Gemini CLI, and OpenCode on Windows) |
Three mistakes cause almost all developer cleanup regrets on Windows:
- Deleting
node_moduleswithout a lockfile or while a dev server is open:cargo clean,.next\, anddist\rebuild deterministically from local source. Deletingnode_modulesin a legacy folder that haspackage.jsonbut nopackage-lock.json,npm-shrinkwrap.json,pnpm-lock.yaml,yarn.lock, orbun.lockforces the next install to resolve newer semver versions that often fail to compile. Deleting while Vite, Next.js, or an editor language server holds.nodenative addons open leaves half the tree locked on disk. - Running
Remove-Item -Recurse -Forceon project directories: PowerShell'sRemove-Itemskips the Recycle Bin permanently. If a repository'sbuild\folder actually holds committed packaging scripts rather than compiler output, there is no undo unless Git already tracks every file. - Wiping
.claudeor.codexwhole: AI coding agents keep debug logs, caches, and 250 to 480 MB auto-update binaries under the same parent profile folders that storeprojects,sessions, andhistory.jsonl. Clearing the parent directory erases months of prompts and local session history along with the cache.
Why deleting node_modules and target stalls File Explorer
Even a modest set of node_modules\ and target\debug\deps\ folders can hold 200,000 to 500,000 tiny .js, .d.ts, .rlib, and .rcgu.o files. On NTFS, unlinking hundreds of thousands of directory entries is metadata-heavy on its own, and Microsoft Defender Antivirus (MsMpEng.exe) inspects file activity in real time during both builds and mass deletions, pushing CPU high while Explorer's progress bar barely moves.
If Task Manager shows MsMpEng.exe spiking alongside cargo, node, or a cleanup pass, follow the steps in Antimalware Service Executable high CPU on Windows before adding broad folder exclusions under C:\Users. On Windows 11, Microsoft's Dev Drive places active repositories and package caches on a dedicated ReFS volume where Defender runs in performance mode without turning protection off.
Where Mole for Windows fits
Mole for Windows separates rebuildable developer caches, idle project output, and AI coding tool data so they are never mixed into one blind delete button:
- Developer Tools inside Clean lists npm (
%LOCALAPPDATA%\npm-cacheand%APPDATA%\npm-cache), Yarn, pip, Poetry, NuGet, Go build, Scoop, and Cargo/rustup caches (registry\cache, unpackedregistry\src, andrustup\downloadsselected;cargo\gitcheckouts and unpinnedrustup\toolchainsunselected for review, honoring customCARGO_HOMEandRUSTUP_HOMEwhile never touching.cargo\binorregistry\index). Globalpnpmanduvstores stay with their ownpnpm store pruneanduv cache prunecommands so hardlinked store entries stay consistent. - Project Folders inside Clean scans fixed drives outside OneDrive and Dropbox for verified build output (
target,build,dist,.next,obj,__pycache__) and outermostnode_modulesdirectories of at least 100 MB that have gone untouched for 90 days next topackage.jsonand an npm, pnpm, or Yarn lockfile (bunwrites no install marker insidenode_modules, so Mole leavesbuntrees untouched). Every Project Folders row starts unselected, skips Git-tracked folders, keypair files, and any project with activenode,cargo,rustc, or open.exe/.dll/.nodehandles, and sends removed folders to the Recycle Bin. - Clicking the Moon on the Clean page opens AI Tool Cleanup & Care, which splits Caches and old versions (preselected caches plus non-active Claude Code, Codex, Cursor Agent, and GitHub Copilot CLI builds) from Chats (where Claude Code chats defaults to Don't list and moves to the Recycle Bin only if you pick an age window and tick it) and Removed tools (unchecked leftovers with no chats or skills). Meanwhile, Clean itself refuses
.claude\projects,.codex\sessions, andhistory.jsonl. If you prefer driving terminal previews through an agent, see how to use Claude Code or Codex to clean up Windows safely.
FAQ
Is it safe to delete node_modules on Windows to free up disk space?
Yes, for inactive projects that still have package.json and a lockfile (package-lock.json, pnpm-lock.yaml, yarn.lock, or bun.lock) and do not depend on a private registry you can no longer reach. Make sure no dev server or editor watcher is running in that repository, and move the folder to the Recycle Bin first rather than deleting it permanently.
What does cargo clean remove in a Rust project, and will it delete installed Cargo tools?
Running cargo clean inside a Rust workspace deletes only that project's target\ build artifacts, which often frees several gigabytes in a single repo. It does not touch binaries installed with cargo install inside %USERPROFILE%\.cargo\bin, and your code recompiles from source on the next cargo build.
Why do Claude Code and Codex use several gigabytes inside my Windows user folder?
Standalone AI coding CLIs download self-contained runtime binaries of roughly 250 to 480 MB on each update and frequently keep older release files on disk alongside debug logs and caches under %USERPROFILE%\.local\share\claude\versions and %USERPROFILE%\.codex. Removing non-active version binaries reclaims that space without touching your active CLI or chat transcripts.
Why does deleting node_modules or target take so long in File Explorer?
File Explorer enumerates permissions, calculates progress, and updates the UI across hundreds of thousands of small files while Microsoft Defender (MsMpEng.exe) scans file operations on NTFS. Using cargo clean for Rust projects, keeping active workspaces on a Windows 11 Dev Drive, or batching idle project cleanup avoids Explorer getting bogged down.
Does Mole for Windows delete node_modules or Claude Code chats automatically?
No. Project Folders (target, dist, .next, build, and 90-day-idle node_modules over 100 MB with a lockfile) always start unselected and go to the Recycle Bin when chosen, and Claude Code chats in AI Tool Cleanup & Care default to Don't list so session histories are never touched unless you opt in.