I run a lot of Claude Code sessions at once. One per feature, sometimes three per feature. They all live in herdr, a terminal workspace manager built for coding agents, as tabs and split panes.
One evening I added it up. 6.1 GB of RAM was sitting under herdr panes. Most of it was idle Claude sessions I hadn’t looked at in hours.
Where the Memory Goes
An idle Claude session is not free. Each one sits at 130–250 MB, and that’s before its MCP servers. One pane was running flutter run against Chrome and holding 2.1 GB on its own.
I didn’t want to close any of them. Closing a tab means losing the session, and the session is the whole point. What I wanted was a browser’s tab discarding: keep the recent ones live and suspend the rest.
The first idea was SIGSTOP. Freeze the process, and memory stays put. On macOS that frees nothing. A stopped process keeps every page it owns.
The only way to get the memory back is to actually quit Claude. Fortunately Claude can come back exactly where it left off:
claude --resume <session-id>
So sleep means quit, and wake means resume.
How the Shelf Works
The plugin is called lru-shelf. It’s a POSIX shell script plus jq, hooked into two herdr events:
tab.focused— move this tab to the front of the recent list, wake it if it’s asleep, then rebalance.pane.agent_status_changed— an agent that just finished might make a tab safe to sleep, so rebalance.
Rebalancing counts the awake tabs that have Claude in them. If there are more than KEEP (I use 10), it sleeps the oldest ones until the count fits.
Putting a tab to sleep goes like this for each Claude pane:
- Send
ctrl+cto clear any half-typed prompt. - Run
/exit. - Wait up to 15 seconds for the agent to disappear. If it doesn’t, leave the tab awake.
- Save the pane, its session ID and its working directory to a small JSON file.
- Rename the pane and tab with a 💤 prefix.
Waking reads that file back and runs cd '<cwd>' && claude --resume <id> in each pane. A sleeping tab drops to 2–3 MB — a bare shell.
The hard part is not sleeping something that’s busy. A tab is only safe if:
- every Claude pane in it is
idleordone, - no pane is labelled with 👁 (my convention for watchers),
- nothing in the foreground matches
flutter run,gradle,xcodebuild,psqland friends, - and every other pane is just a shell at a prompt.
What It Saves
The problem was simple: every tab I’d ever opened kept its Claude running, so memory only ever went up. Tabs were cheap to open and never got cheaper to keep.
Now memory follows what I’m actually working on. The first four tabs I put to sleep held 9 Claude panes between them. Awake, each of those tabs sat at 250–500 MB. Asleep, each one is 2–3 MB. That’s roughly 1.2–2.2 GB handed back to macOS from four tabs I wasn’t looking at.
Nothing is lost. Focus a sleeping tab and every pane resumes its own session, same ID, same history. Opening a tab costs a few seconds of --resume instead of a few hundred megabytes forever.
The limit counts tabs, not panes. A tab with six Claude panes is one tab. When it sleeps, all six sleep together. Tabs with no Claude in them don’t count at all. There’s nothing to free.
Pins, a Menu and a Tree
Some tabs should never sleep, whatever happens. So I added pins. A 📌 tab never sleeps and sits outside the limit.
I wanted pin and sleep in the tab’s right-click menu. That’s where my hand goes. I read herdr’s source to see how. The tab menu is hardcoded to New tab · Rename · Close. Plugin actions can declare a tab context, and herdr stores it, but nothing in the UI reads it.
So I built a popup instead. Ctrl+Opt+P opens a small menu for the current tab: p pin, s sleep, w wake, l status. One keypress and it’s gone.
Then I wanted to see everything at once. Ctrl+Opt+] opens a tree — repo, then tab, then pane — drawn with fzf:
herdr 4.2G 19% · mac 18G / 24G used
work-app 1.7G 4% on feature/ui · 8 tabs
├─ network-image ○ 160M 1%
├─ 💤 cart $$$ 3M 0%
├─ 📌 mission ○○○ 865M 1%
└─ contract ○○👁 477M 2%
Every row shows RAM and CPU. herdr only tells you a pane’s foreground processes, so the script walks the whole process table from those PIDs down. That’s how a Chrome launched by flutter run ends up counted against the pane that started it. The preview pane on the right shows the tab’s heaviest processes, then my last prompt and Claude’s last reply. The whole tree builds in about 0.3 seconds.
Previewing a narrow pane by reading its screen didn’t work. Claude wraps its own output to the pane width, so a thin pane read back one word per line. The fix was to skip the screen and read the session’s log in ~/.claude/projects/ instead.
Two Bugs, Found in Five Minutes of Live Mode
I ran it in dry-run mode first. It only showed a toast saying what it would sleep. The lists looked believable. I switched it to live.
Within minutes I opened a fresh tab, started Claude, and switched away. A few seconds later the tab was 💤. When I came back:
No conversation found with session ID: 79dab85b-aa2e-4c5a-8b1e-fd6ee8727621
That one error had two causes.
The Recent List Was Always Empty
The script keeps a file of tab IDs, most recent first. Bumping a tab looked like this:
bump() { { echo "$1"; grep -vx "$1" "$MRU"; } >"$MRU.tmp" && mv "$MRU.tmp" "$MRU"; }
# ^ exits 1 when it prints nothing, so mv never runs
grep exits 1 when it matches nothing. On an empty file it matches nothing. So the group fails, && skips the mv, and the file stays empty. Forever.
With no history, the order fell back to the tab bar. The end of the tab bar counted as the oldest. So the shelf put my newest tabs to sleep first — the ones I’d opened seconds earlier.
Dry run hid this completely. A list of five idle tabs looks correct whichever five they are.
The fix is to stop letting grep’s exit code decide whether the file gets saved.
Resuming Something That Was Never Saved
The second cause is in Claude itself. A new session isn’t written to disk until you send the first message. That fresh tab had a session ID, but no transcript behind it. The shelf quit it, saved the ID, and later asked Claude to resume something that never existed.
So a Claude pane with no transcript on disk is not safe to sleep. And if a wake ever finds no transcript, it should start a fresh claude instead of a --resume that can only fail.
The Lesson
Dry runs test whether the code runs. They don’t test whether it chooses well. A believable list hid a recent list that had been empty since day one.
Five minutes of live mode found what an afternoon of dry runs didn’t. Ship the dry run, then go live with your eyes open.