返回资讯中心
外部精选
软件工程
#开发者实时流

Claude Code Memory Usage: How Many Sessions Fit on One Machine

This is about what happens to a computer’s working memory when you run several AI coding assistants side by side, and how to plan for it.

Hacker News 最新spreadstreet2026/10/20 · 26 天前30 分钟阅读

以下正文同步自 Hacker News 最新,版权归原站所有,已转换为易读排版。

October 19, 2026· 32 min read· 28 sources

This is about what happens to a computer’s working memory when you run several AI coding assistants side by side, and how to plan for it.

When you open an AI coding assistant, you think you are starting one program. You are actually starting a small crowd. It is like hiring one contractor who shows up with a van full of specialists, each with their own toolbox. Count only the contractor and you will badly underestimate how much room you need on the job site.

The author counted the programs running behind three assistant windows on his own workstation. There were 32 of them, and only three were the assistant itself. In two of the three windows, the add-on helpers used more memory than the assistant did. So how many windows one computer can hold depends less on the assistant and more on everything it brings along. To plan well, you need to measure the whole crowd fairly, check it at its worst moment, and put a fence around each window so one runaway can’t take down the rest.

Note that “memory” here means the computer’s working memory (RAM), the space that fills up and makes programs get shut down. It does not mean the assistant’s feature for remembering notes between chats.

Each assistant window starts its own copy of every add-on helper you have set up. Three windows with four helpers each means twelve helpers, not four. The helpers are not shared by default, even when they do the same job. The author’s helpers for browsing and for deployment tools each showed up as several separate copies.

Two things make the crowd bigger. A teammate assistant that one window spawns counts as a full extra window with its own helpers. And some helpers keep running after you close the window that started them, so count again after closing things, not just while they run.

Programs often share the same underlying pieces. The usual way of adding up memory charges each program for the whole shared piece, like splitting a restaurant bill by giving every diner the full price of the shared appetizer. On the author’s machine, that made the total look about 62% bigger than it really was. A fairer method splits each shared piece among the programs that use it.

There is an even worse number. One widely repeated horror story said an assistant “consumed 129GB.” That figure was the space a program had reserved on paper, not memory it was actually using. The same report showed it was really using about 415 MB. Reserving a seat is not the same as sitting in it.

Every helper you remove from your setup is removed from every window, so cutting helpers is the cheapest fix. Some ways to do it:

One trap worth knowing: a feature that makes helpers cheaper for the assistant’s thinking space does not make them cheaper for the computer’s memory. The helpers still run. It saves one kind of room, not the other.

A window’s size at startup is a floor, not a budget. The author sampled his three windows every five minutes, but the run was cut short by a restart, so he only has about 20 minutes of data. In that time the windows stayed roughly flat; the biggest one rose by 63 MB and then gave most of it back. That is all 20 minutes can say. It says nothing about what happens at hour four.

For longer stretches, the evidence comes from other people’s bug reports, and it is worse: sessions that grew from under a gigabyte to many gigabytes and got killed. The maker has been fixing these one release at a time, so which version you run matters. The maker also shows a warning when a window gets too big. The advice is to restart the window and pick the conversation back up when you see it, and to restart between big tasks anyway.

Without a fence, all windows draw from one shared pool, and one runaway window can freeze the whole machine. On Linux, you can give each window its own memory limit with two settings: a soft one that slows it down when it gets greedy, and a hard one that is the last resort. Then a leak costs you one window, and that window can be resumed.

Two honest limits. First, a fence protects the computer, not the window; the greedy window still gets shut down. Second, Macs don’t have this fencing tool, so on a Mac the options are fewer helpers and fewer windows.

The same math works for automated runs on a build server. Run them in a stripped-down mode so they only start the helpers you listed, put a hard memory cap on each, and record how much each run actually used. The author’s claim that the stripped-down mode saves memory is an inference from his measurements, not something the maker states.

Maximum windows is roughly: (total memory, minus a cushion) divided by the worst size one window reaches.

The cushion, about a quarter of the memory, is the author’s own rule of thumb, not a sourced figure. On his machine, the math gives about 119 windows if every window stays as small as it did in his 20-minute sample, but only about 12 if every window hit its hard limit at once. The gap between those numbers is the whole point. The true answer sits in between, and the fences are what make running well past 12 a reasonable bet. For most teams, though, memory is not the real limit. The number of changes a human can review limits useful parallel work long before the computer does.

Keep reading: the full version, with the research and sources ↓

I counted the processes behind three Claude Code sessions on my workstation: 32 of them, and only three were Claude. In two of the three sessions, the MCP servers I had configured used more memory than Claude did. Memory here means RAM, the resident kind that fills a host and gets sessions OOM-killed, not the CLAUDE.md feature that shares the name. How many sessions one machine can hold depends less on the claude binary than on everything each session drags along with it. That means measuring the whole tree correctly, at its worst moment, inside a fence that keeps one bad session from taking down the rest.

A Claude Code session is not one process. It is a tree: the claude binary, every stdio MCP server it launched, and anything those servers launched in turn. With stdio servers, N sessions times M servers is the number that fills RAM. List the tree for each session before you budget a single megabyte.

