feat: track cost and enforce budget after mid-session subscription→API billing transition
Problem
When a Claude Code session starts on a Claude Max subscription, /cost shows:
"You are currently using your subscription to power your Claude Code usage"
Claude Code does print a warning at the transition point when subscription quota is exhausted and billing switches to API (pay-per-token). However, two gaps remain after that warning:
Gap 1 — /cost doesn't track the API-billed portion
Once billing transitions mid-session, /cost continues to show subscription-mode output only. It does not accumulate a dollar figure for the API-billed tokens incurred after the transition. The only way to see those charges is to start a new session (pure-API sessions show full cost breakdowns).
Gap 2 — No budget ceiling for the API portion
There is no way to set a per-session spending cap that would stop (or warn again) when API charges within a single session exceed a threshold.
Reproduction
- Start a Claude Code session with a Claude Max subscription + API key configured
- Run a large agentic task that exhausts subscription quota mid-session
- Observe the transition warning printed by Claude Code ✅
- Run
/cost— it does not show accumulated dollar amount for the API-billed portion ❌ - Continue the session; there is no secondary warning or hard stop if API charges grow ❌
Requested behavior
/cost live tracking after transition
Once billing mode transitions within a session, /cost should show the dollar amount accrued from the API-billed portion — the same breakdown that appears in a pure-API session.
Optional: budget ceiling
Support --session-budget <$N> flag or CLAUDE_SESSION_BUDGET=<N> env var to abort the session (with a clear message) if API charges within the session exceed the threshold.
Related
- #38369 —
/costshows no token breakdown for subscription (related observability gap) - #45756 — cache tokens counting toward quota (related quota confusion)
Neither covers the specific issue of /cost not tracking the API-billed portion after the mid-session billing mode transition.
Environment
- Claude Code: latest (2.x)
- Platform: macOS (arm64)
- Auth: Claude Max subscription + API key configured
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