Skip to content

agent-gc top

Start cost is half the story; the other half is how much a session piles up as it goes. agent-gc top is a live view of every running Claude Code session and its subagents:

agent-gc top · 12:04:31 · 3 sessions: 2 busy, 1 idle, 1 stalled · 2 agents running · ctx 1.2M · cpu 41% · mem 2.3G sort CTX▼ · ? help q quit
~/.claude 5h 42% resets 17:00 · 7d 18% resets Thu · other ~8%
~/.claude-work limits unknown: run agent-gc limits on · %u = share of usage, last 5h
PID %CPU MEM CTX 5h +10m STATE CMP MODEL AGO SESSION / AGENT
41453 31.0 956M 712k ████████ ~12% +40k busy 1 opus-5-5 4m ▼ blog-18 ~/blog · subagent ac9ed17e (general-purpose): last write 10s ago
130k ██ — running 0 opus-5-5 10s └ ac9ed17e general-purpose Fix bug
+12 done
8821 9.6 712M 415k ██████▌ 31%u — busy 0 opus-5-5 8m ▼ notes-46 ~/notes · Bash: cargo test --workspace (8m) · child cargo <1% CPU, may be waiting for input
7710 0.4 603M 23k ▍ ~1% — idle 0 opus-5-5 2h ▶ blog-7b ~/blog
  • Laid out like htop: the numbers on the left, the session / agent tree on the right, using the whole width of the terminal. The first line sums up like top’s: the time, how many sessions are busy, idle and stalled, running agents, the context of all sessions together, and CPU and memory of all their processes.
  • PID, %CPU and MEM are the session’s Claude Code process together with everything it started (MCP servers, shells, builds): CPU in percent of one core (… until it has been sampled twice), resident memory. Subagents run inside their session’s process and have none of their own.
  • CTX is the context the last model reply carried (input + cache read + cache write tokens): yellow from 150k, red from 300k or after a compaction (top_warn_tokens / top_alert_tokens in the settings). +10m is how much it grew in the last 10 minutes, CMP how many times it was compacted (… while still counting).
  • Subagents hang under the session that started them; finished ones fold into one +N done line. Background sessions (sdk-cli, e.g. memory plugins’ observers) are hidden until you press h. A session that exits stays grey for a minute.
  • It reads session files, the process list and transcripts: the ends of them while it runs, plus one full pass per transcript in the background to count compactions. To find and drive terminals it runs ps, tmux and osascript (each call is cut off after 10 s). It ends a session only when you press K on it and confirm with y.
  • Rows marked ≈ come from an older Claude Code without session files: the match to a transcript is a guess, so they are view-only (enter works, s and c don’t).

Keys (? shows them all):

↑↓ j k g G move; first, last
← → fold, unfold (and show finished agents)
enter jump to the session’s tmux pane or iTerm2 tab; on a subagent, the last 30 events of its transcript
s / c type a line into the session (on a subagent, into the session that owns it) / send /compact
< > R sort by the previous / next column, reverse; the sorted column is highlighted and named in the header
P M T N sort by %CPU, memory, context, pid (as in top)
/ filter by session name, folder or agent while you type; enter keeps it, esc clears it
K end the selected session: asks first, y sends SIGTERM and, if it is still there after 5 s, SIGKILL. Only a Claude Code or Codex process, and only the exact one shown (pid and start time); recorded in the journal
h show background service sessions
q quit (esc clears a filter first)

Ended sessions stay at the bottom whatever the sort.

Commands run in the background, so the screen stays usable while they work. Above the status line, each running one has its own line with a spinner, what it is doing and for how long: /compact → blog-18 · compacting; the draft comes back when it ends · 2m, switching to notes-46, ending blog-18 · SIGTERM, SIGKILL if still there after 5 s. When it finishes, its line is replaced by the result and the time it finished (12:41:07 sent to blog-18); the last two results stay. Sorting, filtering or a refused key only change the status line under them.