Here is that list at 10:42 on October 19, 2026. The host is a WSL2 VM on a 128 GB Windows box running Claude Code 2.1.303, with three interactive sessions open side by side.

Session A runs two MCP servers: proto-mcp, a Go binary at about 75 MB, and playwright-mcp. Sessions B and C add cloud-run-mcp and gitbook-mcp, which pushes their servers past the agent by roughly two to one. Across the host that is three copies of playwright-mcp, three of proto-mcp, two of cloud-run-mcp, and two of gitbook-mcp. Each is a separate process with its own heap, doing the same job as its twins. (ps --ppid <claude-pid> -o pid,rss,args gives you the same view of a session’s direct children on your own machine.)

This is the documented design, not a quirk of my config. Claude Code’s MCP docs state that “Stdio servers run as local processes on your machine” (Claude Code Docs: MCP1). The protocol defines stdio as the transport where “The client launches the MCP server as a subprocess” (MCP Spec: Transports2). Every session is its own client, so every session launches its own copy. Claude Code does deduplicate, but only inside one session. When a server is defined in more than one place, it “connects to it once, using the definition from the highest-precedence source” (Claude Code Docs: MCP1).

Other people’s hosts show the same shape at larger N. One user filed the expected count as “4 sessions with 6 MCP servers should spawn 6 MCP processes total, not 42” (JotaNikkan-pro: #288603). A report from October puts the desktop app at roughly 10 GB of duplicate server processes across ten sessions (lrgibs01: #998314). At the far end:

With N sessions and M configured MCP servers, the system spawns up to N×M node processes with no memory cap. On a 64 GB MacBook Pro, 15 concurrent sessions with 34 configured MCP servers caused a hardware watchdog kernel panic twice in one evening.

Two things push the count past N times M. Agent teammates are not lightweight: “Each teammate is a full, independent Claude Code session.” Each one loads “CLAUDE.md, MCP servers, and skills” when it spawns (Claude Code Docs: Agent teams6), so a lead with three teammates carries four sessions’ worth of servers. Stdio servers can also outlast their parent; the environment variable reference calls them “long-lived and outlive the session that spawned them” (Claude Code Docs: Environment variables7). Count again after you close a session, not only while it runs. The token cost of splitting work across agents is its own budget (multi-agent context isolation); this post is the host-RAM side of the same decision.

Summing RSS across a session’s processes gives you a number that is too big. Reading VSZ gives you a number that is not memory at all. Measure each session as its whole process tree in proportional set size, or read its cgroup’s memory.peak, and nothing else.

PSS is the kernel’s answer to shared pages:

The “proportional set size” (PSS) of a process is the count of pages it has in memory, where each page is divided by the number of processes sharing it.

RSS charges every process the full cost of every page it maps. A dozen node processes sharing one runtime each get billed for all of it. On my three sessions the gap is not a rounding error. Summed tree RSS is 2,943 MB against 1,815 MB of PSS, so RSS overstates the real footprint by about 62%. Shyam Verma hit the same wall measuring his own MCP fleet: “RSS overstates actual memory usage because it double-counts shared pages between processes” (Shyam Verma: My MCP Servers Were Eating 3 GB of RAM9). Budget in RSS and you under-pack the machine by more than a third.

VSZ is worse. The most-cited Claude Code memory headline, a session that “Consumed 129GB RAM,” traces to VmPeak: 135508316 kB in the report (nenrightld-ux: #1131510). The same report’s VmRSS was 425416 kB, about 415 MB actually resident. VmPeak and VSZ count address space. A runtime can reserve far more than it ever touches, and none of that reservation competes with your other sessions.

Every number here comes from walking each claude process’s descendants and summing two fields from smaps_rollup. That file carries “the same fields as /proc/PID/smaps” summed across every mapping of the process (Linux kernel docs: The /proc Filesystem8):

#!/usr/bin/env bash

One line per top-level claude session: process count, tree RSS, tree PSS (MB).

set -u

descendants() { local pid=$1 child echo "$pid" for child in $(pgrep -P "$pid"); do descendants "$child"; done }

for root in $(pgrep -x claude); do parent=$(ps -o ppid= -p "$root" | tr -d ' ')

skip claude processes whose parent is also claude (split-pane teammates)

[ "$(ps -o comm= -p "$parent" 2>/dev/null)" = claude ] && continue rss=0; pss=0; n=0 for p in $(descendants "$root"); do f=/proc/$p/smaps_rollup [ -r "$f" ] || continue read -r r s < <(awk '/^Rss:/{r=$2} /^Pss:/{s=$2} END{print r+0, s+0}' "$f") rss=$((rss + r)); pss=$((pss + s)); n=$((n + 1)) done printf 'pid=%s procs=%d tree_rss_mb=%d tree_pss_mb=%d\n'
"$root" "$n" $((rss / 1024)) $((pss / 1024)) done

The log behind this post’s tables records those tree sums every five minutes, with the claude process and its MCP children broken out separately.

On Linux there is a second instrument that needs no script. Once a session runs in its own cgroup (the fence section below sets that up), the kernel keeps the tree’s total for you. memory.current is “The total amo

正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。

打开原文
去社区讨论 →