Skip to content
cleaning-wsl-docker logo

WSL2/Docker Disk Space Cleanup

cleaning-wsl-docker

Reclaims SSD disk space consumed by WSL2/Docker. Use when user reports disk space issues, Docker build failures due to space, or slow WSL performance. Handles Docker prune, cache cleanup, VHDX compaction, and prevention setup. MUST BE USED when "disk full", "out of space", or "VHDX" mentioned.

SKILL.md

Full skill instructions

WSL2/​Docker Disk Space Cleanup

Problem

WSL2 stores all data in ext4.vhdx files that:

  • GROW automatically when adding files/​building Docker images
  • NEVER SHRINK automatically when files are deleted
  • docker system prune frees space inside WSL but NOT on Windows SSD

Workflow

PHASE 1: Diagnose → PHASE 2: Cleanup → PHASE 3: Compact VHDX → PHASE 4: Prevent

PHASE 1: Diagnose

Check VHDX Size

# Find VHDX files and sizes
Get-ChildItem -Path "$env:LOCALAPPDATA" -Recurse -Filter "ext4.vhdx" -ErrorAction SilentlyContinue |
  Select-Object FullName, @{N='SizeGB';E={[math]::Round($_.Length/​1GB,2)}}

Check Docker Usage

wsl -e bash -c "docker system df -v"

PHASE 2: Cleanup (Inside WSL)

Docker Cleanup

wsl -e bash -c "
  docker stop \$(docker ps -aq) 2>/​dev/​null
  docker container prune -f
  docker image prune -a -f
  docker builder prune -a -f
  # CAUTION: Only if volumes are disposable
  # docker volume prune -f
  docker system df
"

Project Caches

wsl -e bash -c "cd /​mnt/​c/​path/​to/​project && \
  rm -rf .mypy_cache .pytest_cache .ruff_cache htmlcov __pycache__ && \
  find . -type d -name '__pycache__' -exec rm -rf {} + 2>/​dev/​null"

Unbounded Logs

wsl -e bash -c "rm -rf main/​logs/​traces/​* main/​logs/​workflow_test* main/​logs/​langfuse/​*"

PHASE 3: Compact VHDX (CRITICAL - Reclaims Windows Space)

IMPORTANT: This phase requires Administrator privileges. The AI agent CANNOT run diskpart directly. You MUST provide manual instructions to the user.

Step 1: Shutdown WSL (AI can run this)

wsl --shutdown
wsl --list --running  # Should show "no running distributions"

Step 2: Find VHDX Path (AI can run this)

Get-ChildItem -Path "$env:LOCALAPPDATA" -Recurse -Filter "ext4.vhdx" -ErrorAction SilentlyContinue | Select-Object FullName

Step 3: Update compact-wsl.txt Script

Edit .claude/​skills/​cleaning-wsl-docker/​compact-wsl.txt with the correct VHDX path:

select vdisk file="C:\Users\USERNAME\AppData\Local\wsl\{GUID}\ext4.vhdx"
attach vdisk readonly
compact vdisk
detach vdisk
exit

Step 4: MANUAL USER ACTION REQUIRED

Tell the user to run these commands in Administrator PowerShell:

1. Press Win + X
2. Click "Terminal (Admin)" or "PowerShell (Admin)"
3. Click Yes on UAC prompt
4. Run:

diskpart /​s "PROJECT_ROOT/​.claude/​skills/​cleaning-wsl-docker/​compact-wsl.txt"

If "file in use" error:

wsl --shutdown
taskkill /​F /​IM wslservice.exe
taskkill /​F /​IM wsl.exe
:: Wait 10 seconds, retry diskpart

Step 5: Verify (AI can run after user completes)

Get-ChildItem -Path "$env:LOCALAPPDATA" -Recurse -Filter "ext4.vhdx" | Select-Object FullName, @{N='SizeGB';E={[math]::Round($_.Length/​1GB,2)}}

