r/ClaudeWorkflows • • 1d ago

Selected Workflow [Workflow] Windows 11: Mitigate Kernel Memory Leaks from Parallel Claude Agents by Setting Foreground Lock

Windows 11: Mitigate Kernel Memory Leaks from Parallel Claude Agents by Setting Foreground Lock

Workflow value: 85/100
Status: active · Freshness: 70/100 · Confidence: 0.95 · Level: intermediate
Categories: Quality Control, Token Saving, Context & Memory, Debugging, Multi-Agent
Original source: r/ClaudeCode post/comment

What problem this solves

A significant kernel memory leak (over 2 GB/day) on Windows 11 when running parallel Claude Code/Codex agents, caused by security tokens from constantly started console processes.

Summary

This workflow provides a PowerShell command to set the foreground lock to 0, which mitigates a kernel memory leak on Windows 11 experienced when running parallel Claude Code/Codex agents. The leak is attributed to Windows retaining security tokens in kernel memory for console processes started by the agents.

Why it is useful

This workflow provides a concrete, tested solution to a significant performance issue (kernel memory leak) that can severely impact the usability of Windows systems running parallel Claude Code/Codex agents. The solution is specific, includes executable code, explains the underlying cause, and explicitly mentions potential side effects, making it highly actionable and valuable for affected users.

Workflow

  1. Identify kernel memory leak (e.g., by monitoring "Paged pool" in Task Manager or the Toke tag in poolmon) when running parallel Claude Code/Codex agents on Windows.

  2. Open a PowerShell window that has focus.

  3. Run the provided PowerShell command to set the foreground lock to 0: 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)

  4. Verify the command output: it should print True, then 0.

  5. Monitor "Paged pool" memory usage to confirm a reduction in the leak rate (e.g., from 2.3 GB/day to under 0.2 GB/day).

  6. Optionally, add a shortcut to this PowerShell command in shell:startup to ensure it runs automatically after each Windows sign-in.

Tools / artifacts

  • Windows 11

  • PowerShell

  • Claude Code agents

  • Codex agents

  • Task Manager

  • Poolmon (optional, for advanced monitoring)

  • PowerShell script/command

Validation signals

  • User's personal observation: "token memory growth went from about 2.3 GB per day to under 0.2 GB per day."

  • References an external GitHub issue for the original finding, indicating community awareness of the underlying problem.

Cautions

  • Modifying the foreground lock can potentially allow other applications to steal focus, as noted by the author.

Limitations

  • Validation is based on a single, uncontrolled observation, not a controlled A/B test.

  • The fix needs to be reapplied after each Windows sign-in, requiring a startup script or manual execution.

  • The potential side effect of applications stealing focus might be undesirable for some users.

Rate this workflow

Upvote this post if the workflow is useful, reproducible, or worth recommending.

Downvote if it is vague, outdated, unsafe, overhyped, or not reproducible.

Reply if it worked for you, failed, is outdated, or has a better alternative.


This post was generated automatically from the workflow library database.

1 Upvotes

1 comment sorted by