Repository navigation
feat(mods): add the firstmate-quota Claude Code mod showing every seat's quota - #25
Merged
Merged
Conversation
The captain runs four Claude seats and could see none of their quota from inside a session. The two halves of that picture have completely different costs, and the mod is built so it can never confuse them. This session's own seat is free and exact: Claude Code's $.session.usage() carries the account's rate-limit windows and session.measure fires when one moves, so the band needs no process, no quota-axi and no cache. The engine reports percent USED while every firstmate seat setting counts percent LEFT, so the conversion happens once; an empty reading draws nothing at all, because the engine reports no window off a subscription or before the first response and a missing figure must never read as an exhausted account. Every other seat comes from the per-seat reports bin/fm-seat-board.sh already caches, because the Claude quota endpoint rate-limits frequent polling. That script gains a `json` action printing the same reading as its page, with every seat dated from its own cache file, plus `--cached-only` for a read that cannot reach the endpoint at all. The board stays the one owner of the cache contract and of seat resolution, so the mod re-derives neither. Nothing is presented as current when it is not: each row carries its own age, anything past the board's own cache window is labelled stale, a seat with no readable report says so instead of showing a zero, and a reading of another schema is refused rather than half-drawn. The ten-day-old cache files on this machine are why that is a requirement and not a nicety. Drawing never reads anything, so no redraw becomes a quota call. A session start takes one cached read; after that a refreshing read is allowed once every ten minutes behind an in-flight guard, held to a two-minute floor however FM_QUOTA_REFRESH_SECONDS is set. The interval is claimed when a refresh comes due whether or not a read follows, so a burst of timer ticks arriving together after the machine slept spends one interval once rather than reaching the endpoint repeatedly. Activation follows the Calm mod's own firstmate-owned gate: FM_QUOTA_ENABLED must equal 1, firstmate never writes it anywhere, and the mod is otherwise a complete no-op. It deliberately does not read the deprecated CLAUDE_CODE_ENABLE_FUNCTION_HOOKS alias that Calm keeps for its own migration, because this mod never shipped behind that flag and honouring it would turn an unrelated older opt-in into a new drawing.
Rendering the mod against this machine's own seat reading put `5h 63% (20732d 9h)` on the band: no rate-limit window resets a month out, so a wait that long is a disagreement between the clock and the reset timestamp rather than a long window. Such a wait now reads as unreadable and draws nothing, the same as an absent or unparseable one, so the band cannot put a figure like that in front of the captain. A seat row with no markers also drew an empty marker cell, which still took a column gap; it now draws no cell at all.
max-metaplanet
force-pushed
the
fm/quota-mod
branch
from
October 6, 2026 09:23
8c3908a to
0c9d44b
Compare
max-metaplanet
added a commit
that referenced
this pull request
Oct 6, 2026
…t's quota (#25) * feat(quota): add the firstmate-quota Claude Code mod for every seat The captain runs four Claude seats and could see none of their quota from inside a session. The two halves of that picture have completely different costs, and the mod is built so it can never confuse them. This session's own seat is free and exact: Claude Code's $.session.usage() carries the account's rate-limit windows and session.measure fires when one moves, so the band needs no process, no quota-axi and no cache. The engine reports percent USED while every firstmate seat setting counts percent LEFT, so the conversion happens once; an empty reading draws nothing at all, because the engine reports no window off a subscription or before the first response and a missing figure must never read as an exhausted account. Every other seat comes from the per-seat reports bin/fm-seat-board.sh already caches, because the Claude quota endpoint rate-limits frequent polling. That script gains a `json` action printing the same reading as its page, with every seat dated from its own cache file, plus `--cached-only` for a read that cannot reach the endpoint at all. The board stays the one owner of the cache contract and of seat resolution, so the mod re-derives neither. Nothing is presented as current when it is not: each row carries its own age, anything past the board's own cache window is labelled stale, a seat with no readable report says so instead of showing a zero, and a reading of another schema is refused rather than half-drawn. The ten-day-old cache files on this machine are why that is a requirement and not a nicety. Drawing never reads anything, so no redraw becomes a quota call. A session start takes one cached read; after that a refreshing read is allowed once every ten minutes behind an in-flight guard, held to a two-minute floor however FM_QUOTA_REFRESH_SECONDS is set. The interval is claimed when a refresh comes due whether or not a read follows, so a burst of timer ticks arriving together after the machine slept spends one interval once rather than reaching the endpoint repeatedly. Activation follows the Calm mod's own firstmate-owned gate: FM_QUOTA_ENABLED must equal 1, firstmate never writes it anywhere, and the mod is otherwise a complete no-op. It deliberately does not read the deprecated CLAUDE_CODE_ENABLE_FUNCTION_HOOKS alias that Calm keeps for its own migration, because this mod never shipped behind that flag and honouring it would turn an unrelated older opt-in into a new drawing. * fix(quota): draw no reset wait when the clock and the timestamp disagree Rendering the mod against this machine's own seat reading put `5h 63% (20732d 9h)` on the band: no rate-limit window resets a month out, so a wait that long is a disagreement between the clock and the reset timestamp rather than a long window. Such a wait now reads as unreadable and draws nothing, the same as an absent or unparseable one, so the band cannot put a figure like that in front of the captain. A seat row with no markers also drew an empty marker cell, which still took a column gap; it now draws no cell at all. * no-mistakes(review): Advance seat ages with clock; make Refresh read cache * no-mistakes(review): Keep cached Refresh reads from spending the live refresh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Build a Claude Code mod in the firstmate repo: firstmate-quota, using the ALL-SEATS approach.
It provides a band and a /seats pane covering every configured Claude seat (max, max2, max-gmail), not just the current session.
For the live seat it uses $.session.usage() and session.measure; for the other seats it uses the seat board and quota sources firstmate already has, refreshed on a sane cadence, never hammering quota-axi (it rate-limits), and always showing each seat's data age honestly - stale caches must say stale.
Deploy it under .claude/mods/ the way Calm is, with tests, and with its own activation consistent with the Calm flag fix already in progress.
Ship via the no-mistakes PR path.
The source is a scout report on Claude Code mods, readable at ~/firstmate/data/claude-mods-research/report.md; sections 2 (platform limits), 5 (supervision-session ideas), 8 (build sketches), 9 (gotchas) and 10a (a working firstmate-fleet prototype that printed the real fleet) are the basis.
Calm, the one firstmate mod already shipped, lives at .claude/mods/firstmate-calm/ with a symlink from .agents/skills/, and a trusted project auto-loads it as a skills-dir plugin with no install step.
From the report: $.session.usage() returns rateLimits natively and session.measure fires when a plan limit's percent used changes, with no shell-out; rateLimits is empty off a subscription or before the first reading, so draw nothing then, never a zero.
The installed quota-axi reports one claude row, not one per seat; per-seat figures come from bin/fm-seat-lib.sh's fm_seat_quota_json pointed at each seat's CLAUDE_CONFIG_DIR, and bin/fm-seat-board.sh already caches each seat's report under ~/.cache/fm-seat-board because the endpoint rate-limits frequent polling.
A per-seat poll from a mod would be dozens of quota calls a minute; the report found the cache files on disk 10 days old, so a mod reading them must say so rather than present old percentages as current.
What Changed
firstmate-quotaClaude Code mod under.claude/mods/firstmate-quota. Like Calm, it auto-loads through a.agents/skillssymlink, and it does nothing unlessFM_QUOTA_ENABLEDis exactly1. When enabled, it draws a band above the prompt and adds a/seatspane (plain text when the session can't draw) covering every configured seat:$.session.usage()andsession.measure. Before the first reading, or when the session is not on a subscription, it draws nothing rather than a zero.FM_QUOTA_REFRESH_SECONDSoverrides the interval but can't go below 2 minutes. The pane's Refresh (r) only rereads the cache.json [--cached-only]action tobin/fm-seat-board.sh. It prints a versioned per-seat record (schema 1) withageSeconds,hasData, the attention line, the windows andliveSeat. Missing figures arenull, not0, and--cached-onlynever calls quota-axi.bin/fm-test-run.sh.docs/quota-mod.md, with pointers fromAGENTS.mdanddocs/claude-seats.md.🤖 Generated with Claude Code
Risk Assessment
✅ Low: The round-3 fix fully resolves refresh-burns-live-interval. Only a refreshing read can trigger claim-only, and a tick that finds the interval due waits out an in-flight cached read before it starts the refreshing read, so the live refresh no longer slips. Two concurrent refreshing reads are still impossible: the minimum interval (120s) is longer than the tick spacing (60s), and startRead still drops a second read. The two new tests check the elapsed-interval press and the cached-read-in-flight case.
Testing
I drove the seat reader's new
jsonaction live against a fake quota-axi that logs every call. The cached-only read never called quota-axi, a 10-day-old cache came back with its real age, and a refreshing read refilled it. Running/seatsthrough realclaude -pwith the mod enabled printed every seat with its age and a stale label: 0 turns, $0, and no quota call. In an isolated Herdr lab, an interactive Claude session drew the band and the /seats pane. With no new read, the ages moved from 43s to "1m old, stale". Pressing Refresh showed "read 0s ago; next live refresh in 9m" and left the cache files untouched. With the flag unset there was no band and no /seats command. The three targeted regression scripts also pass, including the mod's suites run under the real engine. Visual evidence is text captures of the terminal pane, not screenshots, because this is a terminal UI with no GUI to screenshot. I spent about $2.8 of seat-max-gmail usage by mistake. The gate-offclaude -pchecks went to the model (5 runs at about $0.45 each). A relaunch command was also typed into a session that was still running Claude, and got submitted as a prompt (about $0.51, interrupted). The lab was torn down cleanly, and the real ~/.cache/fm-seat-board was never written.Evidence: Band on startup (interactive Claude Code, lab)
Source: Band on startup (interactive Claude Code, lab)
Evidence: /seats pane with per-seat ages and stale label
Source: /seats pane with per-seat ages and stale label
Evidence: Same reading 45s later: ages advanced to stale with no new read
Source: Same reading 45s later: ages advanced to stale with no new read
Evidence: After pressing Refresh (r): cached reread + next live refresh time
Source: After pressing Refresh (r): cached reread + next live refresh time
Evidence: Cache mtimes before/after Refresh (identical)
Source: Cache mtimes before/after Refresh (identical)
Evidence: Gate off: no band, /seats not offered
Source: Gate off: no band, /seats not offered
Evidence: claude -p /seats text fallback transcript
Source: claude -p /seats text fallback transcript
Evidence: fm-seat-board.sh json / --cached-only transcript with quota-axi call counts
Source: fm-seat-board.sh json / --cached-only transcript with quota-axi call counts
Evidence: Fake quota-axi call log
Source: Fake quota-axi call log
Evidence: Targeted test transcripts
Source: Targeted test transcripts
Evidence: Live run notes
Source: Live run notes
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 5 issues found → auto-fixed (2) ✅
.claude/mods/firstmate-quota/hooks/register.ts:125- Each seat's age and its fresh/stale label are frozen at the moment of the last read.ageSecondscomes from the board JSON and is kept inboard. After that, the mod reads again only at session start (cached-only) and on a refresh at most every 600s.seatRowsandseatFreshnessnever add the time elapsed since that read. Example: the refresh at T reads seat max2's cache at 5s old. The pane and band then showmax2 … (5s old)as fresh, not stale, until T+10min. By then the figure is 9m55s old and well past the board's own 60s window. With FM_QUOTA_REFRESH_SECONDS raised, this wrong label can last hours. That breaks the required "always showing each seat's data age honestly - stale caches must say stale". Fix: record$.clock.now()when a read is parsed and add(now - readAt)/1000to eachageSecondsbefore computing freshness and ageWord. Alternatively, run a cached-only read on every tick: it costs no quota call and also picks up cache files refreshed by other sessions or the board server..claude/mods/firstmate-quota/hooks/register.ts:340- The pane'sRefreshbutton (hotkey r) callstick($), which goes throughrefreshDecision. Within the refresh interval (default 10 min after session start or the last refresh) it returnswait, so the button does nothing and gives no sign of it. A captain who presses Refresh sees the same frozen figures and ages. Decide whether Refresh should at least run a cached-only read (free: it cannot reach quota-axi) and/or say when the next refresh is allowed. This is a product-behaviour choice.docs/quota-mod.md:78- The docs say the mod "never writes: no seat setting, no configuration, no file at all", and register.ts's header says the same. That is not true. The refreshing read runsfm-seat-board.sh jsonwithout --cached-only, andseat_quota_cachedthen rewrites expired cache files under ~/.cache/fm-seat-board via a tmp file and mv. Reword it to say the mod changes no seat setting or configuration and only refreshes the board's own quota cache.docs/quota-mod.md:17- The docs and the register.ts gate comment describe Calm's gate asFM_CALM_ENABLED, with CLAUDE_CODE_ENABLE_FUNCTION_HOOKS kept only as a deprecated alias. Nothing in this tree defines FM_CALM_ENABLED. AGENTS.md (edited in this same diff) and Calm's plugin.json still say Calm activates only on CLAUDE_CODE_ENABLE_FUNCTION_HOOKS. This matches the intent's "Calm flag fix already in progress", but the docs are only accurate once that Calm change lands, so the merge order matters..claude/mods/firstmate-quota/hooks/register.ts:124- A refreshing read callsfm-seat-board.sh jsonfor every seat, including the live seat. That spends a quota-axi call on the seat whose exact figures already come free fromsession.measure. Across N concurrent sessions this adds N extra calls per interval against a rate-limited endpoint. The cost is bounded by the board's 60s cache, so this is minor, but the board's json action could skip the refill forliveSeat.🔧 Fix applied.
2 issues (1 warning, 1 info) still open:
.claude/mods/firstmate-quota/hooks/register.ts:178- Pressing Refresh can push the next live refresh back by a whole interval. Refresh now starts a cached-only read throughstartRead($, false), and that read setsreading. If the 60s ticker fires while it is still running and the interval has elapsed (exactly when the pane says "a live refresh is due"),refreshDecisionseesinFlightand returnsclaim-only.tickthen setslastClaimedAtMs = nowand returns without any refreshing read, so the live refresh slips by a full interval (10 min by default, longer if FM_QUOTA_REFRESH_SECONDS is raised).fm-seat-board.sh json --cached-onlylists seats and runs jq for each one, so the window is not negligible. This goes against the operator's rule that Refresh must not move the live refresh. Fix: makeclaim-onlyapply only when the in-flight read is a refreshing one, for example by trackingreadingRefreshing. When only a cached read is running, return without claiming, and the next tick retries..claude/mods/firstmate-quota/tests/quota.test.ts:313- The test named "never reaches the quota endpoint, even once the live interval has elapsed" advances only 599s against a 600s interval, so the interval never elapses. The old code (onPress: tick($)) would also pass it, becausetickreturnswaitinside the interval. Either rename the test, or press Refresh past the interval with the ticker held off (or between ticks) and assert there are no extra refreshing runs beyond the ticker's own one.🔧 Fix applied.
✅ Re-checked - no issues remain.
✅ No issues found.
✅ No issues found.
tests/fm-quota-claude-mod-plugin.test.sh(strict validate at the folder and the auto-load path, the mod's ownclaude plugin testsuites, and a real reader shape check)tests/fm-quota-claude-mod.test.sh(portable plugin shape and policy checks)tests/fm-seat-board.test.sh(seat-boardjsonandjson --cached-onlyactions)bin/fm-seat-board.sh json --cached-onlyagainst the real ~/.cache/fm-seat-board (10-day-old caches; files left unmodified)Herdr labbin/fm-herdr-lab.sh name/provision/run/teardown; w1:claudewith FM_QUOTA_ENABLED=1, band captured,/seatsopened,rpressed, cache mtimes diffedw2:claudewith FM_QUOTA_ENABLED=1, FM_QUOTA_REFRESH_SECONDS=10 and a temp FM_SEAT_BOARD_CACHE_DIR; 8 Refresh presses, then ~4 min of watching refresh timing via cache mtimesw3:claudewith fresh temp cache files on the default interval;/seatsread at 13s, then again after 80sw3 relaunched withenv -u FM_QUOTA_ENABLED claude; typed/seats(never submitted), no band and no command offeredℹ️ Validation spent about $2.8 of seat-max-gmail model usage by mistake. The gate-off
claude -p /seatschecks fell through to the model, which is itself proof that the mod serves nothing with the gate off, at about $0.45 per run. A relaunch command was also typed into a session that was still running Claude, and got submitted as a prompt (about $0.51, interrupted). This is not a product defect.Live validation: ✅ go - 9 of 11 scenarios driven live against the product
bin/fm-seat-board.sh json --cached-onlyandbin/fm-seat-board.sh jsonagainst an isolated FM_HOME/cache with a call-logging fake quota-axi (cold cache, 10-day-old cache, refill, 60s cache reuse)FM_QUOTA_ENABLED=1 claude -p /seats --output-format json(real Claude Code, fake seat home, fake quota-axi call log)env -u FM_QUOTA_ENABLED claude -p /seats --max-turns 1(gate off)Herdr lab viabin/fm-herdr-lab.sh provision/run/teardown fm-lab-quota3-91649-13547: interactiveclaudewith FM_QUOTA_ENABLED=1, captured band on startup,/seatspane, waited 45s for ages to cross 60s, pressedr, diffed cache mtimes, relaunched with the gate unset and typed/seatwithout submittingtests/fm-quota-claude-mod-plugin.test.sh(claude plugin validate --strict + claude plugin test suites in the real engine)tests/fm-quota-claude-mod.test.shtests/fm-seat-board.test.sh✅ **Document** - passed
✅ No issues found.
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ No issues found.
✅ **Push** - passed
✅ No issues found.
✅ No issues found.