feat(claude_usage): refresh action, local token history and API status#973
feat(claude_usage): refresh action, local token history and API status#973jondmarien wants to merge 1 commit into
Conversation
|
Pushed two more commits on top (the last two): a per-model token breakdown in the Tokens section, and a pinnable popup that matches the cpu/memory/gpu pin button. Both are off by default with no new deps or network calls; the breakdown reuses the transcript data the token-history scan already reads, and the pin reuses the shared |
|
Can you show me a screenshot of how this widget looks now? There have been so many changes. Also, please squash these commits into a single commit. |
|
this also affects the model bars, not just the hourly/weekly bars. will fix for all in this widget! edit: I think because I implemented my own edit2: i think its my css 🙈 let me investigate further |
|
@amnweb could you provide your css for the copilot widget regarding the |
c97294a to
87f6338
Compare
|
Squashed the branch into a single commit, as you asked. What's folded into it:
On the bar that didn't fit its container: see comment below |
nevermind, i had max-height set for some reason. |
87f6338 to
9403117
Compare
…nnable popup Builds on the existing claude_usage widget; everything is off by default and closes amnweb#967, amnweb#970 and amnweb#971. - refresh action plus a header button that force an immediate fetch and skip cache_ttl, with in-flight dedup; a {stale} indicator that shows once the OAuth token has expired; and per-window reset wording (relative or absolute, with an optional date) that fixes the broken "Resets in Sat 6:00 AM" line - local token-usage history: a Session/Today/Week/Month/Year section read from Claude Code's own transcripts under ~/.claude/projects, scanned off-thread and incrementally, with the cache bounded (hourly past 15 days and daily past ~13 months are pruned on scan). No API key, no network call, content never read - Claude API status dot driven by the public status.claude.com page (no auth), keeping the last known status on a failed poll - per-model token breakdown in the Tokens section, following the same period toggle. Model names are derived from the id so new models need no upkeep, and fast-mode usage (usage.speed) is split into its own row - pinnable, draggable popup matching the cpu/memory/gpu widgets, via a shared create_pin_button helper in stat_popup - the popup resizes to fit the selected period instead of cramming or stretching - docs and example CSS under docs/ Co-Authored-By: ManaphatDev <106569727+Gaer12TH@users.noreply.github.com>
9403117 to
0022451
Compare
|
Pushed the bar-alignment fix (still one commit). You were right that the bars came out different sizes (I also talked with @ManaphatDev about this); the cause was the name and total labels being content-width, so the stretchy bar column started and ended at a different x on each row. I moved the per-model rows into a Caught one more while testing: a pinned popup snapped back to its spawn point on a refresh tick. Verified locally across all five periods, on first open and after refresh, pinned and unpinned. |
|
This should probably be done in CSS. Set a minimum width for the left and right labels, and let the progress bar stretch to fill the remaining space, it was more simpler... May I ask what the reason was for creating a new |












Following your comment on #971, I reworked this and went back through the contributing guidelines. This closes #967, #970 and #971 and puts everything in one PR. They were stacked on top of each other and awkward to review one at a time, so I rebased onto
mainas separate commits, one per feature, so each reads on its own. Happy to change anything that doesn't fit the project's conventions.Since opening this I added two more commits on top while using the widget every day: a per-model token breakdown and a pinnable popup. They're the last two commits, same off-by-default style as the rest.
Everything here is off by default and builds on the existing
claude_usagewidget.1. Refresh, stale indicator, reset wording
A
refreshcallback plus a button in the popup header that force an immediate fetch and skipcache_ttl. Repeat fetches are still deduplicated while one is in flight, and a manual refresh rewrites the disk cache so the next scheduled tick reuses it instead of hitting the network again.The header now uses the
stat_popup.pylayout you suggested (aQFrameheader holding aQLabel.texttitle and aQPushButton), so the old ClickableLabel is gone. One thing to watch when theming:.claude-usage-menu .headeris the container row now, and the title text is.header .text.There's also a
{stale}placeholder that shows a warning glyph once the OAuth token has expired. It reads the credentials'expiresAtonly, never the token itself, and it's just a cue since the widget can't renew the token (running Claude Code does that). And two reset-format options,five_hour_reset_format/seven_day_reset_formatwithreset_show_date, which fix the broken "Resets in Sat 6:00 AM" line.2. Local token-usage history
An optional Tokens section in the popup: a Session/Today/Week/Month/Year toggle, the total for the selected period, and an optional graph that reuses the shared
GraphWidget. The same totals are on the bar through{session_tokens},{today_tokens}and the rest.It reads Claude Code's own session transcripts under
~/.claude/projects, so there's no API key and no network call. Only the numeric token counts, timestamps, model name and session id get read; message content never does. A transcript is re-parsed only when its size or mtime changes, and the scan runs off the UI thread in a shared service like the usage poller.3. Claude API status
An optional dot driven by the public status page at
status.claude.com(no auth).{status}colours the dot by level through.status.none/.minor/.major/.critical,{status_text}gives the description, and you can show a status line in the popup header. If a poll fails it keeps the last known value rather than blanking out.4. Per-model token breakdown
The Tokens section can now show where the tokens actually went. Turn on
token_history.show_modelsand a short bar list appears (Opus 4.8, Sonnet 4.6, Fable 5, whatever else is in your transcripts), sorted by usage, top five. It follows the same period toggle as the rest of the section, so switching to Week or Month re-ranks the models for that window.Same local data as the token history; nothing new gets read and there's still no network call. Model ids are shortened for display (
claude-opus-4-6becomesOpus 4.6), with a fallback so an unrecognised id shows as-is instead of vanishing. I also moved the period toggle and running total down next to the graph, since the big number looked stranded once the model list sat between it and the chart.5. Pinnable popup
A pin button in the popup header, the same one
cpu/memory/gpuuse. It reuses the sharedPinnablePopup, so pinning keeps the popup open and lets you drag it anywhere. Thepin_icon/unpin_iconfields default to the same Segoe Fluent Icons glyphs the other widgets use; the button sits to the right of refresh and themes with.claude-usage-menu .header .pin-btn.Notes
Docs are updated under
docs/. Ruff check and format are clean. I tested against my own install plus offscreen Qt: the refresh button and callback, the stale glyph, both reset formats, the token section across all five periods, the per-model breakdown and its re-ranking when I switch periods, the pin button, and the status dot at each level.This also folds in the docs-only changes from #969 by @ManaphatDev (the custom
<img>icon note and the README index entry), credited via Co-Authored-By. They touch the same docs this PR rewrites, and #969 was stuck on an unrelated CI failure, so it was cleaner to bring them in here.