Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

15 Claude Code sessions were sitting on 11 GB of RAM. I built a mod to see which one

说明与用途

claude-load 模块能够准确识别哪些 Claude Code 会话消耗内存和 CPU,并安全终止它们,将内存使用从 11 GB 降至可管理水平。

问题

Multiple Claude Code sessions consume excessive RAM and CPU, making it hard to identify which session is responsible for high resource usage.

结果

The claude-load mod enables precise identification and safe termination of high‑resource Claude Code sessions and orphan processes, reducing memory usage from 11 GB to manageable levels while keeping overall CPU overhead below 1 %.

工作流

  • 1. Read session registry files in ~/.claude/sessions/*.json to map PIDs to session IDs and names.
  • 2. Build a process tree by walking PPID chains, caching results for efficiency.
  • 3. Identify orphan trees whose root’s parent is dead or reparented to init/systemd/launchd.
  • 4. Filter orphans to include only dev tools with >0.3% CPU or >150 MB memory, excluding shells and the sampler itself.
  • 5. For each orphan, resolve its working directory via /proc/<pid>/cwd (Linux), lsof (macOS), or NtQueryInformationProcess (Windows).
  • 6. Display sessions and orphans in a UI pane with CPU, memory, and graph data.
  • 7. Provide an “end” button that takes a fresh snapshot, checks PID freshness and name, and then terminates the process tree safely.
  • 8. Run a single sampler process per machine that writes a snapshot to ~/.claude/state/load/snapshot.json; other sessions read this file every five seconds.
  • 9. On Windows, the sampler uses Get-Process for cheap polling and CIM queries only when new PIDs appear.
  • 10. On macOS/Linux, a session holds a lease file and performs sampling itself, ensuring only one active sampler.
  • 11. The mod enforces strict validation to prevent accidental termination of unrelated processes.

证据

I opened Task Manager and saw what everyone who works like this has probably seen: a wall of identical node and claude processes.

来源

The very first run showed 15 live sessions holding 10.8 GB together.

来源

The sampler takes the list of all processes with their parents and climbs the PPID chain from each one until it hits a session's PID.

来源

On Windows the sampler is a hidden PowerShell process that the mod starts when it sees the snapshot is stale.

来源

  • 记录日期: 2026-10-23T22:11:25.654Z