Typing into a session:

  • Only when the session is idle and not in the middle of a tool call (and its transcript was found, so that can be checked). A session waiting for a permission answer is never typed into, so a stray 1 can’t approve anything.
  • Only when Claude Code is in the foreground of its terminal: a session suspended with ctrl+z or sent to the background is refused, since the keys would go to the shell.
  • Whatever you had half-typed there survives: top parks it behind a . in Claude Code’s prompt stash (ctrl+s), sends the line, and removes the . once Claude Code has put the draft back (a second after a message; after /compact once the session is idle again). If /compact doesn’t bring the session back to idle within 10 minutes, the . stays at the cursor in your draft. The stash holds one draft, so a draft you stashed yourself in that session is overwritten. If the stash key is rebound or vim mode is on, top refuses instead.
  • A line must start with a letter or digit (any alphabet) or one of " ' ( [ { < «: / opens slash commands (c is the one exception, for /compact), and characters like !, # or ? switch Claude Code’s input mode or open a menu. A line whose last word starts with @ is refused too, since Enter would pick a file from the completion list instead of sending.
  • tmux and iTerm2 only. The first time, macOS asks whether your terminal may control iTerm2 (Automation); if you said no, turn it on in System Settings → Privacy & Security → Automation. For sessions in other terminals top shows the tty and the folder. The tmux path is implemented and unit-tested but has not been tried against a live tmux yet (iTerm2 has).

agent-gc top --json prints one snapshot as { "limits": [...], "sessions": [...] }: one entry per account (install ids, the two windows, whether the numbers are fresh, the closed sessions’ share), and the same tree with each session’s share_5h ({"Estimated": 12.3} or {"Relative": 31.0}) and stall (the diagnosis by kind, plus "text": what the screen shows after the name). It takes one process sample, so child CPU shows as unknown there. Account ids are never printed.

On a subscription what runs out is the plan’s 5-hour and 7-day limits, not dollars. Claude Code knows how much of each is used, but tells only its status line command, so agent-gc limits on installs one:

Terminal window
agent-gc limits on # every Claude Code install: status line that shows `5h 42% · 7d 18%` and records the numbers
agent-gc limits status # per install: installed or not, who uses it (limits, sched), whether your own status line is wrapped, age of the last numbers
agent-gc limits off # puts back exactly the status line that was there (or none), unless sched still uses it
  • on edits each install’s settings.json (a backup is made first). If you already have a status line, it is kept: agent-gc runs it and appends its own numbers to the last line of its output. All lines of your command’s output are kept (trailing spaces and blank lines at the end are dropped; at most 16 lines and 16 KiB, a longer output ends with …). A saved line that itself runs agent-gc’s status line is not run, so the status line can never call itself; with no output only agent-gc’s numbers are shown. Your command runs with AGENT_GC_IN_STATUSLINE=1 in its environment, and so do its children; an agent-gc status line started under it (or under another agent-gc status line, found through the process tree, so clearing the environment does not matter) shows only its own numbers and runs no command of yours. Its output is shown whatever its exit status. Your command gets up to 5 s; if it is cut off, the last output it printed in the same session is shown instead (never another session’s), and limits status says your status line timed out 3m ago until it next completes. off restores it.
  • The status line is shared with agent-gc sched, which needs the same numbers. Whichever of the two you turn on first installs it; turning one off keeps it while the other is on (limits status shows ~/.claude: on (limits, sched), snapshot 2m old), and your own line is restored only when both are off, in any order. A status line installed by an older sched on is taken over on the next limits on or sched on.
  • Your status line’s padding is kept while ours is on. If AGENT_GC_DATA_DIR is set when you run limits on, the installed command carries --data-dir <that folder>, since Claude Code runs the status line without your shell’s environment.
  • The status line writes the latest numbers to agent-gc’s data folder, one file per install. Nothing goes over the network: the numbers are the ones Claude Code passes to its status line.
  • Numbers from several sessions of one install are merged per window: the highest usage within the current block wins, and a session that reports nothing never erases them.
  • Installs signed in to the same account share one line in top; different accounts have separate limits and separate lines. The account id is read from Claude Code’s .claude.json only to group installs, and is never shown, logged or stored.
  • The header shows, per account, how much of each window is used (rounded down, as in the status line) and when it resets (5h 42% resets 17:00 local time, 7d 18% resets Thu). When no 5-hour block has started yet the header says 5h not started · 7d 22% resets Thu, and the column shows the share of usage (31%u, as without numbers). Numbers older than 15 minutes, or past their reset, count as unknown. The numbers and the closed sessions are read in the background (closed transcripts at most every 30 s), so top opens at once; until the first read finishes the header says limits: loading and the 5h column shows —.