PHASE 4: Prevent Future Bloat

Update .wslconfig

Add to C:\Users\USERNAME\.wslconfig:

[experimental]
sparseVhd=true           # Auto-reclaim space (WSL 2.0+)
autoMemoryReclaim=gradual

Then: wsl --shutdown to apply.

Weekly Maintenance

# Run in Admin PowerShell
wsl -e bash -c "docker container prune -f && docker image prune -a -f && docker builder prune -a -f"
wsl --shutdown
# Then run diskpart compact

Expected Recovery

ActionRecovery
Docker image prune2-10 GB
Docker builder prune10-100 GB
Cache cleanup200-500 MB
VHDX compaction5-50 GB

Checklist

  • Diagnose: Check VHDX size and Docker usage
  • Docker: Prune containers, images, build cache
  • Caches: Remove .mypy_cache, .pytest_cache, etc.
  • Logs: Clean unbounded log directories
  • WSL: Shutdown completely
  • VHDX: Compact using diskpart (Admin required)
  • Prevent: Enable sparseVhd in .wslconfig

More DevOps & CI/CD skills

Project scaffolding, deployment configuration, and CI/CD setup for Google ADK agents.

6K 472.6K
View

Set up tracing, logging, and monitoring for deployed ADK agents across Cloud Trace, BigQuery, and third-party platforms.

6K 472.6K
View

Enterprise Azure infrastructure architect generating Bicep or Terraform from workload descriptions.

1.5K 454.3K
View
azure-kubernetes logo
DevOps & CI/CD

azure-kubernetes

Plan and configure production-ready Azure Kubernetes Service clusters with Day-0 and Day-1 best practices.

1.5K 447.1K
View

Raw mechanical interfaces fusing Swiss typographic print with military terminal aesthetics. Rigid grids, extreme type scale contrast, utilitarian color, analog degradation effects. For data-heavy dashboards, portfolios, or editorial sites that need to feel like declassified blueprints.

92.7K 354.9K
View
just-scrape logo
DevOps & CI/CD

just-scrape

Web search, scraping, extraction, crawling, and monitoring via ScrapeGraph AI CLI.

69 245K
View

Skill for working with Firebase Hosting (Classic). Use this when you want to deploy static web apps, Single Page Apps (SPAs), or simple microservices. Do NOT use for Firebase App Hosting.

462 159.7K
View

Deploy and manage web apps with Firebase App Hosting. Use this skill when deploying Next.js/Angular apps with backends.

462 159.1K
View
deploy-to-vercel logo
DevOps & CI/CD

deploy-to-vercel

Deploy applications and websites to Vercel. Use when the user requests deployment actions like "deploy my app", "deploy and give me the link", "push this live", or "create a preview deployment".

31.9K 146.6K
View
programmatic-seo logo
DevOps & CI/CD

programmatic-seo

Build SEO-optimized pages at scale using templates, data, and proven playbook patterns.

53.3K 140.1K
View

Design and build isolated, reusable Convex backend components with clear boundaries and app-facing wrappers.

63 123.5K
View

Deploy and manage projects on Vercel using token-based authentication. Use when working with Vercel CLI using access tokens rather than interactive login — e.g. "deploy to vercel", "set up vercel", "add environment variables to vercel".

31.9K 116.1K
View

Coding & apps AI tools

Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View
Imagica logo
Coding & apps

Imagica

Build a no-code AI app in minutes.

Freemium
View
E
Coding & apps

Emergent.sh

An IDE for code migration from legacy to modern frameworks through coding agents.

Freemium
View
Wonder Dynamics logo
Coding & apps

Wonder Dynamics

Automate CGI animation in live-action scenes

Paid
View
M
Coding & apps

Mixo

Launch a website in seconds with AI.

Paid
View
AI Code Convert logo
Coding & apps

AI Code Convert

Streamline Your Coding Experience with AI Code Helper

Free
View