Skip to content

Add toggleable per-message token usage badges in chat UI - #6

Merged
namerror merged 4 commits into
mainfrom
copilot/add-per-message-token-usage
Apr 7, 2026
Merged

Add toggleable per-message token usage badges in chat UI#6
namerror merged 4 commits into
mainfrom
copilot/add-per-message-token-usage

Conversation

Copilot AI commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

This updates the context estimator to show per-message token usage directly in the conversation view (enabled by default). Each badge displays estimated tokens and that message’s share of the selected model context window.

  • Overlay controls

    • Added a persisted Per-message usage toggle in the Overrides section.
    • Introduced showPerMessageUsage in settings defaults/storage handling.
    • Set per-message usage display to enabled by default.
  • Estimation pipeline

    • Extended estimate output to include per-message { tokens, contextPercent } when enabled.
    • Reused existing estimator selection/fallback behavior (Precise/Fast).
    • Added lightweight memoization for repeated message text within a calculation pass.
  • Message-level UI rendering

    • Rendered compact badges next to message nodes in the format x tokens, x%.
    • Implemented idempotent badge updates/removal to avoid DOM-observer churn loops.
    • Added scoped styles for badge placement/appearance and checkbox layout.
  • Docs

    • Updated README usage/features to mention per-message usage display.
    • Added a session devlog entry and index link.
// per-message usage shape produced by estimate engine
[
  { tokens: 26, contextPercent: 0.08125 },
  { tokens: 11, contextPercent: 0.034375 }
]

// rendered badge text
"26 tokens, 0.08%"

Per-message token usage UI

Copilot AI linked an issue Apr 7, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Add toggle for per-message token usage display Add toggleable per-message token usage badges in chat UI Apr 7, 2026
Copilot AI requested a review from namerror April 7, 2026 04:57

@namerror namerror left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The displayed token label should be "x tokens, x%".

Also, enable display of per message token by default

Copilot AI commented Apr 7, 2026

Copy link
Copy Markdown
Contributor Author

The displayed token label should be "x tokens, x%".

Also, enable display of per message token by default

Updated in commit 68c3232: badge text now renders as x tokens, x%, and per-message usage is enabled by default. Screenshot: https://github.com/user-attachments/assets/dca859cc-c39d-4bad-8cce-a58d90db1676

Copilot AI requested a review from namerror April 7, 2026 21:20
@namerror
namerror marked this pull request as ready for review April 7, 2026 22:28
@namerror
namerror merged commit da3f82a into main Apr 7, 2026
1 check passed
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.

Display per-message token usage

2 participants