statusLine rate_limits.five_hour.used_percentage drifts across concurrently open terminals
Title
statusLine rate_limits.five_hour.used_percentage drifts across concurrently open terminals
Body
Summary
When multiple Claude Code terminal sessions are open at the same time against the same account, the rate_limits.five_hour.used_percentage field passed to a custom statusLine command shows different values in each terminal (e.g. one terminal reports 54%, another reports 58%, at the same wall-clock moment).
Why this happens (as far as I can tell)
The value appears to reflect the rate-limit state attached to that specific session's last actual API response, not a live re-check. Since each terminal's most recent turn happened at a different point in time, and the underlying 5-hour quota is account-wide (shared across all concurrent sessions), each terminal is showing a stale snapshot from a different moment — not the current true usage.
Running /usage inside a given terminal does trigger a fresh, authoritative check for that session, but there's no equivalent lightweight way to get that fresh number without sending a real prompt/command in that specific session.
Impact
For anyone running several Claude Code sessions in parallel (multiple terminals/worktrees), the statusLine's session-usage percentage can't be trusted as "current" — it's only as fresh as that terminal's last turn, which makes it easy to accidentally run past the actual 5-hour limit in a terminal that hasn't rendered a fresh number in a while.
Request
Either of these would resolve it:
- Have Claude Code refresh
rate_limitson a short interval (independent of whether the session made an API call), similar to how/usageperforms a fresh check — so statusLine reflects current usage rather than last-turn usage. - Expose a lightweight, non-billable "check current rate limit" call (CLI subcommand or documented endpoint) that a statusLine script could poll on its own cadence without needing full Admin/Console API access — subscription (Pro/Max, OAuth) users currently have no path to this data outside of the CLI's own internal session state.
Environment
- Claude Code version: 2.1.202
- Auth: subscription (OAuth), not API-console billing
- statusLine JSON sample (relevant fields):
"rate_limits": {
"five_hour": { "used_percentage": 63, "resets_at": 1783458600 },
"seven_day": { "used_percentage": 15, "resets_at": 1783936800 }
}
The cadence is the crux, and it resolves the tension with #77477 (concurrent sessions tripping the
per-account 429): refresh the shared usage cache on a bounded interval — say once every 1–3 minutes
while any session is active — coalesced across all local windows, so N open terminals cause one refresh,
not N. Every statusLine then reads the same fresh snapshot, fixing both the drift here and the 429 risk.
A fetched_at timestamp in the payload would also let a statusLine show honestly when the number is
stale instead of guessing.
Three newer reports have added evidence that changes what this request costs to
implement.
#91857 shows the data is already on the wire: rate_limit_event carries per-bucket
unifiedWindows utilization at status=allowed, just undeclared and reachable only
by spending a model turn. So refreshing independently of API calls is not a new
mechanism to build - it is exposure of a value the client already receives.
#92081 reports a related failure in the same payload: individual rate_limits
windows are omitted rather than emitted as null, so a status line cannot tell
"unknown" from "0% used". Any fix here should settle that too, otherwise a fresher
number is still unreadable.
#93107 asks for the per-model weekly limit in the same object.
The concrete ask from this issue is unchanged and now cheaper: one shared usage cache
per machine, refreshed on a bounded interval (once every 1-3 minutes while any session
is active) and coalesced across windows so N terminals cause one refresh rather than N,
plus a fetched_at timestamp so a status line can show honestly when the value is
stale instead of guessing. Related: #77477, #68772, #76036, #33978.
Adding data from one account running several concurrent sessions (Windows, CC 2.1.322–2.1.327).
I log every statusLine rate_limits change to a TSV. Over 8 days (1,796 rows) I saw 420 decreases of five_hour.used_percentage and 59 of seven_day.used_percentage inside the same resets_at window. Every one came from a different session_id than the row before it, typically 1–2 points lower. So it matches what the issue describes: each session reports the snapshot from its own last API response.
Practical impact: any tool that diffs consecutive readings gets nonsense (one day summed to −49% of the weekly limit).
A workaround that works for logging: keep a running max per window, and ignore readings with an older resets_at:
# state: max5 max7 reset5 reset7
if (( r5 < s5 || r7 < s7 )); then exit 0 # reading from an older window
elif (( r5 > s5 || r7 > s7 )); then m5=$p5; m7=$p7 # new window: take values as-is
elif (( p5 > m5 || p7 > m7 )); then ... # same window: only increases
else exit 0; fi
Replaying 423 real rows: 186 written, 0 false decreases, and a genuine mid-window weekly reset (93 → 0) is still captured, because it came with a new 5h window. An as_of timestamp on each rate_limits entry would let consumers handle this properly without the heuristic.