Skip to content

Epic: quota intelligence (live remaining, burn-rate forecast, pre-flight awareness, invoice reconciliation) #725

Description

@iamtoruk

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:

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)

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 --statusline which is cost caps.
  • codeburn plan / a codeburn quota view 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

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions