Repository navigation
feat(plugin): per-agent cache clocks, saved of total, keep-alive hold time - #525
Conversation
OsherElhadad
left a comment
There was a problem hiding this comment.
Review: APPROVE at fa661aa. (Posted as a comment: GitHub does not let the author account approve.)
Verified:
- The branch is up to date with main. All 5 commits are by Osher-Elhadad and signed off, with no AI attribution.
gofmtandgo vetare clean.go testpasses forinternal/thread,dash,proxyandcontext-guru-plugin(nice 10, one package at a time).- The selected agent is not in the payload. In the 2.1.296 binary the status-line payload builder sets
agent:{name}fromKv(), which returnsmainThreadAgentType: the agent the session was started as, not the one selected in the agents view. Nothing else in the builder names an agent. The captured payloads agree:agent.nameis constant within a session. - Only
a:threads are agents.a:ids come only from a validx-claude-code-agent-idheader (thread.go), andp:ids are prefix-grouped. That is right for Claude Code, which is the only client this status line serves. - A plan never revives a cold entry.
KeepAlivePlansholdsk.muonly while reading, with no writes, no new pings and no other lock. It applies the sweep's own skip conditions (stopped,on(),MaxPings,pingable()) and is scoped by tenant. The plugin usesheldonly while the entry is still warm (rem > 0). - Tests fail without the changes. I checked each of these, and each fails its test:
- dropping
@from ValidHeaderID; - removing the tenant check or the
pingable()condition inKeepAlivePlans; - letting
heldapply to a cold entry; - listing
p:threads; - sending unbounded lean back to the lean path;
- dropping ping cost from the
of $ytotal.
- dropping
- Render time. With the PR's own stub harness on this host (15 renders per cell), every layout stays under 0.5 s. The worst is the slow-proxy case, with a maximum a little under the budget.
- Older plugins. An unbounded lean call goes to the full handler. That runs the same
Overview()plus the two credits the removed lifetime branch ran, so its cost is unchanged and the response is a superset of the fields an older plugin reads. @in thread ids. The header id goes only into NUL-separated in-memory keys, structured logs (only its length when invalid) and parameterised SQL. It never reaches a file path.saved $x of $y. Both figures are session-scoped, and the total uses the same pricing basis as the saving (agentcost_usd+cg_llm_cost_usd+ ping cost).
Non-blocking:
held_until_mscan overstate after a ping the limiter refused. The sweep advancesstartedAtandpingsbeforefire(pre-existing keeper bookkeeping), so the plan assumes a refresh that never happened. The plugin stays honest about the current entry, becauseremcomes from recorded rows. Only the↻horizon can be too long while the entry is still warm.KeepAlivePlansscans every live entry underk.muon each/api/cachestate. That lock is also on the request path. It is fine at today's sizes; a per-session index would make it O(threads) if hosted entry counts grow._agent_nameslists the session'ssubagents/directory and reads every.meta.jsonon every render. A long session with hundreds of agents pays that on each render, so consider caching by directory mtime.- The slow-proxy render sits just under 0.5 s. That margin is the fetch timeout, not this PR, but a busy host has little headroom.
OsherElhadad
left a comment
There was a problem hiding this comment.
Re-review: APPROVE at fa661aa (the head, which includes 'mark active sub-agents, most recent first, at most five'). (Posted as a comment: GitHub does not let the author account approve.)
- Clock.
agois the server'snow_msminus the agent'smax(last_ts, end_ts), plus the cachestate response's age, so both readings come from one clock and client skew doesn't matter. - Order and cap.
sortedis stable, so ties keep id order. With 5 named agents there is no+N more; with 6 or 7 it shows+1/+2 more(the newmany-agents-cappedgolden). With 0 named agents the unnamed form is unchanged. - Tests fail without the change. Sorting by id instead of recency fails
many-agents-capped, and so does raising the cap to 6. - Render time. The stub harness on this host keeps every layout under 0.5 s; the slow-proxy case peaks just under 400 ms.
- Docs. They now state the selected-agent limitation plainly, and the tmux-pane teammate paragraph matches what the line does.
go vetis clean, the plugin status-line goldens pass, the commit is signed off with no AI attribution, and the PR text has no numbers.
Nits (non-blocking):
+N morealso counts warm agents that have no name on disk, so it means "more warm agents", not "more named ones".- If a response ever lacked
now_ms,agowould fall back to the response age, and every agent would read asactive. The server always sendsnow_ms, including on thenonepath, so this is theoretical.
Approved.
OsherElhadad
left a comment
There was a problem hiding this comment.
Re-review: APPROVE at 76145b2. (Posted as a comment: GitHub does not let the author account approve.)
refreshedAtis set when the entry is created (the real request's start) and afterwards only inrecord1andrecordSummarySubstituteunderk.mu, whenCacheRead > 0. The sweep's pre-send bump ofstartedAtnever touches it, andKeepAlivePlansreads it under the same lock.go test -race ./proxy -run KeepAlivePlan -count=5passes.heldUntilwalks the plan fromRefreshedMS + TTLand stops at the first ping that would come after expiry.- Mutations:
KeepAlivePlansreportingstartedAtmakes TestKeepAlivePlanCountsOnlyPingsThatRefreshed fail, and dropping the expiry stop inheldUntilmakes TestHeldUntilStartsFromTheLastRealRefresh fail. gofmtandgo vetare clean, and the dash cache-state tests and plugin status-line goldens pass. The commit is signed off with no AI attribution.
Non-blocking: the CacheRead > 0 gate itself is not pinned. The test's failing ping is a transport error that never reaches record1. With the gate replaced by true in record1, or in the summary-substitute path, every test still passes. Add a ping that answers 200 with cache_read: 0 and a full write, and assert RefreshedMS does not move.
OsherElhadad
left a comment
There was a problem hiding this comment.
Re-review: APPROVE at ea0da82. It adds one test, TestAPingThatReadNothingIsNotARefresh. With record1's u.CacheRead > 0 refresh gate replaced by true, that test fails; with the gate it passes under -race. The summary-substitute path's copy of the gate is still unpinned, as noted. The approval stands.
amiddavid
left a comment
There was a problem hiding this comment.
Verdict
Changes requested. The code is sound and all tests pass. One user requirement is not met (finding 1). Finding 2 is a wording and basis problem in the main figure.
Findings
-
Requirement gap: no per-agent money.
- Asked for: main session
saved $x of $y, and each sub-agent<name>: saved $z of $q. - Today the line shows
saved $x of $yonce, for the whole session. That figure comes from/api/stats?lean=1&session=<id>(statusline.py_save_segment). - Each sub-agent shows only its name, an
activemark, a cache clock and↻(_agents_segment). No cost. No saving. - The data exists.
requestsrows havethread_id,cost_usdandbaseline_cost_usd.dash/cachestate.go:117already doesGROUP BY r.thread_idfor the session, bounded to the last 2 h, limit 16. - Proposal: add per-thread
cost_usdandbaseline_cost_usd(andcg_llm_cost_usd) to the/api/cachestatethread rows. Use the same query. The query is one indexed read onidx_requests_session, so cost does not grow with session size. The plugin then showssaved = baseline - cost - cg_llmper agent. Per-thread keep-alive credit and ping cost need the sameGROUP BY. If a per-agent figure leaves them out, the line must say so. - Do not use a second lean call per agent. That is N queries per render.
- Asked for: main session
-
saved $x of $ycan read as nonsense.xis a saving against the uncompacted baseline.yis what the session actually cost, after the saving. They are not a part and a whole.statusline.py_save_segment,dash/savings.go:56.- Failing case:
total_saved_usd=9.00,cost_usd=1.00,cg_llm=0.10,ping=0.05. The line showssaved $9.00 of $1.15. - This happens on any session with a reduction over 50 %. The reader sees a part larger than the whole.
- Bases do match otherwise:
cost_usd,cg_llm_cost_usdand ping cost come from the same rows, andxis already net ofcg_llmand pings. - Proposal: use the baseline as
y(cost + saved: "saved $9 of $10.15"), or change the wording ("saved $9.00, paid $1.15"). Say which in the docs. - Also check:
total_saved_usdin a session scope addsCachesplitHistoricalUSDandDeclFilterSavings(overview_lean.go:44-55). Those are read-time-priced credits. Do they belong in a figure shown plainly, with no≈? Release rule says estimates stay apart from real savings. See Questions.
-
_agent_nameshas no bound. It opens everyagent-*.meta.jsonin the session folder on every render, with no cache and no deadline.- Measured: 3000 files, warm disk, 0.18 s (about 36 % of the 0.5 s budget). A cold disk is slower.
- It runs after the parallel gather, so the gather deadline does not cover it.
- Proposal: look up only the ids that
/api/cachestatelists (a:<id>maps toagent-<id>.meta.json, a direct path). Scan the folder only forname@teamids, and cache the result by directory mtime. Cap the scan.
-
Same name, same label. Two sub-agents of type
Exploreboth show asExplore. The reader cannot tell which clock is which. Minor. Add a suffix (Explore 2) or use the description when names repeat.
What I verified
- Worktree
review-525atea0da82. Tests run on box 1:dash,internal/thread,context-guru-plugin(356 s),proxy(KeepAlive/Plan): all pass. - Merge with #519:
git merge-treeof the PR head and #519 gives no conflict. Meaning is compatible. Main thread keeps id"", andKeepAlivePlansandcachestateboth key main on""/t.Main. Onlya:rows are listed, so #519's header-thread rule does not affect them. - Held-warm clock (
heldUntil,refreshedAt): starts from the last ping that read the cache (CacheRead > 0), not from the sweep'sstartedAt. A refused, failed or timed-out ping does not move it. A ping in flight shows a shorter hold until it ends (it under-promises, never over-promises). The Python side ignores the plan when the entry already expired (_until_cold). So a cold cache is not shown warm. This covers the #532 60 s timeout case. - Lifetime path: no caller of
since=0oroverviewLeanLifetimeExactis left in the plugin or the proxy. The golden test asserts nosince=read. An older plugin that sendslean=1&since=0gets the full handler. Answer is exact, same cost as before (it was an unbounded exact read before too). _agent_rowswith missingnow_msor a badlast_tsreturns[], no exception.ValidHeaderIDacceptsname@team. Test added.
Questions
- Are
CachesplitHistoricalandDeclFilterSavingsmeasured or modelled? If modelled, should they sit outsidesaved $x? - With no valid
session_idin the payload,_fetch_statscallslean=1with no session. That now reaches the full handler on every render (before: the same exact lifetime read). The line then shows the whole-proxy total as "session". Should it show nothing instead? - Held clock assumes every planned ping succeeds (for example a 401 on pings). The clock then over-promises until the first failure. Accepted?
Reviewed by an AI reviewer (Claude)
SummaryRequirement from the product owner for this PR, for release v0.5.1. It replaces finding 1 of the first review. Confirmed by the owner on 2026-10-14. The main agent's status line shows its own spend and the total of all its subagents, side by side. Each listed agent also shows its own figure next to its cache clock. Definitions
DataThe first review found that the per-thread Posted by an AI assistant (Claude), for the release integrator. |
…t header Claude Code sends x-claude-code-agent-id as <name>@<team> for agent-team teammates. The '@' failed ValidHeaderID, so every teammate fell back to prefix continuity and got a p: thread that cannot be mapped to an agent. Signed-off-by: Osher-Elhadad <[email protected]>
/api/cachestate reports, per thread the keeper still plans to ping, pings_left and held_until_ms (the last planned ping plus the cache lifetime), from a read-only hook into the keeper's in-memory entries. Lean /api/stats adds keepalive_pings to its single aggregate. The lean lifetime path (since=0, no session) is removed: nothing on a render reads it any more, and a lean call with no bound is now served by the full handler, which returns the same exact answer (refs #510). Signed-off-by: Osher-Elhadad <[email protected]>
…p-alive hold - saved $x of $y: this session's saving out of the session's proxy cost; the today and lifetime totals and their background reads are gone. - agents: every sub-agent's cache under the name Claude Code's agents list shows (from the session's subagents/*.meta.json), warm clocks and a cold count. Claude Code does not pass the selected agent to the status line, so the selected agent is found by name. - cache: with a keep-alive plan the clock is the time until cold and shows ↻; ka N pings $z is the session's pings and their cost. - docs and images updated. Signed-off-by: Osher-Elhadad <[email protected]>
Signed-off-by: Osher-Elhadad <[email protected]>
A sub-agent with a request in the last 10 s is marked active; the named list is sorted by recency and capped at five, then +N more. Docs state the selected-agent limitation plainly and cover tmux-pane teammates, which are their own sessions with their own status line. Signed-off-by: Osher-Elhadad <[email protected]>
The sweep advances an entry's startedAt and ping count before a ping is sent, so after a refused or failed ping the plan's next ping could come after the entry had already expired, and held_until overstated how long the cache stays warm. The keeper now keeps refreshedAt (the real request's start, then each ping that read the cache), and held_until walks the plan from it, stopping at the first ping that would come too late. Signed-off-by: Osher-Elhadad <[email protected]>
Signed-off-by: Osher-Elhadad <[email protected]>
…e basis The money line is now two figures from /api/cachestate: saved $x of $y session (the main thread) and saved $x of $y subagents (every other thread together, side requests included). y is what the requests would have cost without context-guru, on the same prices; x is the saving against it, net of context-guru's own model calls and keep-alive pings, so x <= y. Only savings written per request count; the read-time credits are left out. /api/cachestate computes both in its existing per-thread GROUP BY: one indexed read of the session, money over every row, cache fields from each thread's latest cache-touching row. Also: without a session id the status line no longer reads the proxy-wide total (it probes /healthz); sub-agent names are read only for the threads the proxy lists, with capped opens, bytes and directory entries; two agents with one name read Explore, Explore 2; the keeper's refresh time is set outside the entry literal. Signed-off-by: Osher-Elhadad <[email protected]>
Signed-off-by: Osher-Elhadad <[email protected]>
ea0da82 to
ee7b7f1
Compare
|
@amiddavid round 2 is ready at ee7b7f1, rebased on main (after #519). Here is each point. Finding 1 and the 2026-10-14 requirement: per-agent money. Done as the requirement defines it. The main line now shows
Finding 2: basis and wording.
Question 1: read-time credits. Question 2: no Question 3: held clock and failed pings. Fixed in two places:
So before the first failure the clock is the plan, and after it the clock is the entry's own expiry. Pinned by Finding 3: unbounded
Finding 4: duplicate names. Two agents with the same name now read Non-blocking notes from the earlier reviews.
Render time. Interleaved A/B against main, 50 renders per cell, money and three named agents in the stub: no measurable change, and the slowest render was 425 ms (slow proxy). Every layout stays under 0.5 s; the table is in #524. The conflict hunk in Tests: This is round 2, the last one. Please review at the head. |
OsherElhadad
left a comment
There was a problem hiding this comment.
Review: REQUEST CHANGES at ee7b7f1, for one formatting fix only. (Posted as a comment: GitHub does not let the author account request changes.)
Blocking:
- CI
build-testfails at lint withgofmt needed: dash/cachestate_test.go. The one-lineseed(t, rec, func() *Event { ...; return e }())near line 167 has to be split;gofmt -w dash/cachestate_test.gois the whole fix. Everything below holds at this head.
Verified:
- Money basis.
threadMoneyuses the dashboard's ownsavingsArithmetic, so x = baseline − cost − cg_llm + cachesplit_saved + keep-alive credit − pings, and y = baseline + cachesplit_saved + keep-alive credit. That makes y − x = cost + cg_llm + pings ≥ 0, so x ≤ y.- Every term is summed over the same rows of the thread: agent rows for baseline, cost, cg_llm, cachesplit and the keep-alive credit, and ping rows for the ping cost.
baseline_cost_usdis summed per row exactly assavings.go,overview.goandquery.goalready sum it, so the status line and the dashboard share one basis.- A negative x renders with a minus sign.
- Session and subagents split.
thread_id == ""is the main thread and every other thread is in subagents. Flipping that test makes TestCacheStateSplitsTheSessionsMoney fail, and so does dropping cachesplit and the keep-alive credit from y. - Bare columns. The select has exactly one
MAX(...), so SQLite takesupstream_ms,model, the prefix and the TTL subquery's inputs from the row that holds it. A thread with no such row has a NULL MAX and is used for its money only (last.Valid). - No session id. The status line probes
/healthzand never reads/api/stats. _agent_namesis bounded. On a sub-agent directory with 30,000 meta files and 100 listed ids, one call took about 1 ms and opened exactly 24 files.a:../..and dot-ids are skipped.- Render time. On the stub harness, the minimal, balanced, detailed and watch layouts stay under 0.5 s in every scenario. The slowest is the slow-proxy case, just under 0.4 s.
refreshedAt. It is set at creation, and afterwards only by a ping that read the cache (record1 and the summary-substitute path). The sweep's pre-send bump never moves it. The proxy plan tests pass.go vetis clean. The dashCacheState|CacheThreads|Lean|Golden|HeldUntiltests,internal/thread, proxyKeepAlivePlan|Refresh|Threadand the plugin status-line tests all pass. All commits are by Osher-Elhadad and signed off, with no AI lines, and the PR text has no experiment numbers.
Non-blocking:
- Nothing pins the single-MAX rule. I changed the ping SUM to a second
MAX(...), which makes SQLite's bare columns undefined, and every test still passed, because each fixture thread has at most one ping. A thread with two pings in TestCacheStateSplitsTheSessionsMoney, or an assertion that the query contains exactly oneMAX(/MIN(, would pin it. - The status line's
saved $xis not the same figure as the dashboard's total./api/statsalso addsDeclFilterSavingsandCachesplitHistorical, which threadMoney leaves out, so with the tool filter on the status line shows less. One sentence indocs/plugin/statusline.mdwould explain the gap. _num(main, "saved_usd") or 0.0would render a missing field as $0.00. The proxy always sends it, so this is moot today.
Signed-off-by: Osher-Elhadad <[email protected]>
OsherElhadad
left a comment
There was a problem hiding this comment.
Re-review: APPROVE at 9ed9685. The only change since ee7b7f1 is gofmt formatting in dash/cachestate_test.go, and the file is now gofmt-clean. CI is green (build-test, purego, trivy, DCO). Signed off. The earlier review's non-blocking notes stand: no test pins the single-MAX rule, and the saving can read lower than /api/stats with the tool filter on. This approval covers 9ed9685.
Each a: agent on the line now carries its own figure from its /api/cachestate thread row, on the same basis as the session and subagents totals; side threads stay in the total only. A narrow terminal drops the per-agent money first. A figure whose fields are missing renders nothing instead of $0.00. Tests pin the single-MAX bare-column rule (a thread with two pings and an older and a newer cache touch), and goldens cover a main-only session, two named agents plus a side thread, the narrow degrade and missing fields. Docs say the line counts only per-request savings, so it can read lower than the dashboard. Signed-off-by: Osher-Elhadad <[email protected]>
|
Update at 0686297, for the edited requirement and reviewer-2-2's notes.
@amiddavid this is the head for round 2. |
OsherElhadad
left a comment
There was a problem hiding this comment.
Re-review: APPROVE at 0686297. (Posted as a comment: GitHub does not let the author account approve.)
- Each listed
a:agent shows its ownsaved $z of $q, andp:threads count only in the subagents total._money_pairreturns nothing when either half is missing, so an unknown value never renders as $0.00. A golden covers the missing-fields case. - The earlier MAX note is closed. With the ping
SUMchanged toMAXincacheThreadsQuery, TestCacheThreadsTakesItsCacheFieldsFromTheLatestTouch fails. - The earlier docs note is closed. The statusline page now says the line can read lower than the dashboard's figure.
gofmtandgo vetare clean, and the dash CacheThreads/CacheState tests and the plugin status-line goldens pass. CI is green, and the commit is signed off with no AI attribution.
This approval covers 0686297.
Signed-off-by: Osher-Elhadad <[email protected]>
|
Point 3 of the edited requirement (per-agent figures) is in the head, 8c95e89. The code went in at 0686297; 9ed9685 did not have it.
Goldens in
The earlier small items are in too:
Live, on a real Claude Code 2.1.296 session with two foreground subagents, the line read: Each agent's Render time: every layout stays under 0.5 s; the slowest was 447 ms, in the slow-proxy case. CI is running on the head. @amiddavid please review round 2 at 8c95e89. |
OsherElhadad
left a comment
There was a problem hiding this comment.
Re-review: APPROVE at 8c95e89. The only change since 0686297, which I approved, is one golden: an agent with no money row shows no figure while the other agent keeps its own. The plugin status-line goldens pass and go vet is clean. CI is green, and the commit is signed off. This approval covers 8c95e89.
amiddavid
left a comment
There was a problem hiding this comment.
Verdict
Ready to merge from my side. All four round-1 points are fixed. The new money split meets the owner's comment. I found no defect. Two minor points and two questions are below. No third round.
Reviewed head: 8c95e89.
Findings
Round-1 points:
- Per-agent and split money (old finding 1, now the owner's comment): met.
- Main line:
saved $x of $y session · saved $x of $y subagents. The second part shows only when a thread other than""exists (_save_segment). - Each listed
a:agent shows its ownsaved $z of $qafter its clock (_agents_segment).p:threads are not listed. They count only insubagents(ThreadsFor:t.ID == ""is main, all others go toOthers). - Data comes from
/api/cachestate(money, plussaved_usdandbaseline_usdper thread). No new query. - I rendered a fixture with 1 main, 2
a:and 1p:thread. Output:saved $50.32 of $250.00 session · saved $60.03 of $300.00 subagents, andreviewer ... saved $1.20 of $6.00. An agent with no money shows no figure.
- Main line:
- Basis (old finding 2): fixed.
y = baseline + cachesplit + keep-alive credit.x = y - cost - cg_llm - pings(dash/cachestate.gothreadMoney). Sox <= y. The proxy's own calls and pings lowerxand are not added toy. The read-time credits (CachesplitHistoricalUSD,DeclFilterSavings) are out ofx. TestTestCacheStateSplitsTheSessionsMoneychecksx <= yand that ap:thread, a thread with no cache touch and a ping all count. - Unbounded name reads (old finding 3): fixed. At most 24 files opened, 4096 bytes each, at most 20000 directory entries listed. Plain ids use a direct path.
- Same label (old finding 4): fixed.
Explore,Explore 2. - No-session read (old question 2): fixed. With no
session_idthe line calls only/healthz. It no longer reaches the full handler.
New, minor:
- Cost of
/api/cachestatenow grows with the session. The thread query lost its 2 h bound. It reads every row of the session (indexed, same shape as lean). Measured on box 1 with the 20,000-row fixture: 70 ms (lean on the same fixture: 48 ms). The plugin calls both on each render, at most every 2 s, in parallel. This is inside the budget and is the cost the design needs. No change asked. Please note the number in the docs. - Agents with no name on disk show no money. The unnamed form (
agents 2 · soonest ◐ 0:50) has no per-agent figure. The owner's text says each listed agent shows one. This affects only non-Claude Code clients or an old Claude Code. Acceptable if you say so in the docs.
What I verified
- Tests on box 1:
dash(72 s),internal/thread,proxy(66 s),context-guru-plugin(362 s). All pass. CI is green. - Merge:
git merge-treeof8c95e89withorigin/main(now includes #519): clean. With #524 (9f9980f7): clean, and no conflict in meaning inproxy/keepalive.go. #524 retires entries throughk.retireandretireSessionStartedBefore.KeepAlivePlansreadsk.live, so a retired entry drops out of the plan. Its compact path retires the main thread only. The held-warm clock of an idle sub-agent stays. - Money for a session with no cache touch yet: the
noneanswer carriesmoney, and_main_cskeeps it. - Ping events carry the thread id (
keepalive.goping emit usesj.thread). Pings are charged to the right thread. - Bare-column rule of the single
MAXincacheThreadsQueryis pinned byTestCacheThreadsTakesItsCacheFieldsFromTheLatestTouch. EXPLAIN testTestCacheThreadsQueryIsIndexedis present. - Round-1 items I checked and found sound are unchanged: held-warm clock, lifetime path removal, fail-open.
Questions
- Teammate files are found by the name pattern
agent-a<name>-<hex>.meta.json. This is from the author's live check on 2.1.296. A different pattern in another Claude Code version leaves the teammate unnamed (shown as the unnamed form), not wrong. Is that accepted? - The status line
saved(this thread split) now differs from/api/statstotal_saved_usd(it adds the read-time credits). Do the dashboard and the status line need a line in the docs that says why they differ?
Reviewed by an AI reviewer (Claude)
…gin to 0.2.1 Both plugins changed in v0.5.1: the Claude Code plugin gained the lifecycle signal hooks (rossoctl#520, rossoctl#524) and the per-agent money status line (rossoctl#525); the Codex plugin gained its SessionEnd and SessionStart hooks (rossoctl#524). A new version number is what makes an installed plugin update. Assisted-By: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
What
The status line now answers per agent and per session:
saved $x of $y session · saved $x of $y subagents: session is the main thread; subagents is every other thread of the session together (sub-agents, teammates, and side requests such as the auto-mode classifier). In both,$yis what those requests would have cost without context-guru, at the same prices, and$xis the saving against it, net of context-guru's own model calls and keep-alive pings, so$x <= $y. Only savings recorded per request count. The today and lifetime totals are gone from the line. Each listed agent also shows its ownsaved $z of $qnext to its clock; side threads count only in the subagents total. A figure the proxy did not report is left out, never shown as$0.00. The line counts only per-request savings, so it can read lower than the dashboard, which also adds the tool-filter and historical cache-split credits.subagents/agent-*.meta.json), most recently used first, at most five then+N more,activefor a request in the last 10 s, cold ones counted.↻. A plan never revives an entry that already expired.ka N pings $z: this session's keep-alive pings and their cost (balanced and detailed layouts).Limitation: the status line cannot follow the selected agent
Claude Code (2.1.296) does not pass the status line anything about which agent is selected in its agents view. Checked in the CLI's payload builder and live: the stdin payload is identical before and after selecting a sub-agent. So the line shows the main agent plus every sub-agent by name, and the selected one is found by its name.
Agent-team teammates in their own tmux pane (
teammateMode: tmux) are separate Claude Code sessions with their own status line, which shows that teammate's own cache, keep-alive and money (checked live). In-process teammates are listed on the lead's line.Fixes found on the way
x-claude-code-agent-id: <name>@<team>.thread.ValidHeaderIDrejected@, so every teammate fell back to a prefix-groupedp:thread. It now getsa:<name>@<team>.p:threads. The status line now lists only header-nameda:threads, so they no longer show up as phantom sub-agents.Proxy changes
GET /api/cachestate:money.main/money.othersand per-threadsaved_usd/baseline_usd, computed in its existing per-threadGROUP BY(one indexed read of the session). Per thread (and top level for the main thread)pings_leftandheld_until_ms, from a read-only hook into the keeper's in-memory entries (dash.API.SetKeepAlivePlans). No new query.GET /api/stats?lean=1: addskeepalive_pingsto the existing single aggregate.since=0read, its detached refresher job andOverviewLean's lifetime branch are gone. A lean call with no session and no window is now answered by the full handler, which gives the same exact number, so an older installed plugin that still asks keeps working. The refresher itself stays for the mode layouts (spark,strip,heat).Tests
internal/thread:name@teamaccepted.dash: lean reports the session's pings and ping cost; cachestate exposes the plan (main thread and sub-agents, none for an unplanned thread); lean lifetime still equals full; goldenstats_leanupdated (the unbounded lean call is now the full handler's answer).proxy:KeepAlivePlansreports only entries that will still ping, scoped by session and tenant.saved $x of $y, named agents in both id forms,p:ignored, cold count, held clock, a plan that cannot revive a cold entry, narrow-width degrade, and nosince=read ever made.Docs:
docs/plugin/statusline.md,docs/dashboard.md, the statusline skill, and the affected status line images.Closes #510.