Jakob Christensen / Cases#001#002#003#004
8 Rules to keep parallel Agent Sessions stable
Relevant skills: /lanes, /tidy-worktrees, /am-i-done
With many agent sessions open at once, the Claude app on my Windows computer kept crashing. A session is one conversation with the agent, and I often had several running side by side, each in its own copy of the project (a worktree). The obvious suspect is the number of sessions. The cause was what they left running: on the evening of 13 November a session that cleaned up my computer found 42 Node processes (the programs that run JavaScript tools such as dev servers) before it started and 4 after it had stopped the leftovers.
Rule of thumbCrashes came from what sessions left running, not from the sessions.Dev servers, test workers and browsers that nobody stopped filled up the computer's memory.
Three kinds of program piled up. Dev servers serve your project on your own computer while you work on it, for example Vite, a common JavaScript development tool. Test workers are the processes that each run part of a test suite. Headless browsers are browsers without a window that scripts start in the background. Each of them holds memory until someone stops it, and in my sessions often nobody did.
Example
When Windows runs short of memory, it writes a warning to its event log (event 2004, "low virtual memory condition", where virtual memory is the RAM plus the page file on disk). The warning names the three programs holding the most memory. This is how many of those warnings my computer logged each day:
Windows low-memory warnings per day, 20 Oct to 29 Nov 2026
- 24 → 2warnings a day (about), before and after the cleanup. More sessions were active per day afterwards, not fewer.
- 19 of 20crashes or hangs of the Claude app came within 30 minutes of a warning. That is a match in time, not proof of cause.
The rules below are what I changed around 13 November, so the drop cannot be traced to a single rule. The skills linked at the top are ready-made instruction files for parts of this work. A skill is a file the agent follows when a task fits it, or when you type its name, for example /fresh.
Rules for your agent (paste into CLAUDE.md or AGENTS.md)
CLAUDE.md or AGENTS.md is the file of standing instructions your agent reads at the start of every session. Paste the rules there, or download them.
-
Stop your dev servers after the merge
After a branch is merged, stop the dev servers that its worktree started, and no others.
A worktree is a second folder for the same project, on its own branch (a separate line of changes). Parallel sessions usually get one each.
Why
A dev server is a node.exe process (node.exe is the Windows program that runs JavaScript outside a browser), and it keeps its memory until someone stops it, even after the branch it served is merged.
178 of 304Windows warnings up to 13 November named node.exe among the three largest memory users.
-
Clean up leftovers at the start
At the start of a session, look for dev servers and headless browsers that run from a folder which no longer exists, and stop only those.
Why
A server whose folder is gone has nothing left to serve but still holds its memory, so stopping it disturbs no other session.
-
Give each dev server a fixed port
Give each dev server a fixed port and make it fail instead of moving to another one (in Vite:
strictPort).A port is the number a local server listens on, such as 5173.
Why
Without a fixed port, a new server quietly starts on the next free port while the old one keeps running, and you may be looking at the old page without noticing.
-
Keep other sessions' folders out of the file watcher
Keep the worktree folders of other sessions, and the
.claudefolder Claude Code keeps in your project, out of the dev server's file watcher (in Vite:server.watch.ignored).The file watcher is the part of a dev server that notices changed files and reloads.
Why
Every other session's worktree is a full copy of the project, so the watcher has far more files to follow, and none of them belong to the page the server shows.
-
Run tests in few, separate processes
Run tests in separate processes (forks, Vitest's default) rather than threads, with only a few workers. Run tests that need no browser page (DOM) without a DOM environment.
Vitest is a test runner for JavaScript projects. The DOM is the page structure a browser builds. A test that never touches a page does not need a simulated one. Forks run each worker as its own process, threads share one process.
Why
Fewer workers means fewer processes holding memory at once.
139 s → 35 sis roughly what the DOM-free change did to one test suite in one project.
-
Small commit, small test run
Let a small commit test only the files it touches (
vitest related --run). Run the full check when you integrate.The full check is the project's whole run of tests, lint (a scan for likely mistakes in the code) and build. Integrating means merging a finished branch into main after that check.
Why
A full test run on every commit starts test workers far more often than needed, and when several sessions commit at the same time those runs stack up.
-
One integration at a time
Allow one integration at a time and enforce it with a lock.
A lock makes a second integration wait until the first has finished.
Why
A full check starts many processes at once, and two checks running at the same time need the memory for both.
-
Retry a red check once with one worker
If a check fails under load, repeat it once with a single worker. If it fails again, the failure counts. If the retry passes, put it into the report as a possible concurrency problem.
Why
Under load a test can fail on timing alone, for example when it runs out of time because the computer is busy. With a single worker most of that load is gone, so a second failure points at the code itself.
The details
Claims checked
Each row is something I claim on this page, next to what the logs showed.
| Claim | Measured |
|---|---|
| "Windows warnings about low memory dropped on 13 November." | 208 warnings from 5 Nov to 13 Nov 19:37 (8.8 days, about 24 a day), and 34 from then to 29 Nov (15.7 days, about 2 a day). |
| "I work less, so there is less to crash." | No. Active sessions per day: 39-98 from 5 to 13 Nov, 85-295 from 22 to 29 Nov. |
| "The crashes follow the warnings." | 19 of 20 crash or hang events of the Claude app (Windows events 1000 and 1002) lie within 30 minutes of a warning. Only 16.8 % of all minutes from 30 Oct to 29 Nov are that close to one. That is a match in time, not proof of cause. |
| "Leftover dev servers and test workers were the main memory users." | Until 13 Nov 19:37, node.exe stood in the top three of 304 warnings 420 times (one warning can name several node.exe processes). Afterwards 26 times in 34 warnings. The warning names programs, not whether they were leftovers. |
| "The cleanup freed the memory." | The session that ran it reported "10.9 GB commit free instead of 2.1 GB, 4 node processes instead of 42" (13 Nov, 19:37). Commit is the memory Windows has promised to programs, so "commit free" is how much it can still promise. The measurement was not repeated. |
How the numbers were measured
Summary
- Windows low-memory warnings fell from about 24 a day to about 2 a day on the evening of 13 November 2026, while more sessions were active per day, not fewer. The chart at the top of the page shows every day.
Measurements
| Windows warnings (event 2004) | 338 from 20 Oct to 29 Nov, 208 from 5 Nov to 13 Nov 19:37, 34 after 13 Nov 19:37 |
|---|---|
| Active sessions per day | 39-98 from 5 to 13 Nov, 85-295 from 22 to 29 Nov |
| Claude app crash or hang events | 20 (events 1000 and 1002), 19 within 30 minutes of a warning |
node.exe in the top three of a warning | 420 times in 304 warnings up to 13 Nov 19:37, 26 times in 34 warnings after (one warning can name several node.exe processes) |
| Machine | 31.9 GB RAM, 2 GB page file on C:, 32 GB on D: |
What changed in the project
| Date | Change in the project |
|---|---|
| 6 Nov | Two agents in separate worktrees: one dev server per worktree |
| 8 Nov | Integration in a temporary worktree behind a lock. DOM-free tests in node with 3 workers |
| 10 Nov | Dev server ignores the .claude folder |
| 11 Nov | Tests in forks instead of threads |
| 12 Nov | Integration retries a red check once with one worker |
| 13 Nov | Fixed port with strictPort. Integration stops the worktree's dev servers. A cleanup command finds leftovers |
| 22 Nov | Worktree folders excluded from watcher and test discovery. Small commits test related files only |
Commands
| Count | Command |
|---|---|
| Windows warnings | Get-WinEvent -FilterHashtable @{LogName="System"; Id=2004} |
| Crash and hang events | Get-WinEvent -FilterHashtable @{LogName="Application"; Id=1000,1002}, filtered to the Claude app |
| What changed | git log of the project, by date |
The counts are a snapshot of 2026-11-29. Session numbers come from local transcripts (the .jsonl files Claude Code stores under ~/.claude/projects).
Method and limitations
- The cleanup was not repeated on a clean machine, so "the leftovers caused it" is the likely cause, not a proven one. The cleanup and the new rules landed on the same evening, so their effects cannot be separated.
- Claude Code itself changed in the same weeks: version 2.1.309 in the crash events until 7 Nov, 2.1.330 now. The official changelog lists memory and crash fixes from 2.1.326 (16 Nov), which is after the drop. The entries for 2.1.300-2.1.322 and 2.1.324 were not read.
- Later peaks came from other work: Unreal (17-18 Nov, up to 10.9 GB), Python scripts (26-27 Nov, up to 32 GB), Firefox and
claude.exeitself (up to 4.9 GB). - Only one setup was measured: one person, one Windows machine, one project at that time.
- How much any single rule helps was not measured. The rules are what was changed. The table above gives the dates. Running tests in forks instead of threads was not measured on its own either.
Sources
- Microsoft: Event ID 2004
- Microsoft blog: debugging the 2004 warning
- Vitest: pool
- Vitest: common errors
- Vite: troubleshooting
- Claude Code: changelog
- User reports on GitHub, not confirmed by Anthropic: #48398 (orphaned dev servers after a desktop app crash on Windows), #41742 (node and bash processes not released on Windows), #67163 (1,220 orphaned node.exe processes after Playwright runs), #96299 (claude.exe processes piling up over a day), #66151 (child processes of Stop hooks survive on Windows)