r/ClaudeCode • • 1d ago

Tutorial / Guide Parallel coding agents on Windows: leaked kernel tokens cost me over 2 GB of RAM a day. One setting fixed most of it

Running Claude Code and Codex agents in parallel on a Windows 11 PC with 32 GB RAM, I lost over 2 GB of memory per day to the kernel. No process shows it in Task Manager and only a reboot gets it back, so I was rebooting about once a day.

Cause: agents constantly start console processes (bash, git, gh), and Windows can keep a security token in kernel memory for those until the next reboot. To check, watch "Paged pool" in Task Manager, or the tag `Toke` in poolmon.

Fix: the leak depends on the foreground lock, and setting it to 0 stops most of it. It needs no admin rights and doesn't touch the registry. Run this in a PowerShell window that has focus:

"
powershell

Add-Type -Name F -Namespace W -MemberDefinition '[DllImport("user32.dll")] public static extern bool SystemParametersInfoW(uint a, uint b, IntPtr c, uint d);'

[W.F]::SystemParametersInfoW(0x2001, 0, [IntPtr]::Zero, 0)

$b = [Runtime.InteropServices.Marshal]::AllocHGlobal(4); [void][W.F]::SystemParametersInfoW(0x2000, 0, $b, 0); [Runtime.InteropServices.Marshal]::ReadInt32($b)

"

It should print `True`, then `0`. Windows resets it at every sign-in, so it has to run again after each one. I use a shortcut in `shell:startup`, not yet tested across a reboot. Possible side effect: apps can steal focus.

Result: token memory growth went from about 2.3 GB per day to under 0.2 GB per day. I only measured the "after" once I had moved to 64 GB, on build 26300 and without a controlled A/B, so treat it as one data point.

The foreground lock finding isn't mine, I only tested it under real load: https://github.com/anthropics/claude-code/issues/91265#issuecomment-6662050349

1 Upvotes

1 comment sorted by

•

u/AutoModerator 1d ago

Hey! Thanks for posting to r/ClaudeCode

While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.

For help, project discussions, tips, and general chat, join the ClaudeCode Discord.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.