Repository navigation
feat(widgets): edit the labels of this fork's widgets with e - #45
Closed
eric-engberg wants to merge 71 commits into
Closed
eric-engberg wants to merge 71 commits into
eric-engberg wants to merge 71 commits into
Conversation
Session Cost shows what a session has cost so far, but not how fast it's spending. Session Cost Rate divides the session cost by time, the agent's hourly rate: `Rate: $5.00/hr`. By default it divides by the time Claude spent working (the API duration Claude Code reports), which reads as the rate for the hours it actually worked. A `t` keybind switches to clock time, the whole session including time spent waiting for the user, which reads as the burn rate. It shows nothing until a full minute of the chosen time has passed, since a rate over the first seconds swings wildly.
The Extra Usage widgets show the amount spent, what's left and the
percentage used, but never the monthly limit itself, so a line could
read "Spend Used: $123.45" with no way to show "of $500". Remaining
and Utilization only imply it.
Extra Usage Limit shows the monthly limit from the usage API, in the
reported currency and the cost number format, labeled like the other
Extra Usage widgets ("Overage Limit", or "Spend Limit" on accounts
without plan limits). When extra usage is on without a monthly limit
it shows "none", and when it's off "n/a", with the same hide options as
its siblings. It needs only the extra usage state and the limit, which
come from the fetch the other Extra Usage widgets already make.
Claude Code reports each session's cost and time as running totals. Keep each session's totals per Claude Code profile in the daily state file, with where they stood when the UTC day began (zero for a session that started today, otherwise the last totals seen yesterday, or the first seen today), and work out today's totals across the profile's sessions: cost, active time (parallel sessions add up) and clock time (the time any session was running, counted once). Unchanged totals aren't rewritten more than once a minute.
When a line shows Daily Cost Rate, each render records its session's totals under the Claude Code profile (CLAUDE_CONFIG_DIR, or default) and passes today's totals to widgets as dailyCost. With the widget's billed spend option on, the usage prefetch also fetches the extra usage state and works out today's billed spend; without it, the widget triggers no usage fetch at all.
Session Cost Rate shows one session's cost per hour; Daily Cost Rate
shows it across all of today's Claude Code sessions ("Rate Today:
$6.20/hr"). It divides Claude Code's own session costs by default; the
b keybind switches to today's billed spend (as Extra Usage Today shows
it, including claude.ai and other machines). The t keybind switches from
active time (Claude working, parallel sessions adding up) to clock time
(the time any session was running). It shows nothing until a full minute
of the chosen time has passed.
…nto label-editor-rebuild # Conflicts: # docs/USAGE.md # src/utils/usage-prefetch.ts # src/utils/widget-manifest.ts # src/widgets/index.ts
…el-editor-rebuild # Conflicts: # docs/USAGE.md
…-editor-rebuild # Conflicts: # docs/USAGE.md # src/utils/usage-prefetch.ts # src/utils/widget-manifest.ts # src/widgets/index.ts
Extra Usage Today, Daily Budget, Extra Usage Limit, Session Cost Rate and Daily Cost Rate declare their default labels, so (e)dit label offers them as upstream's label editor (sirmalloc#601) does for its own widgets. The editor's default for Extra Usage Today and Limit is the "Overage" label, since it has no usage data; accounts without plan limits show "Spend". Each builds that label in one place for the editor and render. So "today: $12.34 of $50.00/day" is Extra Usage Today labeled "today: ", Daily Budget labeled "of " and a "/day" Custom Text, with no raw values.
eric-engberg
force-pushed
the
feat/label-editor
branch
from
October 6, 2026 17:25
b50b489 to
492e0ee
Compare
…to feat/extra-usage-limit-widget #32 no longer detects accounts without plan limits, so Extra Usage Limit keeps a fixed "Overage Limit: " label, as the other Extra Usage widgets do; the label editor can change it.
…to feat/extra-usage-limit-widget
…t/daily-cost-rate
…to feat/extra-usage-limit-widget
#32 no longer picks "Overage" or "Spend" by account, so Extra Usage Today and Limit offer and draw their fixed "Overage" labels; the label editor changes them.
# Conflicts: # docs/USAGE.md # src/utils/__tests__/usage-prefetch.test.ts
…t/daily-cost-rate
… its new totals Daily Cost Rate worked out each session's share of today from Claude Code's running totals, assuming they count up without a break from the session's start. They don't always: - On --resume, /resume and --fork-session, Claude Code restores the session's earlier cost and API time and backdates its start by the time it ran before. A session that ran yesterday for 2 hours and cost $8 read as started 2 hours ago, so it counted from zero and today showed yesterday's $8, 40 minutes of API time and 2 hours of clock time. A fork added its source's totals a second time. - /login sets the totals and the duration back to zero under the same session id. The day's starting point dropped with them, so the session's $6 and 2 hours so far today were lost. A session's totals now carry on from its record only while neither total goes down and its start doesn't move later. Otherwise this is a new run: it counts from the totals it was first seen with (zero for a new session) and its clock time from when it was first seen, kept in the record's new firstSeenAt. A run recorded earlier the same day is kept under its own key, so what it counted still counts and its clock time stays where it was. A same-day resume therefore no longer counts the time between the two runs either. A session first seen with spend already on it, such as one open before the widget was added, now counts from then rather than from zero, the same as an overnight session first seen today already did.
…head A session record keeps the time it was last seen. When the system clock ran ahead past the next UTC midnight for a render and was then put right, that render's record stayed dated the day after. Pruning keeps everything from yesterday on, so the record was kept, and when that day came Daily Cost Rate counted the session as one of its own: its cost and active time, plus clock time up to a last-seen time that hadn't happened yet (2.5 hours of clock time at 07:00 for a session that never ran that day). A record last seen more than a minute after now was stamped while the clock ran ahead; the minute allows for small clock corrections, as in Extra Usage Today. Each record now also keeps when it was first seen on its day, which is when that day's starting point was taken. If that was today, at a time that has come, only the last-seen time is off, and the record counts as last seen now: a clock that runs ahead and is put right within the day leaves the day's totals as they were. Otherwise the record's day can't be trusted either, and it's dropped; the session counts afresh from its current totals. What it had counted on the day the clock ran ahead past midnight isn't recovered, as with Extra Usage Today.
With billed spend on, Daily Cost Rate divides today's extra usage spend, which the usage API reports in the account's own currency. The rate was always formatted as US dollars, so a euro account read "Rate Today: $50.00/hr" next to Extra Usage Today's "Overage Today: €50.00" for the same spend. Billed spend is now formatted in the reported currency, as the Extra Usage widgets do; Claude Code's own costs stay in US dollars.
Brings in upstream main through #41, which now holds #33 as upstream sirmalloc#756. Main adds Extra Usage Limit at the same places the #33 branch merged here did, so the widget manifest, the usage prefetch's widget list and requirements, and its prefetch test keep main's single entry. Daily Cost Rate's billed-spend test stubs getUsageFetchedAtMs, which #36 now reads in place of its own getUsageFetchedAt. # Conflicts: # docs/USAGE.md # src/ccstatusline.ts # src/types/RenderContext.ts
# Conflicts: # src/utils/usage-prefetch.ts
# Conflicts: # docs/USAGE.md
# Conflicts: # docs/USAGE.md
# Conflicts: # docs/USAGE.md
|
Owner
Author
|
Superseded: every widget this labeled declares its own label on main or in #37. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Based on #41, and merges #33, #35 and #37, which add the widgets it labels. Review the last commit. Upstream's label editor (sirmalloc#601) is now in
main, and the stack picks it up with theekey from #48, so this PR only adds this fork's widgets to it.What
e((e)dit label…) now works on this fork's own labeled widgets, as it does on upstream's: Extra Usage Today, Extra Usage Daily Budget, Extra Usage Limit, Session Cost Rate and Daily Cost Rate. Select one in the line editor, presse, and change the label shown before its value. Tab restores the default, and an empty label removes it.Why
A line like
today: $12.34 of $50.00/dayneeded Extra Usage Today and Daily Budget in raw value mode, each with a Custom Text in front for its own words. Upstream's label editor offers itself only on widgets that declare their default label, and these widgets aren't upstream yet. With this PR the same line is Today labeledtoday:, Daily Budget labeledof, and one/dayCustom Text.How
getLabelPrefix(), which is how upstream's widgets opt in. Rendering already goes throughformatRawOrLabeledValue(or value colors'formatColoredValue, which draws edited labels since feat(usage): color Extra Usage Used, Today and Utilization by break points or a gradient #41), so an edited label shows up with no other change.ekey is now feat(tui): edit a widget's label with e #48, proposed upstream, and the stack merges it (itsbkeys would clash with upstream'sla(b)el…otherwise);Demo
Relabeling Extra Usage Today to
today:and Daily Budget toof, merged without padding and followed by a/dayCustom Text. The preview readstoday: $46.10 of $194.70/day, from the TUI's sample values.Powerline
Plain
Testing
fork-widget-labels.test.ts(11): the five widgets' defaults, edited and empty labels, and Today with value colors on.bun testgives 3372 pass, 0 fail (Bun 1.4.2).bun run lintis clean.getLabelPrefix()for each againstmain).