Files
magpie/internal/claudetui/testdata/usage-refreshing-2.1.316.bin
T
yetone dd61299231 claudetui: /usage's saved figures, drawn while Claude Code refreshes them, are not told as today's
jsc9495 (Discord #help, 0.1.2950+, Claude Max): on one account at one
moment magpie's card said 5h 92% / 7d 99% left, another app 53% / 94%.

Claude Code 2.1.316's /usage panel draws the figures it saved on its last
read (cachedUsageUtilization in .claude.json, used up to an hour old,
keyed by accountUuid) at once, with "Refreshing…" under them, while it
asks Anthropic for today's. When that fails it keeps them and says
"Showing last-known usage as of 20m ago (rate limited until …)" or
"… (could not refresh)". The helper took any figures that stood still
for a second as the answer, so with a refresh slower than 1s, or a
rate-limited or failed one, each read told the figures of the read
before it (up to an hour old) stamped with the time now.

Now "Refreshing…" is waited past (up to commandWait). A panel that is
still refreshing at that point, or that shows last-known usage, is told as
"/usage couldn't load the plan's usage: …". claudeUsageUnknown already
matches that, so the card keeps its own last reading and that reading's
time. Figures Claude Code seeds from this session's own reply headers
("Partial usage data", "Per-model breakdown unavailable", "Could not
refresh usage data") are current and are still reported.

Fixtures are real bytes. Claude Code 2.1.316 ran on mote in a sandbox
CLAUDE_CONFIG_DIR with a made-up sign-in and saved figures 20 minutes
old (8% / 1%), and /usage was typed through a pty. It drew "Refreshing…"
and then "Showing last-known usage as of 20m ago (rate limited until
12:11am)". No real account was used, and no Keychain or live config was
touched.

Run (mote-run, at this tree on f280b12e5):
- go test ./internal/claudetui/ -count=1: ok.
- go test ./internal/provider/ -run Claude: ok.
- go test ./internal/gateway/ -run 'ClaudeUsage|ClaudeTUI': ok.
- GOOS=linux and GOOS=windows go vet ./internal/claudetui/: ok.
- gofmt -l: clean.
- win-run on xiaomi-gpu, TestShimWaitsPastSavedUsage and
  TestShimWaitsForUsageFigures: ok.

Broken by hand: with HEAD's tui.go, TestShimWaitsPastSavedUsage is red in
both subtests. Each tells "Current session: 8% used", the saved figures,
as a success.

Not tried:
- A real account's refresh. The redraw after a successful refresh is the
  earlier usage-2.1.316.bin capture on a cleared screen, not a captured
  redraw.
- A panel still "Refreshing…" after 20s; it takes the same error path.
- Why the other app's 7d figure read lower on jsc9495's second account.
2026-11-04 23:19:21 +08:00

2.0 KiB

▎ blocks the rest.
▎ https://code.claude.com/docs/en/permission-modes
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ ◐ medium · /effort ▔
Settings Status Config Usage Stats
 
Sessi n
 
T tal cost: $0.0000
Total duration (API): 0s
Total duration (wall): 9s
Total code changes: 0 lines added, 0 lines removed
Usage: 0 input, 0 output, 0 cache read, 0 cache write
 
Current session
████ 8% used
Resets 2:10am (Asia/Shanghai)
 
Current week (all models)
▌ 1% used
Resets Nov 8 at 11:10pm (Asia/Shanghai)
 
What's contributing to your usage?
Approximate · sessions on this machine only
 
Scanning local sessions…
 
Refreshing…
 
Esc to cancel
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Refreshing…
 
Esc to cancel