Skip to content

feat(tui): add /usage command for token and cost usage#34280

Open
anxkhn wants to merge 1 commit into
anomalyco:devfrom
anxkhn:feat/usage-command
Open

feat(tui): add /usage command for token and cost usage#34280
anxkhn wants to merge 1 commit into
anomalyco:devfrom
anxkhn:feat/usage-command

Conversation

@anxkhn

@anxkhn anxkhn commented Jun 28, 2026

Copy link
Copy Markdown

Issue for this PR

Related to #9281

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Adds a /usage command (alias /cost) to the TUI. It pulls the session list from the SDK client, sums cost and tokens into Today / This Week / This Month / All Time buckets plus a per-model breakdown, and shows them in a dialog. The numbers are the same ones opencode stats already computes, just surfaced in the TUI. It is one new dialog component plus one command registration in app.tsx, all inside the TUI package.

I first wrote this as a plugin, then read the codebase and it looked small enough to do natively. Please treat it as a proposal: happy to change scope or approach, or fold it into the discussion in #9281.

Known limitation: the client session.list is scoped to the current project, whereas opencode stats reads every session from the DB. I can wire it to a server side aggregation if you would prefer all projects.

How did you verify your code works?

  • Ran it in the TUI; /usage opens the dialog and renders correctly (screenshot below).
  • bun install, then bun run typecheck in packages/tui: passes, no errors.
  • oxlint on the new file: clean. app.tsx shows only pre-existing warnings (confirmed unchanged via git stash).
  • prettier applied to both changed files; pre-push checks passed.

Screenshots / recordings

/usage dialog in the TUI

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Jun 28, 2026
@anxkhn

anxkhn commented Jun 28, 2026

Copy link
Copy Markdown
Author
Screenshot 2026-06-28 at 11 27 47 AM attaching screenshot.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Jun 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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