Skip to content

feat(mods): add the firstmate-quota Claude Code mod showing every seat's quota - #25

Merged
max-metaplanet merged 4 commits into
mainfrom
fm/quota-mod
Oct 6, 2026
Merged

max-metaplanet merged 4 commits into
mainfrom
fm/quota-mod

Conversation

@max-metaplanet

@max-metaplanet max-metaplanet commented Oct 6, 2026 •

Copy link
Copy Markdown
Owner

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

  • Adds the firstmate-quota Claude Code mod under .claude/mods/firstmate-quota. Like Calm, it auto-loads through a .agents/skills symlink, and it does nothing unless FM_QUOTA_ENABLED is exactly 1. When enabled, it draws a band above the prompt and adds a /seats pane (plain text when the session can't draw) covering every configured seat:
    • This session's seat: percent left per window, taken from $.session.usage() and session.measure. Before the first reading, or when the session is not on a subscription, it draws nothing rather than a zero.
    • Other seats: each figure shows its own cache age and is labelled stale once it is older than the board's cache window.
  • Limits how often the mod reads seat data. Drawing never triggers a read. A session start does one cache-only read. Reads that can refresh from quota-axi happen at most once every 10 minutes, with only one running at a time. FM_QUOTA_REFRESH_SECONDS overrides the interval but can't go below 2 minutes. The pane's Refresh (r) only rereads the cache.
  • Adds a json [--cached-only] action to bin/fm-seat-board.sh. It prints a versioned per-seat record (schema 1) with ageSeconds, hasData, the attention line, the windows and liveSeat. Missing figures are null, not 0, and --cached-only never calls quota-axi.
  • Also includes:
    • Node tests for the mod, plus shell tests for the mod, its plugin loading and the new board action.
    • Routing for those tests in bin/fm-test-run.sh.
    • docs/quota-mod.md, with pointers from AGENTS.md and docs/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 json action 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 /seats through real claude -p with 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-off claude -p checks 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.

  • Live validation: ✅ go - 9 of 11 scenarios driven live against the product
Scenario Result Live Evidence
Captain enables FM_QUOTA_ENABLED=1 and starts Claude Code: the band shows the live seat's % left from session usage plus the tightest other seat with its age ✅ pass live r2-01-band-on-startup.txt: 'seat-max-gmail 5h 83% · 7d 60% (5d 20h) │ others tightest seat-max 3% (10d old, stale)'
Captain runs /seats: the pane lists every configured seat (default, seat-max, seat-max-gmail, seat-max2) with this-session/new-workers marks, figures, and each reading's age ✅ pass live r2-02-seats-pane.txt
A 10-day-old seat cache is labelled '(10d old, stale)', never presented as current ✅ pass live r2-02-seats-pane.txt and claude-p-seats-transcript.txt ('max-gmail: credentials_missing (10d old, stale)')
Ages advance with the clock: a reading shown as 43s old becomes '1m old, stale' 45s later without any new read ✅ pass live r2-02-seats-pane.txt (43s old, read 19s ago) -> r2-03-ages-advanced-to-stale.txt (1m old, stale; read 59s ago)
Pressing Refresh (r) inside the interval visibly rereads the cache, says when the next live refresh is allowed, and makes no refreshing read ✅ pass live r2-04-after-refresh-press.txt ('read 0s ago; next live refresh in 9m'); r2-cache-mtimes-before/after identical
Never hammer quota-axi: a cached-only read (session start, /seats, Refresh) makes zero quota-axi calls even with a cold or 10-day-old cache ✅ pass live seat-board-json-transcript.txt (call count unchanged across cached-only reads); claude-p-seats-transcript.txt ('quota-axi calls made during the /seats run: 0')
A refreshing read refills an expired cache through the board, and a second one inside the 60s window reuses the cache ✅ pass live seat-board-json-transcript.txt steps 4-5 (2->5 calls, then still 5)
/seats in a session that cannot draw (claude -p) answers with the same content as text, with no model turn ✅ pass live claude-p-seats-transcript.txt (num_turns 0, cost $0)
Gate unset: no band and no /seats command, so the mod is a complete no-op ✅ pass live r2-05-gate-off.txt (no band line; /seat completion lists no /seats); claude-p-seats-transcript.txt gate-off run falls through to the model with 0 seat reads
Live refresh lands once per interval (10 min default, 2 min floor) and a cached read in flight cannot spend the interval ⏸️ untested no Watching a real interval land needs an interactive session held open for 2-10+ minutes, and it makes real quota-axi reads against rate-limited seats. I kept the lab short to avoid that. To re-run it:…
Live seat with no rateLimits (off subscription or before the first reading) draws nothing rather than a zero ⏸️ untested no The interactive Max-plan session already had a reading at startup. Seeing the empty band live needs an API-key (non-subscription) Claude login, which this machine does not have set up.
Evidence: Band on startup (interactive Claude Code, lab)

Source: Band on startup (interactive Claude Code, lab)


 ▐▛███▛█   Claude Code v2.1.291
▝▜██████▀  Opus 5.5 · Claude Max
 ▝▝   ▝▝   ~/.no-mistakes/worktrees/61c6dd39b831/01M4862X6MG5M49F15PE5RCEGF




























seat-max-gmail 5h 83% · 7d 60% (5d 20h)  │  others tightest seat-max 3% (10d old, stale)                           [-]

───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
❯ Try "refactor fm-seat.test.sh"
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
  ⚠ Transcript saving is off — inherited CLAUDE_CODE_CHILD_SESSION marker · restart with CLAUDE_CODE_FORCE_SESSION_P…
  Opus 5.5 | ~/./w/6/01M4862X6MG5M49F15PE5RCEGF [HEAD ✓] | ⚙️30 | ⚡100% | P02=E05=U09=J18:18:31
  -- INSERT -- ⏵⏵ auto mode on (shift+tab to cycle)
Tue Oct  6 05:18:48 EDT 2026
Evidence: /seats pane with per-seat ages and stale label

Source: /seats pane with per-seat ages and stale label

                                                                      │                                              ✕
 ▐▛███▛█   Claude Code v2.1.291                                       │seat-max-gmail 5h 83% · 7d 60% (5d 20h)  live
▝▜██████▀  Opus 5.5 · Claude Max                                      │defau [new     session 85% · week 60% ·   (43s
 ▝▝   ▝▝   ~/…/worktrees/61c6dd39b831/01M4862X6MG5M49F15PE5RCEGF      │lt    workers] Fable week 99%             old)
                                                                      │seat-m session 100% · week 3% ·      (10d old,
                                                                      │ax     Fable week 100%               stale)
                                                                      │seat-max [this     session 85% · week 60%  (44s
                                                                      │-gmail   session]  · Fable week 99%        old)
                                                                      │seat-ma session 97% · week 24% · Fable   (44s
                                                                      │x2      week 100%                        old)
                                                                      │cached readings over 60s old are stale; only th…
                                                                      │read 19s ago; next live refresh in 10m
                                                                      │r: Refresh
                                                                      │
                                                                      │
                                                                      │
                                                                      │
                                                                      │
                                                                      │
                                                                      │
                                                                      │
                                                                      │
                                                                      │
                                                                      │
                                                                      │
                                                                      │
                                                                      │
                                                                      │
                                                                      │
                                                                      │
                                                                      │
                                                                      │
seat-max-gmail 5h 83% · 7d 60% (5d 20h)  │  others tightest seat… [-] │
                                                                      │
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
❯
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
  ⚠ Transcript saving is off — inherited CLAUDE_CODE_CHILD_SESSION marker · restart with CLAUDE_CODE_FORCE_SESSION_P…
  Opus 5.5 | ~/./w/6/01M4862X6MG5M49F15PE5RCEGF [HEAD ✓] | ⚙️30 | ⚡100% | P02=E05=U09=J18:18:31
  -- INSERT -- ⏵⏵ auto mode on (shift+tab to cycle)
Tue Oct  6 05:18:54 EDT 2026
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

                                                                      │                                              ✕
 ▐▛███▛█   Claude Code v2.1.291                                       │seat-max-gmail 5h 83% · 7d 60% (5d 20h)  live
▝▜██████▀  Opus 5.5 · Claude Max                                      │defa [new     session 85% · week 60% · (1m old,
 ▝▝   ▝▝   ~/…/worktrees/61c6dd39b831/01M4862X6MG5M49F15PE5RCEGF      │ult  workers] Fable week 99%           stale)
                                                                      │seat-m session 100% · week 3% ·      (10d old,
                                                                      │ax     Fable week 100%               stale)
                                                                      │seat-max [this s session 85% · week 60% (1m old,
                                                                      │-gmail   ession] · Fable week 99%       stale)
                                                                      │seat-m session 97% · week 24% ·      (1m old,
                                                                      │ax2    Fable week 100%               stale)
                                                                      │cached readings over 60s old are stale; only th…
                                                                      │read 59s ago; next live refresh in 9m
                                                                      │r: Refresh
                                                                      │
Tue Oct  6 05:19:47 EDT 2026
Evidence: After pressing Refresh (r): cached reread + next live refresh time

Source: After pressing Refresh (r): cached reread + next live refresh time

                                                                      │                                              ✕
 ▐▛███▛█   Claude Code v2.1.291                                       │seat-max-gmail 5h 83% · 7d 60% (5d 20h)  live
▝▜██████▀  Opus 5.5 · Claude Max                                      │defa [new     session 85% · week 60% · (2m old,
 ▝▝   ▝▝   ~/…/worktrees/61c6dd39b831/01M4862X6MG5M49F15PE5RCEGF      │ult  workers] Fable week 99%           stale)
                                                                      │seat-m session 100% · week 3% ·      (10d old,
                                                                      │ax     Fable week 100%               stale)
                                                                      │seat-max [this s session 85% · week 60% (2m old,
                                                                      │-gmail   ession] · Fable week 99%       stale)
                                                                      │seat-m session 97% · week 24% ·      (2m old,
                                                                      │ax2    Fable week 100%               stale)
                                                                      │cached readings over 60s old are stale; only th…
                                                                      │read 0s ago; next live refresh in 9m
                                                                      │r: Refresh
                                                                      │
Tue Oct  6 05:19:58 EDT 2026
Evidence: Cache mtimes before/after Refresh (identical)

Source: Cache mtimes before/after Refresh (identical)

total 80
-rw-r--r--@ 1 max  staff  5598 Oct  6 05:18:06 2026 _Users_max__claude-seats_seat-max-gmail.json
-rw-r--r--@ 1 max  staff  5642 Sep 26 05:18:00 2026 _Users_max__claude-seats_seat-max.json
-rw-r--r--@ 1 max  staff  5780 Oct  6 05:18:06 2026 _Users_max__claude-seats_seat-max2.json
-rw-r--r--@ 1 max  staff  5776 Sep 26 00:40:35 2026 default.json
-rw-r--r--@ 1 max  staff  1033 Sep 24 16:07:49 2026 seat-max.json
-rw-r--r--@ 1 max  staff  3852 Sep 24 16:07:49 2026 seat-max2.json
Evidence: Gate off: no band, /seats not offered

Source: Gate off: no band, /seats not offered


 ▐▛███▛█   Claude Code v2.1.291
▝▜██████▀  Opus 5.5 · Claude Max
 ▝▝   ▝▝   ~/.no-mistakes/worktrees/61c6dd39b831/01M4862X6MG5M49F15PE5RCEGF

























    /setting-mac-reminders                         Use when the user wants to schedule a recurring or one-shot popup
                                                   reminder on macOS — phrases like "remind me every Wednesday", "se…
    /web-setup                                     Set up cloud sessions with your GitHub account
    /status                                        Show Claude Code status including version, model, account, API
                                                   connectivity, and tool statuses
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
❯ /seat
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
  ⚠ Transcript saving is off — inherited CLAUDE_CODE_CHILD_SESSION marker · restart with CLAUDE_CODE_FORCE_SESSION_P…
  Opus 5.5 | ~/./w/6/01M4862X6MG5M49F15PE5RCEGF [HEAD ✓] | ⚙️29 | ⚡100% | P02=E05=U09=J18:21:26
  -- INSERT -- ⏵⏵ auto mode on (shift+tab to cycle)
Tue Oct  6 05:21:39 EDT 2026
Evidence: claude -p /seats text fallback transcript

Source: claude -p /seats text fallback transcript

$ FM_QUOTA_ENABLED=1 claude -p /seats --output-format json   (fake seat home: max2 cache 1m old, max-gmail cache 10 days old; real Claude Code 2.1.291)
{
  "result": "firstmate-quota: ~/.claude-seats/seat-max-gmail (this session): no rate-limit reading yet\ndefault: no quota data (quota-axi unavailable or the read timed out) (no reading)\nmax-gmail: credentials_missing (10d old, stale)\nmax2 [new workers] [email protected]: session 37% · week 71% (1m old, stale)\ncached figures older than 60s are shown as stale; this session's own figures are live",
  "num_turns": 0,
  "total_cost_usd": 0
}

quota-axi calls made during the /seats run: 0

$ env -u FM_QUOTA_ENABLED claude -p /seats --max-turns 1 --output-format json
(gate off: no mod command answers; the prompt falls through to the model, num_turns>0, cost>0, and the mod made no seat read)
{"subtype":"error_max_turns","num_turns":2,"total_cost_usd":0.4460146,"stop_reason":"tool_use"}
quota-axi calls after gate-off run: 0
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

$ # 1. cold cache, cached-only read (must make zero quota-axi calls)
$ fm-seat-board.sh json --cached-only
{"liveSeat":"default","activeSeat":"max2","cacheSeconds":60,"seats":[{"name":"default","hasData":false,"ageSeconds":null,"attention":"no quota data (quota-axi unavailable or the read timed out)","windows":0},{"name":"max-gmail","hasData":false,"ageSeconds":null,"attention":"no quota data (quota-axi unavailable or the read timed out)","windows":0},{"name":"max2","hasData":false,"ageSeconds":null,"attention":"no quota data (quota-axi unavailable or the read timed out)","windows":0}]}
(eval):8: no such file or directory: /tmp/fmq-live.6lIr/calls.log
quota-axi calls so far: 0

$ # 2. refreshing read fills the cache
$ CLAUDE_CONFIG_DIR=<seats>/max2 fm-seat-board.sh json
{"liveSeat":"max2","activeSeat":"max2","seats":[{"name":"default","active":false,"hasData":true,"ageSeconds":0,"account":"[email protected]","attention":null,"windows":[{"label":"session","percentRemaining":37},{"label":"week","percentRemaining":71}]},{"name":"max-gmail","active":false,"hasData":true,"ageSeconds":0,"account":null,"attention":"credentials_missing","windows":[]},{"name":"max2","active":true,"hasData":true,"ageSeconds":0,"account":"[email protected]","attention":null,"windows":[{"label":"session","percentRemaining":37},{"label":"week","percentRemaining":71}]}]}
quota-axi calls so far:        2

$ # 3. age the cache files 10 days, then cached-only read again
[{"name":"default","hasData":false,"ageSeconds":null,"windows":[]},{"name":"max-gmail","hasData":true,"ageSeconds":864052,"windows":[]},{"name":"max2","hasData":true,"ageSeconds":864052,"windows":[37,71]}]
quota-axi calls so far:        2  (unchanged => cached-only never reached quota-axi)

$ # 4. refreshing read on the 10-day-old cache refills it
[{"name":"default","ageSeconds":0},{"name":"max-gmail","ageSeconds":1},{"name":"max2","ageSeconds":0}]
quota-axi calls so far:        5

$ # 5. a second refreshing read inside the 60s window re-uses the cache
[{"name":"default","ageSeconds":3},{"name":"max-gmail","ageSeconds":3},{"name":"max2","ageSeconds":1}]
quota-axi calls so far:        5
Evidence: Fake quota-axi call log

Source: Fake quota-axi call log

1791278091 CLAUDE_CONFIG_DIR=/tmp/fmq-live.6lIr/seats/max2 --provider claude --no-credential-refresh --full --json
1791278091 CLAUDE_CONFIG_DIR=/tmp/fmq-live.6lIr/seats/max-gmail --provider claude --no-credential-refresh --full --json
1791278092 CLAUDE_CONFIG_DIR= --provider claude --no-credential-refresh --full --json
1791278092 CLAUDE_CONFIG_DIR=/tmp/fmq-live.6lIr/seats/max-gmail --provider claude --no-credential-refresh --full --json
1791278094 CLAUDE_CONFIG_DIR=/tmp/fmq-live.6lIr/seats/max2 --provider claude --no-credential-refresh --full --json
Evidence: Targeted test transcripts

Source: Targeted test transcripts

=== tests/fm-quota-claude-mod-plugin.test.sh
ok - Claude Code 2.1.291 (Claude Code) validates the Quota mod strictly at its folder and its auto-load path, hooking exactly the account measurement, the band, the seats pane, and /seats
ok - Claude Code 2.1.291 (Claude Code) runs the Quota mod's plugin test suites clean: the activation gate, the live band, the dated seats pane, its text fallback, and the refresh cadence
ok - the seat reader prints schema 1 with every seat dated, and its cached-only form makes no quota call
exit=
=== tests/fm-quota-claude-mod.test.sh
ok - the Quota mod declares one hooks module, nothing that loads on its own, and is reachable from the project auto-load path
ok - the live-seat policy converts percent used to percent left, clamps nonsense, draws nothing for an empty reading, and never guesses a reset
ok - the all-seats policy dates every figure, calls anything past the board's cache window stale, says when a seat has no reading, and refuses a reading of another schema
ok - the refresh cadence defaults to ten minutes, cannot be driven below its floor, and spends one interval on one read however often it is asked
# all fm-quota-claude-mod tests passed
exit=
=== tests/fm-seat-board.test.sh
ok - render lists a named seat with its windows and extra-usage spend
ok - render shows an attention line for a seat that is not logged in
ok - render shows a rate-limited seat's error as-is
ok - a reload within the cache window does not read quota-axi again
ok - render reads quota-axi without refreshing or prompting for credentials
ok - the cache is scoped to each seat's config dir, not its name
ok - render escapes markup in quota-axi text
ok - serve rejects a missing or non-numeric port
ok - json reports every seat with its own cache age and the window those ages are judged against
ok - json marks the active seat, the live seat, and a seat held out of automatic rotation
ok - json reports a seat with no usable report as absent rather than as a zero
ok - json --cached-only reports an empty cache as no data and never reads quota-axi
ok - json --cached-only serves an expired cached report with its real age, so a reader can call it stale
ok - json rejects an unknown flag
# all fm-seat-board tests passed
exit=
Evidence: Live run notes

Source: Live run notes

# firstmate-quota live run (this run, files prefixed r2-, plus claude-p-seats-transcript.txt and seat-board-json-transcript.txt)

Herdr lab fm-lab-quota3-91649-13547 (provisioned + torn down via bin/fm-herdr-lab.sh, teardown exit 0), Claude Code 2.1.291,
CLAUDE_CONFIG_DIR=seat-max-gmail, FM_SEAT_BOARD_CACHE_DIR = throwaway copy of ~/.cache/fm-seat-board
(seat-max file aged to 10 days, others touched to now). The real cache was never written.

- r2-01: FM_QUOTA_ENABLED=1, band on startup: live seat 5h/7d % left + reset wait, "others tightest seat-max 3% (10d old, stale)".
- r2-02 (05:18:54): /seats pane: every seat, [this session]/[new workers] marks, per-seat ages (43s/44s old, 10d old stale), "read 19s ago; next live refresh in 10m".
- r2-03 (05:19:47): no new read ("read 59s ago"), the same rows now say "(1m old, stale)": ages advance with the clock.
- r2-04 (05:19:58): Refresh (r): "read 0s ago; next live refresh in 9m"; cache mtimes identical before/after (r2-cache-mtimes-*), so no refreshing read.
- r2-05: relaunched with FM_QUOTA_ENABLED unset: no band, /seats is not in the command completions. Input was never submitted.

Unintended spend: one relaunch command was typed into a still-running Claude session and submitted as a prompt
(~$0.51, interrupted). Separately, the claude -p gate-off checks fell through to the model (~$0.45 each, several runs).
- Outcome: ⚠️ 1 info across 2 runs (21m52s)

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. ageSeconds comes from the board JSON and is kept in board. After that, the mod reads again only at session start (cached-only) and on a refresh at most every 600s. seatRows and seatFreshness never 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 show max2 … (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)/1000 to each ageSeconds before 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's Refresh button (hotkey r) calls tick($), which goes through refreshDecision. Within the refresh interval (default 10 min after session start or the last refresh) it returns wait, 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 runs fm-seat-board.sh json without --cached-only, and seat_quota_cached then 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 as FM_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 calls fm-seat-board.sh json for every seat, including the live seat. That spends a quota-axi call on the seat whose exact figures already come free from session.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 for liveSeat.

🔧 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 through startRead($, false), and that read sets reading. 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"), refreshDecision sees inFlight and returns claim-only. tick then sets lastClaimedAtMs = now and 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-only lists 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: make claim-only apply only when the in-flight read is a refreshing one, for example by tracking readingRefreshing. 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, because tick returns wait inside 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.

⚠️ **Test** - 1 info

✅ No issues found.

  • Live validation: ✅ go - 9 of 10 scenarios driven live against the product
Scenario Result Live Evidence
Captain starts Claude Code with FM_QUOTA_ENABLED=1 and sees a band with this seat's exact percent left from session.usage plus the tightest other seat with its age ✅ pass live 01-band-on-startup.txt: 'seat-max-gmail 5h 87% · 7d 61% (5d 21h) │ others tightest seat-max2 10% (10d old, stale)'
Captain opens /seats and sees every configured seat (default, max, max-gmail, max2) with figures, ages, and this-session / new-workers markers ✅ pass live 02-seats-pane.txt
10-day-old caches are labelled stale, and a seat with no report shows the reader's attention line instead of a zero ✅ pass live 02-seats-pane.txt: '(10d old, stale)' and 'no quota data (quota-axi unavailable…) (no reading)'
Pressing Refresh (r) visibly rereads the cache, says when the next live refresh is allowed, and does not touch the quota cache ✅ pass live 03-after-refresh-press.txt 'read 0s ago; next live refresh in 9m'; cache-mtimes-before/after-refresh.txt identical
Adversarial: hammering Refresh 8 times and setting FM_QUOTA_REFRESH_SECONDS=10 cannot drive quota reads faster than the 2-minute floor ✅ pass live cadence-watch.log: 'next live refresh in 2m', zero reads after 8 presses; temp-cache mtimes show reads only at 05:05:19-23 and 05:07:19-21; live-run-notes.md
Default cadence: one live refresh about 10 minutes after session start, none before ✅ pass live live-run-notes.md: w1 started ~04:59:3x; the real cache was refilled once at 05:09:54-58; no change at the 05:00:35 Refresh
A reading that is fresh when read becomes labelled stale as the clock passes the board's 60s window, without a new read ✅ pass live 05-fresh-reading.txt '(13s old)' then 06-same-reading-turned-stale.txt '(1m old, stale)'; cache mtimes unchanged
Adversarial: with FM_QUOTA_ENABLED unset the mod is a no-op (no band, no /seats command) ✅ pass live 07-gate-off.txt: no band line; typing /seats suggests only /usage
Mod loads from the project auto-load path and passes strict validation with no network, env-write, or fs-write capability ✅ pass live plugin-test.log (claude plugin validate --strict on the folder and .claude/skills path, plus claude plugin test suites)
Band draws nothing (never a zero) off a subscription or before the first rateLimits reading ⏸️ untested no Every available seat is a logged-in Claude Max subscription that has a rateLimits reading at startup. Driving this live needs an API-key or non-subscription Claude Code login in the lab.
  • tests/fm-quota-claude-mod-plugin.test.sh (strict validate at the folder and the auto-load path, the mod's own claude plugin test suites, 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-board json and json --cached-only actions)

  • bin/fm-seat-board.sh json --cached-only against the real ~/.cache/fm-seat-board (10-day-old caches; files left unmodified)

  • Herdr lab bin/fm-herdr-lab.sh name/provision/run/teardown; w1: claude with FM_QUOTA_ENABLED=1, band captured, /seats opened, r pressed, cache mtimes diffed

  • w2: claude with 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 mtimes

  • w3: claude with fresh temp cache files on the default interval; /seats read at 13s, then again after 80s

  • w3 relaunched with env -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 /seats checks 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

Scenario Result Live Evidence
Captain enables FM_QUOTA_ENABLED=1 and starts Claude Code: the band shows the live seat's % left from session usage plus the tightest other seat with its age ✅ pass live r2-01-band-on-startup.txt: 'seat-max-gmail 5h 83% · 7d 60% (5d 20h) │ others tightest seat-max 3% (10d old, stale)'
Captain runs /seats: the pane lists every configured seat (default, seat-max, seat-max-gmail, seat-max2) with this-session/new-workers marks, figures, and each reading's age ✅ pass live r2-02-seats-pane.txt
A 10-day-old seat cache is labelled '(10d old, stale)', never presented as current ✅ pass live r2-02-seats-pane.txt and claude-p-seats-transcript.txt ('max-gmail: credentials_missing (10d old, stale)')
Ages advance with the clock: a reading shown as 43s old becomes '1m old, stale' 45s later without any new read ✅ pass live r2-02-seats-pane.txt (43s old, read 19s ago) -> r2-03-ages-advanced-to-stale.txt (1m old, stale; read 59s ago)
Pressing Refresh (r) inside the interval visibly rereads the cache, says when the next live refresh is allowed, and makes no refreshing read ✅ pass live r2-04-after-refresh-press.txt ('read 0s ago; next live refresh in 9m'); r2-cache-mtimes-before/after identical
Never hammer quota-axi: a cached-only read (session start, /seats, Refresh) makes zero quota-axi calls even with a cold or 10-day-old cache ✅ pass live seat-board-json-transcript.txt (call count unchanged across cached-only reads); claude-p-seats-transcript.txt ('quota-axi calls made during the /seats run: 0')
A refreshing read refills an expired cache through the board, and a second one inside the 60s window reuses the cache ✅ pass live seat-board-json-transcript.txt steps 4-5 (2->5 calls, then still 5)
/seats in a session that cannot draw (claude -p) answers with the same content as text, with no model turn ✅ pass live claude-p-seats-transcript.txt (num_turns 0, cost $0)
Gate unset: no band and no /seats command, so the mod is a complete no-op ✅ pass live r2-05-gate-off.txt (no band line; /seat completion lists no /seats); claude-p-seats-transcript.txt gate-off run falls through to the model with 0 seat reads
Live refresh lands once per interval (10 min default, 2 min floor) and a cached read in flight cannot spend the interval ⏸️ untested no Watching a real interval land needs an interactive session held open for 2-10+ minutes, and it makes real quota-axi reads against rate-limited seats. I kept the lab short to avoid that. To re-run it:…
Live seat with no rateLimits (off subscription or before the first reading) draws nothing rather than a zero ⏸️ untested no The interactive Max-plan session already had a reading at startup. Seeing the empty band live needs an API-key (non-subscription) Claude login, which this machine does not have set up.
  • bin/fm-seat-board.sh json --cached-only and bin/fm-seat-board.sh json against 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 via bin/fm-herdr-lab.sh provision/run/teardown fm-lab-quota3-91649-13547: interactive claude with FM_QUOTA_ENABLED=1, captured band on startup, /seats pane, waited 45s for ages to cross 60s, pressed r, diffed cache mtimes, relaunched with the gate unset and typed /seat without submitting
  • tests/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.sh
  • tests/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.

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 max-metaplanet changed the title feat: add the firstmate-quota Claude Code mod showing every seat's quota feat(mods): add the firstmate-quota Claude Code mod showing every seat's quota Oct 6, 2026
@max-metaplanet
max-metaplanet merged commit 5355dfc into main Oct 6, 2026
22 checks passed
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant