Skip to content

feat(claude): show what fills the context window in the composer meter - #10419

Open
t3dotgg wants to merge 2 commits into
mainfrom
t3code/add-context-usage-breakdown
Open

feat(claude): show what fills the context window in the composer meter#10419
t3dotgg wants to merge 2 commits into
mainfrom
t3code/add-context-usage-breakdown

Conversation

@t3dotgg

@t3dotgg t3dotgg commented Sep 6, 2026

Copy link
Copy Markdown
Member

The context meter tells you how full the window is, but not what filled it. When a Claude thread sits at 44% before you type anything, you cannot tell if that is MCP tool schemas, memory files, or the conversation itself.

Hovering the meter in a Claude thread now shows the same per-category breakdown Claude Code's own /context command renders: system prompt, system tools, MCP tools, messages, skills, memory files, and custom agents, each with a token count and share of the window. Rows below the list expand to the individual MCP tools, memory files, skills, and agents so you can see which one is the offender.

Context breakdown popover in a Claude thread

Breakdown collapsed MCP tools expanded Memory files expanded

How it works

The Claude Agent SDK exposes query.getContextUsage(), which returns categories, per-tool, per-file, per-skill, and per-agent token counts. A new provider.getContextUsage RPC routes through ProviderService to an optional getContextUsage on the adapter. The Claude adapter maps the SDK response to a small ProviderContextUsage contract. The web meter fetches it when the popover opens and refetches after the next token-usage event.

The call is on demand only. It is never issued automatically after a turn, because the SDK's token-count fallback can make extra model requests (#8610).

Why Claude only

Codex app-server reports only aggregate token counts on thread/tokenUsage/updated (input, cached input, output, reasoning, total) and has no method that returns a per-category or per-tool split. Estimating one client-side from transcript items would disagree with what Codex actually sends. The adapter method is optional so Codex, and any other provider, can add a breakdown later without touching the contract or UI.

The SDK's messageBreakdown field is skipped on purpose. It sums every API call in the session, so it reads larger than the resident "Messages" slice next to it.

Notes

  • The meter itself is still behind the "Context window indicator (legacy)" setting. The breakdown appears only when that meter is on.
  • Opening the popover on a thread with no running session resumes the session first, same as compaction does.
  • Mobile keeps the plain meter for now. The RPC is available to it through the shared client runtime.

Built with Claude Fable 5.1 in Claude Code.

@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:XL 500-999 changed lines (additions + deletions). labels Sep 6, 2026
@macroscopeapp

macroscopeapp Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Not approved

Macroscope's review found this PR not approvable — This PR adds a cross-stack Claude context-breakdown feature with a new authenticated RPC, provider SDK call, session recovery path, and interactive composer UI. It also changes an authorization file, so the change warrants human review despite its additive contracts and focused tests.

Not approved because:

  • Monthly spending limit reached (workspace setting). Approvability relies on correctness review in order to determine eligibility

No code changes detected at 17f0c30. Prior analysis still applies.

Review your spending limits in Billing settings. You can add or adjust custom eligibility rules. Learn more.

@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

Provider Metric Main baseline This PR Impact PR ceiling
Codex Total thread wire 13.6 KiB 13.6 KiB −39 B (−0.3%) 15.1 KiB
Codex Thread snapshot wire 7.0 KiB 7.0 KiB +7 B (+0.1%) 7.3 KiB
Codex Live turn WebSocket wire 6.6 KiB 6.5 KiB −46 B (−0.7%) 7.8 KiB
Codex Live turn WebSocket decoded 57.1 KiB 57.0 KiB −88 B (−0.2%) 66.4 KiB
Codex Live turn messages 10 8 −2 (−20.0%) 21
Claude Total thread wire 13.6 KiB 13.6 KiB +8 B (+0.1%) 15.1 KiB
Claude Thread snapshot wire 7.1 KiB 7.0 KiB −3 B (−0.0%) 7.3 KiB
Claude Live turn WebSocket wire 6.5 KiB 6.5 KiB +11 B (+0.2%) 7.8 KiB
Claude Live turn WebSocket decoded 57.8 KiB 57.8 KiB 0 B (0.0%) 66.4 KiB
Claude Live turn messages 8 8 0 (0.0%) 21

Baseline: ec36176 · PR result: 17f0c30 · Source CI: success

Scenario and decoded snapshot size

10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

  • Codex decoded thread snapshot: 113.9 KiB
  • Claude decoded thread snapshot: 114.6 KiB

Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

t3dotgg and others added 2 commits September 6, 2026 17:16
Hovering the context meter in a Claude thread now shows what fills the
window: system prompt, system tools, MCP tools, messages, skills, memory
files, and custom agents, each with token counts and share of the window.
Rows below the list expand to individual MCP tools, memory files, skills,
and agents.

The data comes from the Claude Agent SDK's getContextUsage, read on
demand when the popover opens. Codex app-server reports only aggregate
token counts, so the breakdown stays Claude only; the adapter method is
optional for that reason.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Knip flagged the unused export.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@t3dotgg
t3dotgg force-pushed the t3code/add-context-usage-breakdown branch from de53833 to 17f0c30 Compare September 7, 2026 00:16
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