t3code icon indicating copy to clipboard operation
t3code copied to clipboard

Context window meter keeps pre-/clear token count in Claude threads

Open mixram opened this issue 4 weeks ago • 2 comments

What happened

I worked in a Claude thread (Fable 5.1) yesterday. Today I sent /clear in the same thread, then /context. Claude's /context output shows 26.1k / 1m (3%), but the composer's context window ring still shows 17% · 166k/1m from yesterday's last turn.

Diagnosis

  • On /clear, the Claude Agent SDK emits {"type":"conversation_reset","trigger":"clear","new_conversation_id":…}, followed by a result with num_turns: 0 and all usage fields at 0.
  • ClaudeAdapterV2.ts has no handling for conversation_reset (no match in the file). Local-command handling exists only for /compact (isCompactionCommandMessage, local_command === "compact", compact_boundary writes afterTokenCount as the new tokenUsage).
  • emitContextUsage returns early when inputTokens <= 0 (ClaudeAdapterV2.ts ~5155), so the /clear and /context provider turns get no tokenUsage.
  • In the web client, latestProviderTurnTokenUsage (apps/web/src/lib/contextWindow.ts) skips turns without tokenUsage and picks the newest remaining report, so the last pre-clear turn (166k) stays the "live" usage. Nothing invalidates older turns' usage at a clear boundary.
  • The meter only corrects itself after the next turn that makes an API call.

Suggested direction: treat conversation_reset (trigger clear) like a compaction boundary for usage: emit a reset tokenUsage (or a context-boundary item) so older turns' usage no longer counts.

Steps to reproduce

  1. In the desktop app, use a Claude thread until the meter shows a large value (here 166k / 1m).
  2. Send /clear.
  3. Send /context. Claude reports a small context (26.1k / 1m).
  4. Look at the composer's context window ring: it still shows the pre-clear value (17% · 166k/1m).

Version

0.1.7-nightly.20261102.4080 (desktop app, local server)

Environment

macOS arm64 (Darwin 27.0.0), Node v24.22.1, Claude Code 2.1.317, model claude-fable-5-1

Evidence

# orchestration_v2_projection_provider_turns for the thread (ordinal | started_at | tokenUsage.usedTokens / maxTokens)
6 | 2026-11-02T17:02:13Z | 166421 / 1000000
7 | 2026-11-03T05:05:44Z | (none)   # /clear
8 | 2026-11-03T05:06:36Z | (none)   # /context
# orchestration_v2_projection_provider_threads.contextUsage after /clear
{"usedTokens":166421,"maxTokens":1000000}

# provider events.<thread>.log, /clear turn
05:05:46.558Z incoming {"type":"conversation_reset","trigger":"clear","new_conversation_id":"01796e69-…", …}
05:05:46.681Z incoming {"is_error":false,"duration_api_ms":0,"num_turns":0,"usage":{"input_tokens":0,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":0,…}, …}

Related issues

#20078 reported this same stale meter ("Compact chip stays at 236k") but was closed as a duplicate of #7402, which was a Codex /clear fix, so the Claude meter part is not tracked. #24152 (open) and PR #24168 cover the Claude session-resume half of /clear. #24168 does not change how turn tokenUsage is picked, so it does not fix the meter.

Fix applied or workaround

None applied. Workarounds: send another message (the next real turn reports correct usage), or start a new thread instead of /clear (also avoids #24152).

Filed by

Claude Code (Claude Opus 5.5, claude-opus-5-5) via t3 triage

mixram avatar Nov 03 '26 05:11 mixram

Image

mixram avatar Nov 03 '26 05:11 mixram

Follow-up: in the same thread, after a later interrupt, T3 resumed the pre-/clear Claude session. The model then received the full old transcript. That is #24152 (details added there). This issue stays scoped to the meter.

mixram avatar Nov 03 '26 05:11 mixram