Repository navigation
Description
Motivation
The single loudest unserved ask across every voice-of-customer source is a live "how close am I to the wall" view with a forecast: how much of my plan is left, and when will I hit the limit at this pace. Users describe it viscerally ("my lizard brain wants to hoard it"; weekly limits "gone in one or two days"), and the structural reason no one has built it is that no vendor exposes an official quota API for consumer plans. A local tool that already reads the session logs and the live rate-limit surfaces is the only thing that can physically see the signal, and see it across vendors in one place.
CodeBurn is already most of the way there without having named the target:
src/plan-usage.tsmodels plan periods, per-provider utilization, and a month-end projection (projectMonthEnd,PlanStatus = under | near | over).src/budget.tshas run-rate projection (projected = spent * totalDays / elapsedDays) and the guard hooks enforce caps in-session.- The menubar already fetches live quota windows:
ClaudeSubscriptionService(api/oauth/usage) andCodexSubscriptionService(wham/usage), with menubar: honor Retry-After on Claude quota 429s, back off failed refreshes #702 handling 429s and menubar: surface Codex limit-reset credits (count and next expiry) in the Plan tab #724 surfacing Codex limit-reset credits.
What's missing is the synthesis: a single quota model per plan, a burn-rate forecast against the plan window (not just the calendar month), pre-flight cost awareness, and one clear surface that answers "am I about to run out." This epic scopes that, decoupled so pieces can land independently.
Non-goals (this epic)
- No new network polling loops. Everything rides the existing refresh lifecycle (single-flight, backoff, Retry-After), the rule menubar: honor Retry-After on Claude quota 429s, back off failed refreshes #702/menubar: surface Codex limit-reset credits (count and next expiry) in the Plan tab #724 established.
- No request-path proxy or model routing (that is the separate deferral/routing track, Design: tool-def deferral coverage (detect deferral gaps, restore/tune native deferral, proxy for non-native agents) #614 part 3).
- No scraping of undocumented endpoints beyond the ones the official clients already call with the same auth we already hold.
- No hard enforcement of vendor quotas (we cannot block a vendor request); this is visibility and pre-flight nudging. Guard already owns local-cost enforcement.
Proposed scope, decoupled parts
Part 1 — Quota model (src/quota.ts, foundation, no UI)
A provider-agnostic model of a plan's quota state: for each active window (5h, weekly, monthly, credit-based), the limit, the amount used, the reset time, and a pace (used / elapsed-fraction-of-window). Fed by two sources that already exist: derived-from-local-tokens (works offline, all providers) and live-quota-endpoint (Claude/Codex, authoritative when present). Live wins when available; local is the always-on fallback. Pure and testable, mirroring plan-usage.ts. Depends on nothing.
Part 2 — Burn-rate forecast (extends Part 1 + budget.ts math)
Given the window model and recent burn rate, project the exhaustion time: "at this pace you hit your weekly limit Thursday ~3pm" and "projected to end the window at 140%." Reuse the run-rate approach in budget.ts but anchor to the plan window boundaries from Part 1, not the calendar month. Honest about confidence with sparse data (same discipline as the outlier/young-project work). Depends on Part 1.
Part 3 — Surfaces (menubar + statusline + CLI + web)
- Menubar Plan tab: a live burn-down bar per window and the forecast line, next to the Codex reset-credits row menubar: surface Codex limit-reset credits (count and next expiry) in the Plan tab #724 already added.
- A first-class quota statusline (research flagged this as a parity gap with ccusage's ecosystem) showing remaining + forecast, distinct from
guard --statuslinewhich is cost caps. codeburn plan/ acodeburn quotaview surfacing the same model in the TUI and--json.
Depends on Parts 1 and 2. UI-only; each surface can land separately.
Part 4 — Pre-flight cost awareness (optional, opt-in)
Before an expensive turn, an ambient signal of what it will cost against the remaining window ("~40 credits, 3% of your month"). Delivered through the existing MCP server or a hook, never a blocking gate. Depends on Part 1; can follow the surfaces.
Part 5 — Invoice reconciliation (trust, separable)
An opt-in mode that reconciles CodeBurn's parsed spend against official billed spend where an API exists (Anthropic cost API, OpenRouter key endpoint, Claude Code OTEL) and flags drift. Directly answers "are these numbers even right." Strictly opt-in and network-gated, off by default, honoring the local-first promise. Independent of the rest; grouped here because it is the trust half of quota confidence.
Dependency order
Part 1 first. Parts 2 and 5 in parallel after (5 is fully independent and can start anytime). Part 3 after Part 2. Part 4 last. Each part is its own PR; UI surfaces in Part 3 are independently shippable.
Evidence gate (per the epic-#602 discipline)
Before Part 2's forecast ships to users, it must be validated against real historical windows: replay a month of local sessions, compute the forecast at each day, and check it against what actually happened at the window boundary. A forecast that is confidently wrong is worse than none, so the same reproduce-and-measure bar the acting layer used applies here.
Already shipped toward this
- menubar: honor Retry-After on Claude quota 429s, back off failed refreshes #702 Claude 429/Retry-After handling and refresh backoff (the lifecycle every fetch must ride).
- menubar: Codex Plan tab doesn't surface limit-reset credits (count and expiries) #723 / menubar: surface Codex limit-reset credits (count and next expiry) in the Plan tab #724 Codex limit-reset credits in the Plan tab (the first Part 3 brick, and proof of the best-effort companion-fetch pattern).
Contributions welcome on any decoupled part. Comment to claim one; design discussion on the model shape (Part 1) is the most useful place to start.
Activity
avs-io commentedon Jul 17, 2026
Claiming Part 1 (quota model). Also for the record: #726 phase 1 (the Part 2 menubar slice you green-lit) is in progress now, so Part 1 here is next in queue after that lands.
Proposed model shape for
src/quota.ts, before any code — happy to adjust:Semantics I'd commit to:
(provider, kind); derived fills the gaps. The merged result keepssourceper window rather than per plan — a Claude weekly from the live endpoint and a monthly derived from local tokens coexist, and every surface can (and should) render derived windows as estimates. Same discipline ascostIsEstimated: a guess must never render as a measurement.plan-usage.tsis tested.One open question worth deciding before code: on the CLI side, where do live snapshots enter? The live fetchers currently live in the menubar (Swift), so Part 1 as a pure TS model works offline-first from day one, but "live wins" only activates for surfaces that have a live snapshot to hand it. Options: (a) model accepts an optional live snapshot param and the menubar is the first supplier via its existing payload path, or (b) the CLI grows its own read of the same endpoints later as a separate decision. I'd start with (a) — no new network surface, consistent with the epic's non-goals.
quota: provider-agnostic window model with provenance, merge rule, an…
feat(quota): show Codex limit resets in the Plan tab, hover card and CLI
feat(mac): tell the user when a quota reset came early
docs: record early quota reset detection
feat(menubar): translate the early-reset notification, band and history
feat(menubar): translate the Codex banked-reset copy and the cache-re…
feat(codex): refresh the reset history from GitHub, at most hourly
hasanAbbas2004 commentedon Nov 3, 2026
Measured data for Parts 3/4: what one Claude Code turn costs against the 5-hour window
I logged the 5-hour % from
/api/oauth/usageat the start and end of every Claude Code turn (via hooks) and matched it against the local transcripts, on a Pro plan. Two findings that may help with the pre-flight signal (Part 4) and a quota statusline (Part 3):1. Output tokens drive the 5-hour %, context length barely does. In controlled tests, the same amount of output in a fresh context and in a long one moved the % by the same amount, even with 3.6× (Opus) and 71× (Sonnet) more cache reads. Predicting the second half of a window from the first: output tokens only had 0.8 points of error, API price weighting 1.4, all tokens flat 9.0.
2. On Pro, 1% of the 5-hour window ≈ 6,000 output tokens on Opus 5.5 and ≈ 9,500 on Sonnet 5.5 (ranges 4,700–9,400 and 7,700–11,200; a least-squares fit over all readings gives 5,500 and 9,600).
So a turn's cost can be estimated as
output_tokens / ratio(model). CodeBurn's parser already readsoutput_tokensandmodeland dedupes streaming partials, so this needs no new network calls, which fits the epic's non-goals.Caveats: one account, one plan (Pro), two days, whole-number readings. Max plans will differ, so the ratio needs calibrating per plan (it can be fitted from % readings plus the transcripts: least squares over intervals of 15+ minutes, since the % lags usage by 1–2 min). Other pitfalls I hit:
resets_atjitters across minute boundaries (round, don't truncate), and resumed sessions repeat earlier message ids.I've built this as a status line in a small local tool:
5h 41% · resets 1h 12m · task ~1.3%. Claude Code already passesrate_limits.five_hour.used_percentage/resets_aton the status line's stdin, so the live % needs no API call at all, and the task cost is just the transcript's output tokens since the last user prompt divided by the per-model ratio.I'd like to claim Part 3 with that. Proposal: extend
codeburn guard statusline(Claude Code allows only one status line, and guard already installs it) tocodeburn guard $1.24 · 5h 41% · resets 1h 12m · turn ≈1.3%. It would reusecomputeSessionUsage's incremental fold to track output per model since the last user prompt, mark the estimate asderivedper Part 1, and make no new network calls. Roughly 250 lines with tests.Questions before I start:
src/quota.ts?), and should they be per plan? I've only measured Pro.transcript_path, but subagent transcripts (<session>/subagents/) use the quota too. Should this PR count them, or should that be a separate change?