The 5h column is each session’s share of its account’s 5-hour window, and it is an estimate (~12%). Anthropic does not publish how plan usage is counted, so each assistant message is weighted by the ratios of the public API prices:

input + 1.25 × cache write + 0.1 × cache read + 5 × output (tokens)

The weights of all transcripts (sessions and their subagents, open or closed) since the current 5-hour block started are summed per session, and the window’s used percentage is split in proportion. Subagents count toward the session that started them; sessions that are no longer running are summed into other ~8% in the header. This assumes the account is used only from Claude Code on this machine: usage from claude.ai, the desktop app or another computer on the same account would be attributed to the local sessions. Background sessions hidden from the list (until you press h) still count: their share is part of the totals, so the visible rows may add up to less than the window’s used percentage. A transcript is read back at most 16 MB from its end, so a very large session whose last 5 hours span more than that is undercounted.

Without fresh numbers the header says limits unknown: run agent-gc limits on when there are none at all, or limits stale (last numbers 20m old) when the status line has not run in the last 15 minutes or the window has reset since; the column then shows 31%u: the session’s share of all local usage in the last 5 hours, by the same weights. It says how the sessions compare, not how much of the plan is left. The 7-day window is shown in the header only.

A session is stalled when it is busy and its own transcript has not been written for 2 minutes (top_stall_secs in the settings). For a stalled session its line says, after the name, what it is waiting on; the first line that applies wins:

  • subagent ac9ed17e (general-purpose): last write 10s ago: a subagent of this session is still working (its own last write). no writes yet instead of the time: it started but has not written anything. , also stalled: … follows when the subagent itself has been silent past the threshold, with what that subagent is waiting on (a pending tool call, or no local activity).
  • hook running: <command> / MCP <name> busy: a child process of Claude Code that runs one of your configured hook commands (directly or as sh -c <command>) is using CPU, or an MCP server is using CPU while no tool call is pending or the pending call is to that server.
  • Bash: cargo test --workspace (8m): a tool call has no result yet: the tool, the start of its main input (the command, file path or URL) and how long ago it was made. When the call started child processes, the busiest one follows: · child cargo 97% CPU. <1% CPU means it is barely running; CPU ? means it has been sampled only once so far (CPU needs two samples, 2 s apart). , may be waiting for input is added when the child has stayed below 1% CPU for over a minute: often a command waiting on a prompt nobody can see.
  • child sh running (started after last write, 1m) · <1% CPU: no tool call is pending, but a process under Claude Code (other than an MCP server) started after the session’s last write, so something local is still going on. agent-gc’s own status line runs (agent-gc statusline --install …, started by Claude Code every 30 s when limits or sched is on) and the commands they wrap are ignored.
  • waiting on model/API, no local activity (6m): none of the above. This is an inference by elimination: no process has started under Claude Code since the last write and no hook or MCP server is busy, so the session is presumably waiting on the model or the API (a long reply, a retry). Claude Code does not record API retries, so top cannot see them directly.

On a narrow terminal the number columns go one by one (MODEL, CMP, +10m, MEM, %CPU, PID, 5h) so the tree keeps at least 24 characters; when a stalled session’s line is still too short for its diagnosis, the full text of the selected one appears in the status line at the bottom. Diagnosis only: top never interrupts a stalled session on its own; enter takes you there and K ends it if you choose to.