Skip to content

Surface context window usage in the UI#1351

Merged
juliusmarminge merged 5 commits intomainfrom
t3code/context-window-meter
Mar 24, 2026
Merged

Surface context window usage in the UI#1351
juliusmarminge merged 5 commits intomainfrom
t3code/context-window-meter

Conversation

@juliusmarminge
Copy link
Member

@juliusmarminge juliusmarminge commented Mar 24, 2026

Summary

  • Adds provider normalization for token usage snapshots from Codex and Claude runtime events.
  • Projects token usage and compaction state into orchestration thread activities.
  • Renders a compact context window meter in the chat composer area.
  • Displays context compaction markers as centered timeline chips.
  • Adds coverage for adapter normalization, orchestration ingestion, and UI rendering behavior.

Testing

  • Not run in this pass.
  • Added/updated tests for ClaudeAdapter, CodexAdapter, ProviderRuntimeIngestion, contextWindow, MessagesTimeline, and session logic.
  • Repository task requirements still call for bun fmt, bun lint, bun typecheck, and bun run test before merge.

Note

Surface context window usage in the chat UI with a token meter

  • Adds a ContextWindowMeter component to the chat composer bar that shows a circular SVG progress arc with used/remaining tokens and a popover with full details.
  • Normalizes token usage events from both Claude and Codex adapters into a typed ThreadTokenUsageSnapshot contract, emitting thread.token-usage.updated provider runtime events at task progress and turn completion.
  • Maps thread.token-usage.updated and thread.state.changed (state compacted) runtime events to new context-window.updated and context-compaction thread activities in ProviderRuntimeIngestion.
  • Adds deriveLatestContextWindowSnapshot in contextWindow.ts to scan activities backwards for the latest usage snapshot, and formatContextWindowTokens for compact k/m display.
  • context-window.updated activities are excluded from the work log; context-compaction entries remain visible with their label.
  • Behavioral Change: ThreadTokenUsageUpdatedPayload now validates usage against a strict ThreadTokenUsageSnapshot schema — events that don't conform will fail decoding.

Macroscope summarized 4747000.


Note

Medium Risk
Introduces a new validated ThreadTokenUsageSnapshot schema and changes thread.token-usage.updated payload decoding/normalization; any producers sending unstructured usage data may now fail validation or be dropped. Also adds new activity kinds that affect timeline/work-log rendering, so regressions are possible if consumers assume the previous activity set.

Overview
Projects provider runtime signals into new thread activities: thread.token-usage.updated becomes context-window.updated (with a structured ThreadTokenUsageSnapshot payload) and thread.state.changed with state: "compacted" becomes context-compaction.

Updates Claude and Codex adapters to emit/unwrap normalized token-usage snapshots (handling multiple payload shapes and deriving Claude context-window size from modelUsage), and updates the contracts schema so thread.token-usage.updated is no longer Schema.Unknown.

Adds a compact context window meter (ContextWindowMeter) to ChatView driven by the latest context-window.updated activity, plus UI/session-logic tweaks so context-window updates are excluded from the work log while compaction entries remain visible, with new test coverage across adapters, ingestion, and UI helpers.

Written by Cursor Bugbot for commit 4747000. This will update automatically on new commits. Configure here.

- Normalize provider token-usage events into thread activities
- Add a compact context window meter to chat
- Handle context compaction markers in the timeline
@coderabbitai
Copy link

coderabbitai bot commented Mar 24, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: aa332626-0a28-428d-80f3-246a1cab0097

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch t3code/context-window-meter

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added size:XL 500-999 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. labels Mar 24, 2026
- Let the tooltip width fit its content instead of wrapping
- Keep the usage line on one row for readability
- Replace timeline marker treatment with normal grouped work rows
- Switch context window meter to an SVG ring and show auto-compaction
@github-actions github-actions bot added size:L 100-499 changed lines (additions + deletions). and removed size:XL 500-999 changed lines (additions + deletions). labels Mar 24, 2026
- Increase ring stroke thickness for better visibility
- Shrink the center badge to keep the meter balanced
- Replace the tooltip wrapper with a hover popover
- Preserve the context window details popup behavior
@juliusmarminge juliusmarminge merged commit 8f35155 into main Mar 24, 2026
11 checks passed
@juliusmarminge juliusmarminge deleted the t3code/context-window-meter branch March 24, 2026 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant