# Working with WSL: an honest field report with fixes

> WSL in everyday development: automatic updates, memory pressure, crash dumps and a VHDX that doesn't shrink by itself. What's behind them and what helps.

Source: https://www.jpkc.com/db/en/blog/wsl-erfahrungsbericht/

My favourite machines run Debian, Linux Mint and the latest macOS. For developers, I don't think there's anything better. At work, though, Windows is a given, and with it the Windows Subsystem for Linux, WSL for short. This blog, for example, is written under WSL 2: the projects live in the Linux file system, the browser runs on Windows.

I don't want to talk WSL down here. It's a fine piece of engineering, and for the most part it works well. But it doesn't replace a full Linux server, a Linux workstation or a Mac. And it has quirks that can cost you a running session or fill up your Windows drive without you doing anything wrong. I've run into four of them myself: updates that end everything, memory management with pitfalls, crash dumps in the temp folder and a virtual disk that only grows.

For each of these problems you'll find what's behind it, what to set up in advance and what to do once it has happened. At the end there's a commented `.wslconfig` and a checklist. Where I rely on Microsoft's documentation, it says "according to the docs". Where the docs are out of date and only the source code in the [WSL repository](https://github.com/microsoft/WSL) helps, it says "according to the source code". What I looked up on my own machine is marked "on my machine" or "checked".

## The short version

| Problem | What's behind it | What helps |
| --- | --- | --- |
| **Updates end all sessions** | Since WSL 3.0.1 the package registers with Windows Update. On Windows 11 26H2 the update arrives that way without asking. The installer stops the WSL service and with it the whole VM | There's no reliable switch against it. Commit often, keep sessions resumable, check `wsl --version` after the update |
| **Memory pressure paralyses WSL** | By default the VM gets half of the Windows RAM. Under pressure the OOM killer ends processes, and WSL may refuse new sessions | Set `memory=` and `swap=` deliberately, limit big jobs, then `wsl --shutdown` |
| **Crash dumps fill C:** | WSL catches every crash of a Linux process and keeps up to 10 images in `%TEMP%\wsl-crashes` | `maxCrashDumpCount=2` or `-1` (off) under `[wsl2]`. Careful: `0` means "unlimited" |
| **The VHDX doesn't shrink by itself** | The `ext4.vhdx` grows up to 1 TB but never hands deleted space back on its own | Clean up, then compact: diskpart, `Optimize-VHD` or the new `wsl --manage <Distro> --compact` |

All of this refers to WSL 3.0.5 (package version of 3 November 2026, the distributions run as WSL 2) on Windows 11 26H2, as of 26 November 2026. There's no "WSL 3" as a new architecture. The 3 is just the package version number.

## How WSL 2 works under the hood

Most of the problems are easier to understand once you know the basic principle. According to Microsoft, WSL 2 is a "lightweight utility virtual machine": a small VM managed by Windows with a real Linux kernel. **All your distributions run in the same VM.** They share kernel, CPU, memory, swap and network, and have their own PID, mount, user and cgroup namespaces plus their own init process ([Microsoft: What is WSL?](https://learn.microsoft.com/en-us/windows/wsl/about)).

Three things follow from that:

- **Each distribution lives in its own virtual disk**, the file `ext4.vhdx` on your Windows drive. Linux sees an ordinary ext4 file system in it.
- **There are two configuration files.** `%UserProfile%\.wslconfig` applies globally to the VM, so to all distributions. `/etc/wsl.conf` applies only to the distribution it lives in ([Microsoft: Advanced settings configuration](https://learn.microsoft.com/en-us/windows/wsl/wsl-config)).
- **`wsl --shutdown` ends the VM** and with it every distribution, immediately. Only then do changes to `.wslconfig` take effect. I do this after every change, and it works reliably. The docs talk about an "8 second rule" after which WSL stops on its own. With today's idle timeouts of 15 seconds for the distribution and 60 seconds for the VM, it takes longer than that. `wsl --shutdown` is unambiguous.

Microsoft recommends changing settings in the "WSL Settings" app from the Start menu rather than in the file, by the way. For a commented template like the one at the end of this article, though, the file is more practical.

## What WSL does well

Before we get to the problems: if you have to use Windows, WSL gives you a lot, and most of it works well.

- **Linux tools without dual booting.** According to Microsoft, WSL needs less CPU, memory and storage than a full VM, and you work with Linux and Windows programs on the same files ([FAQ](https://learn.microsoft.com/en-us/windows/wsl/faq)).
- **File access in both directions.** In Linux, `C:` is at `/mnt/c`. In Windows you reach the distribution via `\\wsl.localhost\<Distro>\`. `explorer.exe .` opens the current Linux folder in Explorer, and `wslpath` translates paths back and forth.
- **Windows programs from the Linux shell** and Linux commands from PowerShell (`wsl <command>`), plus Linux GUI apps through WSLg.
- **systemd** if you want it, switched on with `[boot]` `systemd=true` in `/etc/wsl.conf` ([Microsoft: systemd](https://learn.microsoft.com/en-us/windows/wsl/systemd)). I have it switched on, and Docker and other services run with it largely as they would on a normal Linux. The exceptions come further down.
- **IDEs that take WSL seriously.** VS Code with the WSL extension starts a small server inside the distribution while the UI stays on Windows. JetBrains IDEs can open projects in the WSL file system.
- **Docker, and now containers of its own.** Docker Desktop uses WSL 2 as its foundation. Since WSL 3.0.1, `wslc.exe` is also generally available, a built-in container command line without a separate engine. It was already there as a preview from 2.9.3 ([Microsoft: WSL containers](https://learn.microsoft.com/en-us/windows/wsl/tutorials/wsl-containers)).
- **Networking and hardware.** The mode `networkingMode=mirrored` mirrors the Windows network interfaces into Linux, which helps with VPNs, IPv6 and access from the LAN (Windows 11 22H2 and later). CUDA runs with the normal Windows driver, and you pass USB devices through with usbipd-win.
- **Claude Code with a sandbox.** According to the docs, Claude Code's sandbox runs on macOS, Linux and WSL 2, but not on native Windows ([Sandboxing](https://code.claude.com/docs/en/sandboxing)). If you want the sandbox on Windows, there's no way around WSL 2.
- **Open source.** WSL has been open source since 19 May 2025 ([announcement](https://blogs.windows.com/windowsdeveloper/2025/05/19/the-windows-subsystem-for-linux-is-now-open-source/)), under the [MIT licence](https://github.com/microsoft/WSL/blob/master/LICENSE). Only the WSL 1 driver and the file redirection for `\\wsl.localhost` stay closed; both are part of Windows. That came in handy several times for this article: where the docs lag behind, the code shows what really happens.

One rule I'll give you right here because it makes such a difference: **put your projects in the Linux file system**, in `~/…`, not in `/mnt/c/…`. Access across the boundary goes through the 9P protocol under WSL 2 and is much slower. Microsoft calls exactly this "the most common performance mistake" ([WSL interop](https://learn.microsoft.com/en-us/windows/dev-environment/wsl-interop)).

And Microsoft itself says what WSL was built for: "inner loop development workflows", the development loop on your own machine. Microsoft doesn't rule out production, but recommends the WSL container API for it. The VM starts and stops automatically, and the kernel is updated automatically ([FAQ](https://learn.microsoft.com/en-us/windows/wsl/faq)). That automation is exactly where the first problem starts.

## Problem 1: Updates that end running sessions

### What happens

You're working, a build is running, a coding agent is in the middle of a task. Suddenly the terminal closes, VS Code loses its connection, and the Claude Code session is gone. There was no warning, and Windows didn't restart either. WSL updated itself in the background and ended everything in the process.

On my machine, Event Viewer shows the installation of "Windows Subsystem for Linux 3.0.5.0 (x64)" via Windows Update. In the same time window the WSL service was disabled and reinstalled, and the distribution's journal ends a few seconds later with a shutdown (checked).

### Why

WSL no longer ships with Windows itself but as a separate package. The Microsoft Store used to update that package automatically. **Since WSL 3.0.1, and in pre-releases even earlier, the package also registers with Windows Update according to the source code**, and the repository has its own release stage for it. For Windows 11 26H2 there's evidence that the update arrives this way without asking, reported for example in [issue #42237](https://github.com/microsoft/WSL/issues/42237) (open). For older Windows versions there's no such report in the issues so far. None of this is in Microsoft's docs yet, which still talk about the Store.

The installer itself shows why an update ends all sessions. On every upgrade it stops the `WSLService` service, which hosts the VM, and forces programs that use files of the update to exit (according to the source code: `Stop="both"` and `MSIRMSHUTDOWN=1`). When the service ends, the VM ends, and with it every process in every distribution: shells, editor servers, Docker, agents.

A maintainer once wrote in an issue: "WSL never 'decides' to update itself" ([#13138](https://github.com/microsoft/WSL/issues/13138)). Strictly speaking, that's true. The trigger comes from the Store or Windows Update. Sitting at your machine, it feels the same anyway.

### Prevention: what you can control and what you can't

I'll be frank: **there's currently no reliable, supported switch against automatic WSL updates.** Neither `.wslconfig` nor the Intune or Group Policy settings for WSL have one. What circulates online only helps to a degree:

- **Pausing Store updates** only works for all Store apps together and only for one to five weeks ([Microsoft Support](https://support.microsoft.com/en-us/account-billing/keep-apps-and-games-up-to-date-with-the-microsoft-store-db1434f0-63f9-4331-97bc-a97d5326ccd2)). It does nothing about the Windows Update route.
- **Active hours in Windows Update** only control Windows restarts. The WSL update needs no restart, so active hours don't protect your session. Whether "Pause updates" holds back the WSL package isn't documented anywhere.
- **The registry value `AutoUpgradeViaMsix`** was never supported, and according to a collaborator on the WSL repository it has had no effect since the switch to Windows Update ([discussion #12675](https://github.com/microsoft/WSL/discussions/12675)).
- **`winget pin`** only affects winget itself.

One bright spot: an open pull request in the WSL repository proposes cancelling automatic installations while WSL is busy ([#42293](https://github.com/microsoft/WSL/pull/42293)). Whether and when it lands remains to be seen.

Until then, the remedy lies in how you work:

- **Commit often.** Better one `wip:` commit too many than an hour of work that only existed in the head of an aborted agent. Claude Code's checkpoints don't capture everything: files changed only by Bash commands and most edits by subagents are missing. According to the docs, they're explicitly not a replacement for Git ([Checkpointing](https://code.claude.com/docs/en/checkpointing)).
- **Name your Claude Code sessions**, with `claude -n <name>` or `/rename`. Then `claude --resume <name>` finds them straight away after an abort.
- **Make long jobs resumable**: write intermediate results to disk, and design steps so that a second run doesn't break anything.
- **Don't rely on tmux.** The tmux server is a process inside the VM. When the VM ends, all tmux sessions are gone. tmux only protects against closed terminal windows.

### Afterwards

1. **Check the version:** `wsl --version` shows what's installed now. The [release notes](https://github.com/microsoft/WSL/releases) tell you what changed.
2. **Start WSL again.** After an update the distributions stay stopped until you start them. Services, Docker and autostart scripts only run again after that.
3. **Resume Claude Code:** `claude --continue` in the same directory opens the last session, and `claude --resume` shows a picker. The history survives because Claude Code writes it to disk continuously. But the tool call that was running at the time of the abort is **not** rerun, and background tasks are gone ([Sessions](https://code.claude.com/docs/en/sessions)). You pass start options such as `--add-dir` again. After an abort, ask Claude to check the last step before it carries on.
4. **Check the state of your work:** `git status` and `git diff` show what wasn't committed. Files that were being written at the time may be half finished.

Related, but not an update issue: WSL shuts down a distribution after 15 seconds without an open session, and the VM after another 60 seconds. systemd services on their own don't keep it alive. If you need a service without an open terminal, there's `instanceIdleTimeout` under `[general]` (`-1` turns it off) and `vmIdleTimeout` under `[wsl2]` (Windows 11 only).

## Problem 2: Memory, when the VM gets tight

### What happens

A big build, a broad search or several agents at once, and WSL turns sluggish. Processes vanish without a word, new terminals no longer open, VS Code loses its connection. Calls to Windows programs from the shell hang and end with `UtilAcceptVsock … accept4 failed 110`. From the outside it looks like WSL crashed.

### Why

According to the docs, the VM gets **50 percent of the Windows memory** by default, with no upper limit. Swap, according to the docs, is 25 percent of the Windows RAM. According to the source code, however, WSL 3.0.5 calculates 25 percent of the VM memory, rounded up to whole GB. That's exactly what my machine shows too (checked). In practice you usually have less swap than the docs promise.

When memory runs short, three things come together:

- **The OOM killer inside the VM** ends a process, usually the biggest one. That's normal Linux behaviour and the most common case. With a coding agent it often hits the very search, the language server or the agent itself. A process ended this way leaves no crash dump.
- **WSL stops accepting new sessions.** The VM keeps running, but the channel between Windows and Linux can no longer be set up. The kernel needs a large contiguous block of memory for it and can't find one. This happens under memory pressure, but according to the reports mostly with fragmented memory, that is, even when RAM is still free. A bigger `memory=` therefore doesn't reliably prevent it. This is what produces the `accept4 failed 110` messages. It's also reported for WSL 3.0.3 in [issue #40795](https://github.com/microsoft/WSL/issues/40795) (open). A maintainer writes: "We've seen multiple reports on hvsockets getting into a bad state when the guest runs out of memory" ([#41901](https://github.com/microsoft/WSL/issues/41901)). The matching kernel message is in the log on my machine (checked). So far, only `wsl --shutdown` helps.
- **Windows doesn't get the memory back.** Linux uses free RAM as a file cache, and to Windows that memory is in use. In Task Manager you see it in the `vmmemWSL` process (`vmmem` on Windows 10). WSL only releases the cache once the VM has done almost nothing for two minutes (according to the source code since 3.0.1, in pre-releases since 2.9.8). Memory that a program really holds is not given up by WSL on its own when Windows is under pressure: "this isn't something that WSL can solve", a maintainer writes in [#41875](https://github.com/microsoft/WSL/issues/41875).

It's also fair to say that Microsoft has improved things. Before version 3.0.1 (before 2.9.8 for pre-releases), heavy memory load could hit WSL's own processes and put the whole instance into an error state. Since then, WSL puts your processes into a cgroup of their own and keeps a small reserve of 32 MiB for itself ([PR #40519](https://github.com/microsoft/WSL/pull/40519)). For 3.0.x, I found only a single report of the whole VM actually crashing from lack of memory.

### Prevention

- **Set `memory=` deliberately** (section `[wsl2]`). Not too tight: in [issue #40458](https://github.com/microsoft/WSL/issues/40458), 2 GB weren't enough for a big build. Not too generous either: Windows needs room alongside, or programs there start to stutter.
- **Choose a suitable `swap=`.** Swap absorbs peaks before the OOM killer strikes.
- **`autoMemoryReclaim` belongs under `[experimental]`**, not under `[wsl2]`. If you put it there, WSL only reports "Unknown key". The default `dropCache` is fine for most people.
- **Don't add `pageReporting` any more.** The key has disappeared from the docs, and the feature is now always on. Older guides with `pageReporting=false` are out of date.
- **Limit Node tools.** Many language servers and build tools run on Node. With `NODE_OPTIONS=--max-old-space-size=<MiB>` you limit the JavaScript heap of a Node process ([Node.js docs](https://nodejs.org/api/cli.html#--max-old-space-sizesize-in-mib)).
- **Scope your searches.** Under WSL, the Claude Code docs recommend naming specific directories and file types. They give slow reads across file system boundaries as the reason ([Troubleshooting](https://code.claude.com/docs/en/troubleshooting)). For me, memory is another reason.

### What I tell my agents

These days I tell my agents to keep an eye on resource usage. For most workflows the Claude Code docs recommend three to five parallel teammates, citing tokens and coordination ([Agent teams](https://code.claude.com/docs/en/agent-teams)). Under WSL, I add memory to those reasons. Something along these lines is in my instructions:

```markdown title="Excerpt: rules for agents under WSL (paraphrased)"
## Resources on this machine (WSL 2)

- Run at most 3 subagents at the same time. Use more, e.g. 6,
  only when I tell you to. I do that when the machine is mostly idle.
- Before heavy builds, test suites or broad searches, check memory
  and disk first. If memory is low, say so and wait.
- Scope every search: name the directory and file type, exclude
  node_modules, vendor, .git and build output.
- Do not wait for background jobs in your own sleep loops.
- If a project has tens of thousands of source files, tell me before
  you open files that start a language server.
```

So my default is three agents. When there's little going on on the machine, I sometimes tell them to use six in parallel. On top of that, I've built helper functions into my own CLI, which I wrote in Go. Among them is a system monitor the agents can query: memory, disks, CPU and swap, each with a warning level. Matching skills explain to the agents when to slow down. It's not rocket science, but this way the agents can see for themselves when things are getting tight.

### Afterwards

1. **Look for traces.** `journalctl -k -b -1 | grep -E 'Out of memory|oom-kill'` shows OOM kills in the previous start of the VM, `dmesg` the current one. The line names the process and its memory use.
2. **Read `free -h` correctly.** What counts is the `available` column, not `free`. A lot of `buff/cache` is file cache that gets freed as soon as it's needed.
3. **If the terminal and `wsl.exe` hang**, search the kernel log for `page allocation failure` with `vmbus_alloc_ring` and the journal for `accept4 failed`. That's the pattern from issue #40795. Then end the VM with `wsl --shutdown`. That stops all distributions but gives Windows all the memory back.
4. **"Catastrophic failure" is no proof of a memory shortage.** According to [Microsoft](https://learn.microsoft.com/en-us/windows/wsl/troubleshooting), error code `0x8000FFFF` has many causes. Check the kernel log first.
5. **Claude Code itself** warns once its heap passes 2.5 GB. According to the docs, a restart with `claude --continue` helps then.

## Problem 3: Crash dumps fill the Windows drive

### What happens

The temp folder on Windows keeps growing, even if you clean up regularly. Most of it sits in `%TEMP%\wsl-crashes`: files following the pattern `wsl-crash-<timestamp>-<PID>-_usr_bin_node-6.dmp`, each one or several gigabytes in size.

The example that got me onto this topic: a coding agent started a PHP language server (Intelephense, a Node program) in the background as soon as it touched a PHP file. The project tree contained tens of thousands of PHP files. The server tried to index all of them, ran past Node's heap limit and aborted. Each time, WSL wrote a dump of around 2.8 GB, the agent restarted the server, and the whole thing started over. Before long, more than 20 GB had piled up. No bug in the code, no user error, just three automatic mechanisms reinforcing each other.

### Why

- **WSL collects crashes.** Since version 2.3.17 (mid-2024), WSL writes a pipe to a helper of its own into `/proc/sys/kernel/core_pattern`: `|/wsl-capture-crash %t %E %p %s`. When a Linux process dies from a signal such as SIGSEGV or SIGABRT, its memory image ends up in `%TEMP%\wsl-crashes` on Windows.
- **Up to 10 images are kept.** That's the default of `maxCrashDumpCount`.
- **The files are often larger than the process.** Through a pipe the kernel can't skip gaps in memory and writes them as real zero bytes. In [issue #41314](https://github.com/microsoft/WSL/issues/41314), a single dump was 58 GiB. Together with the dumps next to it, C: filled up to 0 GiB free. Microsoft closed the issue as "by design": "Unfortunately you're seeing the expected behavior."
- **`ulimit -c 0` doesn't help.** With a pipe in `core_pattern`, the kernel ignores this limit ([core(5)](https://man7.org/linux/man-pages/man5/core.5.html)). On my machine `ulimit -c` is 0, and there are still dumps in the folder (checked).
- **Crash loops multiply this.** Claude Code restarts a crashed language server by default (`restartOnCrash` is `true`). If it only crashes while indexing, that is, after a successful start, the next dump comes with the next request.

### Prevention

The most important line goes into `.wslconfig`, section `[wsl2]`:

```ini title="%UserProfile%\.wslconfig (excerpt)"
[wsl2]
# Keep at most 2 crash dumps in %TEMP%\wsl-crashes (default: 10)
maxCrashDumpCount=2
```

Then `wsl --shutdown`. Two subtleties that aren't in Microsoft's docs:

- **`-1` turns collection off completely.** Maintainers confirm this in issues [#12147](https://github.com/microsoft/WSL/issues/12147) and #41314, and the source code backs it up. But then there are no dumps either if you want to report a bug to Microsoft.
- **`0` doesn't mean "off" but "unlimited".** According to the source code, since version 2.7.0 WSL deletes no old dumps at all with `0`. It's an easy mix-up, and it fills the drive even faster.

Optionally, you move the folder to another drive with `crashDumpFolder=D:\\wsl-crashes`, with double backslashes. That protects C: but doesn't save any space.

The only real fix for the cause is preventing the loop. For language servers that means: the bigger the tree they're asked to index, the sooner they hit their memory limit. Narrow down the working folder or exclude large subtrees. Where that isn't possible, switch off the language server plugin for that project only, for example with `claude plugin disable php-lsp@claude-plugins-official --scope local` in the project folder. Without `--scope` the command usually applies to all projects. Claude then uses its built-in search tools.

### Afterwards

1. **Look at the folder:** open `%TEMP%\wsl-crashes` in Explorer. The file name gives the program and the signal: `-6` is SIGABRT, `-11` SIGSEGV. A language server on Node doesn't show up under its own name but under the path of the Node binary, for example as `_usr_bin_node` for a Node installed by the package manager.
2. **Find the culprit:** `file <dump>` shows the command line of the crashed process, truncated. `head -c 3000000 <dump> | strings -n 6 | head` gives you more.
3. **Fix the cause first, then delete.** As long as the loop is running, the dumps come straight back.
4. **Delete the dumps.** Finished dumps are ordinary files that WSL only keeps for debugging. A dump that's still being written is locked. Be careful when sharing them: a memory image can contain credentials and tokens.
5. **After lowering the limit, clean up by hand once.** According to the source code, WSL only deletes one old dump per new one. If there are already nine in the folder, it stays at nine.
6. **Leave `swap.vhdx` alone.** The swap file of the running VM also lives in the temp folder or a subfolder of it. WSL deletes it itself on shutdown. If you clean `%TEMP%` wholesale, exclude it.

Whether Windows Disk Cleanup covers the `wsl-crashes` folder isn't documented by Microsoft. On my machine it didn't. So don't rely on it.

## Problem 4: The virtual disk grows and doesn't shrink

### What happens

In Linux, `df -h /` still shows plenty of space, but on Windows C: keeps filling up. You delete a few Docker images in the distribution, and nothing changes on Windows. On my machine the `ext4.vhdx` is currently around 27 GiB larger than what Linux uses.

### Why

The `ext4.vhdx` is a dynamic virtual disk. It grows as needed, by default up to 1 TB ([Microsoft: Disk space](https://learn.microsoft.com/en-us/windows/wsl/disk-space)). When you delete files in Linux, the blocks become free in the file system, but the file on Windows stays the same size. The feature request "WSL 2 should automatically release disk space back to the host OS" has been open since 2019 ([#4699](https://github.com/microsoft/WSL/issues/4699)).

Where the file lives depends on how you installed the distribution:

- **From the Store:** `%LOCALAPPDATA%\Packages\<package name>\LocalState\ext4.vhdx`
- **With `wsl --install` in newer versions:** `%LOCALAPPDATA%\wsl\{GUID}\ext4.vhdx`

The reliable way to find the folder is Microsoft's read-only PowerShell one-liner:

```powershell
(Get-ChildItem -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss | Where-Object { $_.GetValue("DistributionName") -eq 'Ubuntu' }).GetValue("BasePath") + "\ext4.vhdx"
```

Replace `Ubuntu` with the name from `wsl -l -v`. Microsoft explicitly advises against touching the WSL files in `AppData` with Windows tools, by the way, because that can corrupt the distribution. With diskpart or `Optimize-VHD` you can't avoid it, though. Without Windows tools it only works with the new `wsl --manage --compact` (see below). All the more reason to make a backup first.

### Prevention

- **Clean up regularly**, before things get tight: `docker system df` shows what Docker is using. `sudo apt clean` empties the package cache. `sudo journalctl --vacuum-size=200M` trims archived journals. You empty the pip and npm caches with `pip cache purge` and `npm cache clean --force`.
- **Know that TRIM is already running.** WSL mounts the distribution with the `discard` option, so ext4 reports free blocks to the virtual disk straight away (checked). The file doesn't get smaller because of it, though. Ubuntu's weekly `fstrim.timer` doesn't even run under WSL, because systemd detects WSL as a container (checked).
- **Put new distributions somewhere else** if C: is short on space: with `wsl --install --location <path>` or `distributionInstallPath=` under `[general]`. `defaultVhdSize=` under `[wsl2]` caps the maximum size of new disks.

**What about sparse?** WSL can keep a VHDX as a sparse file, which is then supposed to shrink automatically: `wsl --manage <Distro> --set-sparse true` with the distribution stopped, or `sparseVhd=true` under `[experimental]` for new disks. From version 2.5.6 to 3.0.1, Microsoft had blocked this because of "potential data corruption", and it only worked with `--allow-unsafe`. Since 3.0.2 it works without it again, but with a warning that the feature is experimental. Microsoft hasn't published a cause for the reported data damage, and the big issue about it is still open ([#10609](https://github.com/microsoft/WSL/issues/10609)). My data matters too much to me, so I'd rather compact by hand now and then. If you want to try it anyway, make a backup with `wsl --export` first (as in step 0 below).

### Afterwards: shrinking the disk

Compacting only gives back free space. If you want to get below the space in use, clean up first. `sudo du -xh --max-depth=1 / 2>/dev/null | sort -h` shows what takes up the space. `sudo ncdu -x -r /` is more convenient (install it with `sudo apt install ncdu`). `-x` stays on the distribution's disk and doesn't wander into `/mnt/c`, and `-r` blocks deleting from within ncdu. Typical space hogs are Docker images, build caches, old `node_modules` folders and logs. Look closely before running `docker system prune -a`: the command deletes all stopped containers along with their data, all unused networks, all images not used by a running container and the whole build cache. It can't be undone. Back up anything you still need from stopped containers first. With `--volumes`, anonymous volumes are removed as well; named volumes are kept.

Here's how I go about it.

**Step 0: backup.** `wsl -l -v` shows the distribution's name. Careful: `wsl --export` ends the running distribution immediately and without asking, just like `--compact` further down. Save your work first and end open sessions, such as Claude Code. Ideally export to another drive, since C: is short on space anyway:

```powershell
wsl --export Ubuntu E:\backup\ubuntu.tar
```

**Step 1, optional: trim.** Inside the distribution, `sudo fstrim -av` reports all free blocks once more. Since WSL already works with `discard`, this is more of a safeguard than a big gain.

**Step 2: shut WSL down completely.** First quit Docker Desktop (entirely, not just the window), close VS Code windows with a WSL connection and terminal tabs with a WSL profile. An Explorer window on `\\wsl.localhost` can also start the distribution again on Windows 11. Then, in PowerShell:

```powershell
wsl --shutdown
wsl --list --running
```

The second line has to report that no distribution is running any more: "There are no running distributions."

**Step 3: compact with diskpart.** Open a Command Prompt or PowerShell **as administrator** and start `diskpart`. Then type at the `DISKPART>` prompt:

```text title="diskpart"
select vdisk file="C:\Users\<user>\AppData\Local\Packages\<package name>\LocalState\ext4.vhdx"
attach vdisk readonly
compact vdisk
detach vdisk
exit
```

The path in the block applies to a distribution from the Store. After `wsl --install` it's `C:\Users\<user>\AppData\Local\wsl\{GUID}\ext4.vhdx`. The safest option is to paste the output of Microsoft's one-liner. If it starts with `\\?\`, leave that out. Write the path out in full. According to the [docs](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/select-vdisk), diskpart expects the full path, and `%LOCALAPPDATA%` as a shortcut isn't provided for there. You need the quotes as soon as the path contains spaces. According to the docs, `attach vdisk readonly` is optional; `compact vdisk` also works on a detached file. The process takes a few minutes. Don't interrupt it, and don't start WSL in the meantime. If Windows prompts you with "Initialize Disk" or asks you to format the disk, always cancel. Either would wipe the distribution. And because diskpart is a general-purpose tool: check the path at `select vdisk` twice. After an error message, don't keep typing, type `exit`.

diskpart is also the way to go on **Windows Home**. Microsoft doesn't restrict it to particular editions anywhere, and in issue #4699 several users report success on Home.

**Alternative with Hyper-V (Pro and Enterprise):** `Optimize-VHD -Path <path>\ext4.vhdx -Mode Full` in an administrator PowerShell. On Home there's no Hyper-V module. A subtlety from the [docs](https://learn.microsoft.com/en-us/powershell/module/hyper-v/optimize-vhd): if the file isn't attached read-only, `-Mode Full` automatically runs in `Prezeroed` mode. And the command reports success even when it couldn't shrink anything.

**New in WSL 3.0: `wsl --manage <Distro> --compact`.** Since the 3.0 versions, WSL comes with a command of its own. According to the source code, it checks the file system offline (`e2fsck -E discard`, so it frees blocks the way `fstrim` does) and then compacts via the Windows virtual disk API. According to the source code, it needs neither admin rights nor Hyper-V. Two things you need to know: it **ends the running distribution without asking**, and it isn't in Microsoft's docs yet. I haven't tried it for this article. As long as it isn't documented, I'll stick with diskpart, the route I use regularly.

**Docker Desktop has a disk of its own.** These days it lives at `%LOCALAPPDATA%\Docker\wsl\disk\docker_data.vhdx`, in older installations at `…\Docker\wsl\data\ext4.vhdx`, and it grows just the same. Docker used to give space back automatically on exit but "temporarily disabled" that in version 4.59.0 ([release notes](https://docs.docker.com/desktop/release-notes/)). `wsl --manage --compact` doesn't reach this file because it isn't a registered distribution. That leaves diskpart or `Optimize-VHD`, with Docker Desktop quit and after `wsl --shutdown`. The `wsl --export` from step 0 doesn't back this file up. So copy `docker_data.vhdx` to another drive first, which is also what Docker's [backup guide](https://docs.docker.com/desktop/settings-and-maintenance/backup-and-restore/) suggests.

## More stumbling blocks, briefly

- **Slow builds under `/mnt/c`.** See above: projects belong in the Linux file system. With VS Code and the WSL extension, you edit them there as comfortably as if they were on Windows.
- **Wrong time after sleep.** The VM's clock can fall behind after standby. `sudo hwclock -s` sets it right again. On Ubuntu 24.04 the program is missing, though; you add it with `sudo apt install util-linux-extra`. Without installing anything, `wsl --shutdown` helps. Don't run a time service of your own alongside Hyper-V's time synchronisation; the two would compete. And measure run times with a monotonic clock, not the wall clock. Under WSL 2 the system time can even jump backwards, as I showed in the [article on Bun and Claude Code](https://www.jpkc.com/db/en/blog/bun-anthropic-claude-code/).
- **Windows programs no longer start from the shell**, and you see `UtilAcceptVsock … accept4 failed 110`. Often after waking from standby or under memory pressure (see problem 2). The fix is `wsl --shutdown`. If Docker Desktop is running, quit it first and restart it afterwards.
- **No network or DNS with a VPN.** Leave `dnsTunneling` on; it's the default under `[wsl2]`. If that doesn't help, try `networkingMode=mirrored`, and check Microsoft's list of known VPN problems ([Troubleshooting](https://learn.microsoft.com/en-us/windows/wsl/troubleshooting)).
- **Line endings and file permissions.** Work on a repository from one side only, and add a `.gitattributes` with `* text=auto eol=lf`. Real Linux permissions on `C:` are only available with the `metadata` mount option in `/etc/wsl.conf`.

## My `.wslconfig` template

Here's a `.wslconfig` you can start with. The values are a starting point for a developer PC with 32 GB of RAM. With 16 GB, halve `memory` and `swap`.

```ini title="%UserProfile%\.wslconfig"
[wsl2]
# RAM for the WSL VM (default: 50% of Windows RAM, no upper limit).
# Leave Windows enough for browser, IDE and Teams.
memory=12GB
# Swap file (default per source code: 25% of the VM memory,
# rounded up to whole GB). Catches peaks before the OOM killer.
swap=4GB
# Keep at most 2 crash dumps in %TEMP%\wsl-crashes (default: 10).
# -1 turns collection off. 0 means "no limit", not "off".
maxCrashDumpCount=2
# Optional: keep crash dumps off the system drive.
# crashDumpFolder=D:\\wsl-crashes

[experimental]
# Return the Linux page cache to Windows when the VM is idle.
# dropCache is the default, gradual releases it step by step.
autoMemoryReclaim=dropCache
```

Then `wsl --shutdown`. What does **not** belong in it: `pageReporting` (no longer exists), `autoMemoryReclaim` under `[wsl2]` (wrong section) and `systemd=true` (belongs in the distribution's `/etc/wsl.conf`). You check whether your values arrived with `free -h` inside the distribution.

## Checklist

**Prevention:**

- [ ] Create `.wslconfig` with `memory`, `swap` and `maxCrashDumpCount`, then `wsl --shutdown`
- [ ] Projects in the Linux file system, not under `/mnt/c`
- [ ] Commit often, name your Claude Code sessions
- [ ] Limit big jobs and parallel agents, scope your searches
- [ ] Language servers only in lean project folders
- [ ] Clean up inside the distribution regularly (Docker, apt, journal, caches)
- [ ] Back up with `wsl --export` before working on the VHDX

**When it has happened:**

- [ ] Session gone without a restart: `wsl --version`, then `claude --continue` or `--resume`, `git status`
- [ ] Terminals hang: search the kernel log for OOM and `accept4 failed`, then `wsl --shutdown`
- [ ] Temp folder full: look at `%TEMP%\wsl-crashes`, fix the cause, delete the dumps, leave `swap.vhdx` alone
- [ ] C: full: clean up, back up with `wsl --export`, `wsl --shutdown` and check with `wsl --list --running`, then compact the VHDX with diskpart or `Optimize-VHD`, don't forget the Docker disk

## Conclusion

For me, WSL is no replacement for a real Linux machine or a Mac, and I don't think Microsoft means it to be one. It's a tool for the development loop on Windows, and as such it's well equipped by now: systemd, mirrored networking, GPU, built-in containers, open source. The problems aren't user errors but consequences of a VM being expected to behave like a piece of Windows. It updates like Windows, it shares memory with Windows, it stores its crashes and its disk on Windows.

With a well-tuned `.wslconfig`, a few habits and agents that watch the resources, WSL is a reliable compromise for me. If you have to develop on Windows, you can work well with it. Just know its limits before they catch you out in the middle of your work.

## Frequently asked questions

### Can I turn off automatic WSL updates?

Not reliably. Since WSL 3.0 the package also comes via Windows Update, and neither `.wslconfig` nor the WSL policies have a switch for it. The Store pause applies to all Store apps and lasts five weeks at most. What's left: commit often and run your sessions so that you can resume them.

### What's the difference between `maxCrashDumpCount=0` and `-1`?

`-1` turns dump collection off completely. `0`, by contrast, has meant no limit since WSL 2.7.0, according to the source code, so WSL then deletes no old dumps at all. For "only a few dumps", use a small positive number such as `2`.

### Is it safe to delete the files in `%TEMP%\wsl-crashes`?

Yes, finished dumps are ordinary files that WSL only keeps for debugging. But leave the `swap.vhdx` in the temp folder alone while WSL is running, and fix the cause first. Otherwise the dumps come straight back.

### Why does `df` in WSL show so much free space even though C: is full?

`df` shows the maximum size of the virtual disk, 1 TB by default, not the free space on C:. The `ext4.vhdx` grows as needed and doesn't shrink by itself. You only get the space back by compacting.

### Do I need Windows Pro to shrink the disk?

No. `Optimize-VHD` needs the Hyper-V module and therefore Pro or Enterprise. diskpart is also available on Home; Microsoft doesn't restrict it to any edition, and users report success there. You only need admin rights.

## Further reading

The most important `wsl` commands are in the [WSL cheat sheet](https://www.jpkc.com/db/en/cheatsheets/shell-system/wsl/), graphics support in the [WSLg cheat sheet](https://www.jpkc.com/db/en/cheatsheets/shell-system/wslg/). How cmdlets such as `Get-ChildItem` and `Where-Object` from the one-liner above work together is shown in the [PowerShell cheat sheet](https://www.jpkc.com/db/en/cheatsheets/shell-system/powershell/). How to lock Claude Code into a container with Podman or Docker, including notes for WSL 2, is described in the [article on Claude Code in a container](https://www.jpkc.com/db/en/blog/claude-code-container/). Microsoft explains every `.wslconfig` key on the page [Advanced settings configuration](https://learn.microsoft.com/en-us/windows/wsl/wsl-config). Why texts like this one get checked separately from the writing is shown in [Who Checks the Checker?](https://www.jpkc.com/db/en/blog/faktentreue-review/).

For this article, Claude Code supported me with creation, correction and verification. The direction and the editorial responsibility are mine. There's more on that on the [AI transparency](https://www.jpkc.com/db/en/ai-transparency/) page.

