Skip to content

Surface context window usage in the UI#1351

Open
juliusmarminge wants to merge 1 commit intomainfrom
t3code/context-window-meter
Open

Surface context window usage in the UI#1351
juliusmarminge wants to merge 1 commit 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 and compaction events in the chat UI

  • Adds a ContextWindowMeter circular ring meter to the chat composer that shows current token usage as a percentage, derived from a new deriveLatestContextWindowSnapshot utility that scans thread activities.
  • Both the Claude and Codex adapters now emit structured thread.token-usage.updated events with a normalized ThreadTokenUsageSnapshot (including used/max tokens, per-slice counts, and compaction flags) at task progress, task completion, and turn boundaries.
  • The orchestration layer maps thread.token-usage.updated events to context-window.updated thread activities, and thread.state.changed with state compacted to context-compaction activities.
  • The messages timeline renders context-compaction activities as standalone centered chips labeled "Context compacted" and excludes context-window.updated activities from the work log feed.
  • Risk: ThreadTokenUsageUpdatedPayload now requires a structured ThreadTokenUsageSnapshot; events that previously passed through untyped usage payloads will fail schema decoding.

Macroscope summarized b2a7fa3.

- 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: fcab330a-c93b-4db7-a5e4-9a4cc5924be5

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

Labels

size:XL 500-999 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