My C: drive was nearly full. Explorer said C:\WSL\Ubuntu\ext4.vhdx was 70 GB. Inside Linux, df -h said 40 GB used.
Thirty gigabytes of nothing.
The file that only grows
WSL 2 keeps each distro in a virtual disk, ext4.vhdx. When Linux writes data, the file grows. When you delete files inside Linux, the space is freed inside the filesystem, but the .vhdx file on Windows keeps its size. After months of npm install, pip install, Docker builds and VS Code server updates, the gap gets big.
This is a well-known issue: microsoft/WSL#4699 has over 1,400 reactions.
Why the usual fixes don't work for everyone
Optimize-VHD isn't on Windows Home. Most guides tell you to run Optimize-VHD -Mode Full. That cmdlet is part of the Hyper-V PowerShell module, which only exists on Pro, Enterprise and Education with Hyper-V enabled. On Home, the command simply doesn't exist.
Sparse mode isn't the answer yet. Newer WSL has wsl --manage <distro> --set-sparse true, which is supposed to release space automatically. It's experimental, off by default, and was disabled for a while after reports of corruption. Worse: once a disk is sparse, Optimize-VHD and compact vdisk refuse to touch it.
Deleting files alone does nothing for C:. You have to compact the file afterwards, with WSL fully shut down.
The manual fix that works everywhere
diskpart ships with every edition of Windows, including Home:
# inside the distro: free space, then tell the disk which blocks are free sudo apt-get clean rm -rf ~/.cache/pip ~/.npm/_cacache sudo fstrim -av # in Windows, as administrator wsl --shutdown diskpart select vdisk file="C:\path\to\ext4.vhdx" attach vdisk readonly compact vdisk detach vdisk exit The trap: not everything in ~/.cache is cache
"Just delete ~/.cache" is common advice. On a developer machine it can hurt:
-
~/.cache/huggingface/token: your Hugging Face login -
~/.cache/gh,~/.cache/claude: CLI auth and state -
~/.cache/deno/location_data: Deno KV databases and localStorage -
~/.cache/pypoetry/virtualenvs: every Poetry project's environment -
~/.cache/lm-studio: multi-GB local AI models
And on the Docker side, docker volume prune on an old Docker version (or anonymous volumes of a stopped postgres container) can delete database data.
I automated it, carefully
I got tired of doing this by hand, so I wrote wslim, a small open-source Windows tool (one 120 KB exe, no install, works on Home):
- Find: reads your WSL distros and their
.vhdxfiles from the registry. - Scan: pipes a rule catalog (a POSIX
shscript) into each distro. Each finding gets a tier:- safe: rebuilds itself (npm/pip/uv caches, old Claude Code and VS Code server builds, Docker build cache). Ticked.
- review: can be rebuilt but costs time or bandwidth (Go modules, Hugging Face models, unused Docker images). Not ticked.
- never touched: Docker named volumes, databases, project source,
~/.config, keys, logins.
- Clean: deletes a path only if it was in the scan you saw, you ticked it, and the rule still matches it now.
- Shrink: asks before stopping WSL, then runs
diskpart compact vdiskbehind one UAC prompt.
On my machine: 69.8 GB → 42.6 GB.
There's a command-line version too:
wslim-cli scan --json wslim-cli clean --preview wslim-cli clean --shrink Install with Scoop:
scoop bucket add 4riful https://github.com/4riful/scoop-bucket scoop install wslim or grab the exe from Releases.
The rules live in one file and are documented in docs/RULES.md. What eats space in your distros? I'd love rule suggestions, as comments here or as issues on GitHub.
