Skip to content

fix(server): Claude models tagged [1m] learn the window Claude Code reports - #46029

Open
zhangyan-unipat wants to merge 2 commits into
pingdotgg:mainfrom
zhangyan-unipat:fix/claude-1m-reported-context-window
Open

zhangyan-unipat wants to merge 2 commits into
pingdotgg:mainfrom
zhangyan-unipat:fix/claude-1m-reported-context-window

Conversation

@zhangyan-unipat

Copy link
Copy Markdown

Problem

A custom Claude model tagged [1m], such as anthropic/claude-opus-5-5[1m] routed through a gateway, never gets a context window in T3 Code. Its turns record maxTokens: null, and a handoff back into its existing session falls back to the 128K default. With a few hundred thousand tokens already in that session, the handoff budget comes out as 0, so T3 Code starts a new session with a summary instead of continuing the existing one.

Claude Code does report the window. It drops the [1m] suffix from a Claude model id before sending it, so result.modelUsage uses anthropic/claude-opus-5-5 as the key, with contextWindow: 1000000. The adapter looks the window up by the suffixed id and finds nothing. Ids that Claude Code does not treat as Claude models keep the suffix. For example, anthropic/anthropic-glm-5.3[1m] and anthropic/anthropic-kimi-k3.1-pro[1m] are reported unchanged, so those models already work.

Change

claudeContextWindow looks up the reported window by the exact API model id first. If that finds nothing and the id ends in [1m] (case-insensitive), it tries the id without the suffix. The catalog is still checked first, and nothing else changes.

Because the window is recorded on each provider turn, a later handoff picks it up from stored usage, even after a restart.

Scope

This is a small fix for an obvious bug: the reported window exists, but the lookup uses the wrong key. It does not add a setting or a feature. #30051 added the reported-window path, which matches result.modelUsage keys against the selected model id. This PR handles the one case where Claude Code itself changes the id.

Verification

  • Found on T3 Code desktop with Claude Code 2.1.326 and a local gateway. In the provider event log, every [1m] Claude model reported usage under the unsuffixed key (Opus: 36 results, Sonnet: 16). In statev2.sqlite, all 37 of their turns had tokenUsage.maxTokens = null, and the context handoffs back into those sessions used full_thread_summary.
  • I ran claude -p --model <id>[1m] --output-format json against the same gateway. Claude ids came back without the suffix (anthropic/claude-sonnet-5-5, 1000000). The GLM and Kimi ids came back unchanged (1048576).
  • I made the existing test "measures a model outside the catalog against the window Claude reports" into a parameterized test with three cases: plain id, non-Claude [1m] id reported unchanged, and Claude [1m] id reported without the suffix. With the adapter change reverted, the third case fails with expected [ null, null ] to deeply equal [ null, 1048576 ]. With the change, all three pass.
  • vp run check:changed passes (format, lint, graphql, typecheck, knip, tests in 2 files).

What I could not check: I did not run a live desktop build from this branch. The runtime behavior is covered by the adapter test and by matching the real CLI output above. I could not probe the Gemini model ids because the gateway's upstream was down.

Implementation, tests and PR text: Claude Opus 5.5 (claude-opus-5-5) in Claude Code through T3 Code.

🤖 Generated with Claude Code

…eports

Claude Code drops the `[1m]` suffix from a Claude model id before sending
it, so `anthropic/claude-opus-5-5[1m]` reports its usage and context window
under `anthropic/claude-opus-5-5`. The adapter looked the window up by the
suffixed id, missed it, and recorded no window for these custom models.
Handoffs into their sessions then fell back to 128K.

Look up the reported window by the exact id first, then without `[1m]`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:unvouched Author is not yet trusted in the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Nov 30, 2026
@macroscopeapp

macroscopeapp Bot commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at 3b8dc18

Macroscope's review found this PR approvable — Models tagged [1m] can now use the context window Claude Code reports under the unsuffixed model ID. Catalog values and exact matches retain precedence, keeping the change narrowly scoped.

You can add or adjust custom eligibility rules. Learn more.

@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The adapter now uses a shared lookup for reported context windows. The lookup checks the exact API model ID first, then retries without a trailing [1m] suffix. Tests cover three uncatalogued model IDs and verify that the runtime lookup updates to 1,048,576 tokens.

Changes: Claude context-window resolution

Layer / File(s) Summary
Reported context-window lookup
apps/server/src/provider/ClaudeTurnTokenUsage.ts, apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts, apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
The new lookup checks for an exact model ID, then removes a trailing [1m] suffix if needed. claudeContextWindow uses this lookup when the catalog has no value. Tests cover three uncatalogued model IDs and verify reported usage updates the runtime lookup.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related issues

  • pingdotgg/t3code#31441 — The PR changes the reported-window lookup used by claudeContextWindow, but retains catalog-first precedence, so the issue’s reported-window precedence objective remains unaddressed.

Suggested reviewers: juliusmarminge, yash-singh1

Merge Risk: Minimal · up to 2e2f6

This change fixes the context-window lookup for Claude [1m] models whose usage is reported without the suffix. Handoffs into existing sessions should then use the correct window instead of the 128K default. No outstanding risk was found, and the change is narrow and easy to revert.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: Claude models tagged [1m] now get the context window that Claude Code reports, under the unsuffixed model ID. The title follows the conventional commit format with a s…
Description check Passed The description follows the template sections (Problem, Change, Scope, Verification) and fills each one with specific detail. The Problem section gives the reproduction context and expected behavior. …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: Claude models tagged [1m] now get the context window that Claude Code reports, under the unsuffixed model ID. The title follows the conventional commit format with a scope and a specific description, and the changeset adds a suffix-stripping fallback lookup for exactly this case.

Full details: Description check

Explanation

The description follows the template sections (Problem, Change, Scope, Verification) and fills each one with specific detail. The Problem section gives the reproduction context and expected behavior. The Change section explains the lookup order and the reason it is safe. The Scope section links the prior feature (#30051) and explains why this is a bug fix. The Verification section lists concrete test results, commands run, and what could not be checked. The description does not link a tracking issue, but it explains why none is needed for a small fix. The description also includes the model and harness line that the template asks for.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 3b8dc18 and 2e2f6c7.

Files selected for processing: 1

  • apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@juliusmarminge juliusmarminge added the takeover:in-progress A takeover lead is working on this PR label Nov 30, 2026
@juliusmarminge

Copy link
Copy Markdown
Member

Evidence

Real web app on Linux Chromium, light theme, 1280×800 CSS pixels (DPR 2), fresh isolated databases, Claude Code 2.1.332 through a custom API endpoint.

  1. Add custom Claude model claude-haiku-5-5[1m] in Settings → Providers → Claude → Models.
  2. Start a thread using it and send “Reply with just the word ok. Do not use any tools.” Both replies complete with “ok”.
  3. Enable Context window in thread details and hover it. Repeat the prompt through the composer during recording.
  4. Control: a separate catalog-model claude-haiku-5-5 thread stores a 1,000,000-token capacity on both commits.
Before After
a58d86f863 2e2f6c78b4
Before: 31k used with no capacity or percentage After: 31k of 1m and 3 percent used
Before recording After recording

Claude reports modelUsage["claude-haiku-5-5"].contextWindow: 1000000 on both sides. The selected custom model includes [1m]. Base stores maxTokens: null; head stores maxTokens: 1000000 after both completed custom-model turns.

Reproduction seed commands and browser steps · Usage evidence extracted from real runs · Extraction script

The scenario runner cannot cover this Claude-specific protocol behavior. Stills were checked for stability and all captures inspected before upload. Large-session provider-switch handoff behavior was not exercised.

Not shown:

  • Large-session handoff budgeting and preservation after switching provider instances were not exercised; the proof demonstrates reported capacity storage and the context meter, not the downstream handoff consequence.
  • The anthropic/-prefixed spelling was not exercised; the reproduction used the unprefixed custom ID from triage against the available gateway.

@juliusmarminge juliusmarminge added takeover:ready Takeover done; auto-lands when gates pass and removed takeover:in-progress A takeover lead is working on this PR labels Nov 30, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10-29 changed lines (additions + deletions). takeover:ready Takeover done; auto-lands when gates pass vouch:unvouched Author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants