Repository navigation
Description
What happened
While a Claude agent is working, the context meter in thread details sometimes jumps to about double the real usage, often past the window (for example 1.1M / 1M or 1.4M / 1M). It drops back to normal a turn or two later. I've seen this across several threads and several nightly builds.
Diagnosis
It happens when a response includes a call to the advisor server tool. The API then samples the main model more than once inside one message. The top-level usage on message_delta is the sum across those samples, and the per-sample breakdown is in usage.iterations.
ClaudeAdapterV2 builds context usage from the top-level fields: claudeMessageInputTokens feeds claudeProviderTurnTokenUsage, which mergeClaudeStreamUsage updates on each message_delta. With two main-model passes, the cached input is counted twice. The real context is the last type: "message" entry in iterations, and that's what the meter should use when iterations is present.
The iterations handling in provider/Drivers/claudeUsage.ts covers billing and usage accounting (#24129), not the context meter. This path is unchanged on main as of 2026-11-24.
Steps to reproduce
- In a Claude thread with the advisor tool available, build up the real context past ~500K, for example by having the agent read large files.
- Have the agent call the advisor, then end its turn with plain text and no further tool calls.
- Open thread details. The context meter shows about 2× the real context and goes past the window (1.1m / 1m in the attached screenshot).
- Send another message. The next request's usage replaces the doubled value, and the meter drops back to the real ~545K.
The doubling shows at any context size. Below ~500K it just doesn't go past the window.
Version
Reproduced on T3 Code Desktop 0.1.12-nightly.20261123.5151. I've also seen it on earlier nightlies: the first logged instance is from 2026-11-13, and I don't know which build that was.
Environment
macOS 27.0 (arm64), T3 Code Desktop app against its local server, Claude agent (claude-opus-5-5 for the repro, claude-fable-5-2 for the Nov 13 instance), 1M context window.
Evidence
Repro on 0.1.12-nightly.20261123.5151. The message_delta usage for the advisor turn:
"usage": {
"input_tokens": 4, "cache_read_input_tokens": 1087272,
"cache_creation_input_tokens": 1222, "output_tokens": 711,
"iterations": [
{"type":"message","input_tokens":2,"cache_read_input_tokens":543529,"cache_creation_input_tokens":214,"output_tokens":268},
{"type":"advisor_message","input_tokens":545497,"output_tokens":3144},
{"type":"message","input_tokens":2,"cache_read_input_tokens":543743,"cache_creation_input_tokens":1008,"output_tokens":443}
]
}Stored turn usage in the same thread:
| Turn | usedTokens / maxTokens |
Note |
|---|---|---|
| 3 | 224,888 / 1,000,000 | advisor call; real context ~112K |
| 4 | 1,089,209 / 1,000,000 | advisor call; real context ~545K |
| 5 | 546,552 / 1,000,000 | next normal turn |
Earlier instance (2026-11-13, claude-fable-5-2):
| Turn | usedTokens / maxTokens |
|---|---|
| 19 | 678,931 / 1,000,000 |
| 20 | 1,430,668 / 1,000,000 |
| 21 | 719,874 / 1,000,000 |
In turn 20, cache_read_input_tokens was 1,427,069, the sum of the two main-model passes (712,663 + 714,406). An advisor_message pass of 716,963 input tokens sat between them.
Across my provider logs, every message_delta that carried an advisor_message iteration reported top-level input above the real context, up to 2.0×. 8 of the 291 went over 1M.
Screenshot of the thread-details meter at 1.1m / 1m during the repro:
Related issues
#24129: advisor tokens were missing from usage accounting. Same iterations shape, different code path.
Workaround
None needed. Only the meter is wrong: the model's real context is unaffected, and the reading corrects itself on the next normal request. I haven't checked whether anything else reads the inflated contextUsage, such as the compaction triggers. A turn after a 1.43M reading started normally without compacting.
Triaged and drafted by Claude Code (Opus 5.5, claude-opus-5-5) via the T3 Code triage playbook.
Activity
juliusmarminge commentedon Nov 24, 2026
I tried to reproduce this on the current build and could not.
Commit 13c5b0f (origin/main). I could not do a live app run: it needs a first-party Claude sign-in with the advisor server tool, and no VM has one. Instead I reproduced it in ClaudeAdapterV2's own harness (makeWakeHarness), feeding the reporter's frames through the real adapter stream handling. message_start carried the first pass's usage. message_delta carried the reporter's exact usage: input 4, cache_read 1,087,272, cache_creation 1,222, output 711, plus an iterations array of message / advisor_message / message. Then a result frame. The last provider_turn.updated tokenUsage reported inputTokens 1,088,498 and cachedInputTokens 1,087,272. The real context, from the last
messageiteration, is 544,753 and 543,743. Adding the 711 output tokens gives usedTokens 1,089,209, which exactly matches the stored turn 4 value in the report (1,089,209 / 1,000,000). The new test 'measures context from the last main-model iteration when an advisor call samples twice' in apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts fails on main for this reason.Closing as not planned. If it still happens for you, reply with the exact steps and the version you are on and it will be looked at again.
muhammadmamdouh42 commentedon Nov 24, 2026
Thanks for looking into this. I think it was closed by mistake: the harness run above reproduces the bug rather than ruling it out. It produced
usedTokens1,089,209, while the real context from the lastmessageiteration was 544,753 (+711 output). That is exactly the doubling reported here, and it matches the stored turn value. The comment also says the new test, "measures context from the last main-model iteration when an advisor call samples twice", fails onmain. I couldn't find that test onmainor in an open PR.It still happens on the current nightly. I reproduced it live on
0.1.12-nightly.20261123.5165(the local server reportsserverVersion0.1.12-nightly.20261123.5165), with the same steps as in the issue:cache_read_input_tokenscache_creation_input_tokensmessagepass 1advisor_messagemessagepass 2usageStored turn usage: 1,149,383 / 1,000,000. The real context is ~574.7K (+890 output), and the next normal turn read 580,141.
Nothing reads
iterationsin the context-usage path (claudeMessageInputTokens/mergeClaudeStreamUsageinClaudeAdapterV2.ts) on 5165 or on currentmain.Screenshot of the meter during the repro on 5165:
Could you reopen this?
Drafted by Claude Code (Opus 5.5,
claude-opus-5-5) via the T3 Code triage playbook.