Skip to content

feat: add a Session Cost Rate widget - #671

Open
eric-engberg wants to merge 2 commits into
sirmalloc:mainfrom
eric-engberg:feat/session-cost-rate
Open

eric-engberg wants to merge 2 commits into
sirmalloc:mainfrom
eric-engberg:feat/session-cost-rate

Conversation

@eric-engberg

Copy link
Copy Markdown
Contributor

What

A new Session Cost Rate widget shows the session's cost per hour: Rate: $5.00/hr. It sits next to Session Cost in the picker's Session category.

Why

Session Cost shows what a session has cost so far, but not how fast it's spending. A rate makes long and short sessions comparable, and on usage-based plans, where session cost is close to what's actually billed, it reads as the agent's hourly rate.

How

  • Time base: by default it divides by the time Claude spent working, the cost.total_api_duration_ms Claude Code sends with the status payload. That reads as a rate for the hours it actually worked. A t keybind in the line editor switches to clock time (cost.total_duration_ms, the whole session including time spent waiting for the user), which reads as the burn rate. The editor row shows (active time) or (clock time).
  • First minute: it shows nothing until a full minute of the chosen time has passed, since a rate over the first seconds swings wildly ($0.50 in 30 seconds is $60/hr).
  • Format: the cost number format applies, and the unit stays in raw value mode ($5.00/hr).
  • Data: only the status payload, so it works on every account type and needs no fetch.
  • Preview: a fixed sample, Rate: $4.90/hr (the Session Cost sample over 30 minutes).

Demo

A status payload with $2.50 over a 2-hour session in which Claude worked for 30 minutes: the third widget uses active time ($2.50 梅 0.5 h), the fourth clock time ($2.50 梅 2 h).

Powerline

Session Cost Rate with active and clock time, Powerline mode

Plain

Session Cost Rate with active and clock time, plain mode

Switching between active and clock time with t in the line editor:

Powerline

Toggling active and clock time in the line editor, Powerline mode

Plain

Toggling active and clock time in the line editor, plain mode

Testing

  • New widget tests: the rate over active time and clock time, raw value mode, nothing before a full minute (both time bases) and a rate at exactly one minute, missing cost or duration, the cost number format, the preview sample, and the t toggle (keybind labels, editor modifier, metadata).
  • On today's main (with docs: explain an empty status line in one folder (workspace trust)聽#606 and feat(git-is-fork): render forks as an editable glyph聽#617 merged in locally): bun test gives 2790 pass, 0 fail (Bun 1.4.2), and bun run lint passes.
  • Under Node (Vitest): the new tests pass, 8 of 8.
  • Built CLI under Bun 1.4.2 and Node 26.10.0 with a payload carrying cost and durations: all runtimes give identical output in plain and Powerline modes; it differs from main only by the new widgets. The TUI opens and exits cleanly under both.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant