Skip to content

Copilot Chat: claude-sonnet-4.6 / claude-opus-4.6 max_prompt_tokens under-reported by CAPI — compaction fires 40K tokens early #298900

Description

Summary

The GitHub Copilot API (/models endpoint, hereafter "CAPI") appears to report a max_prompt_tokens value for claude-sonnet-4.6 that is below the model's actual 200K context window as documented by Anthropic.

Impact

baseBudget in agentIntent.ts is set to Math.min(userSetting ?? endpoint.modelMaxPromptTokens, endpoint.modelMaxPromptTokens), where modelMaxPromptTokens flows directly from CAPI's capabilities.limits.max_prompt_tokens. If CAPI under-reports this value, the budgetThreshold = floor((baseBudget - toolTokens) * 0.85) fires early, triggering conversation compaction sooner than necessary — effectively wasting 40K tokens of usable context per request on every claude-sonnet-4.6 session.

Evidence

Per Anthropic's official model documentation, as of March 2026:

Model Context window Max output
claude-sonnet-4.6 200,000 tokens 64,000 tokens
claude-opus-4.6 200,000 tokens 128,000 tokens

The compaction threshold observable at runtime is significantly lower than 170,000 tokens (200K × 0.85), suggesting CAPI is returning approximately 160,000 for max_prompt_tokens.

Code path

CAPI /models → capabilities.limits.max_prompt_tokens
  → modelMetadataFetcher.ts _getMaxPromptTokensOverride()
    → chatEndpoint.ts this._maxTokens (line ~151)
      → registered as maxInputTokens with VS Code LM API
        → extChatEndpoint._maxTokens = languageModel.maxInputTokens
          → agentIntent.ts baseBudget
            → budgetThreshold = floor((baseBudget - toolTokens) * 0.85)

A user-side workaround exists (github.copilot.chat.advanced.summarizeAgentConversationHistoryThreshold) but the Math.min clamp in agentIntent.ts means it can only lower the threshold, not raise it above what CAPI reports. There is no client-side fix.

Expected behavior

CAPI returns max_prompt_tokens: 200000 (or ≥ 190000 accounting for the output token reservation logic) for claude-sonnet-4.6, and the compaction threshold fires at ~170K tokens.

Actual behavior

Compaction fires well below 170K tokens on claude-sonnet-4.6 sessions, consistent with a CAPI-reported max_prompt_tokens of ~160K instead of 200K.

Environment

  • VS Code Insiders 1.110.0-insider
  • github.copilot-chat 0.38.2026022001
  • Model: claude-sonnet-4.6

Suggested fix

Update the CAPI model entry for claude-sonnet-4.6 (and claude-opus-4.6) to report max_prompt_tokens: 200000. No client code change required.

Metadata

Metadata

Labels

bugIssue identified by VS Code Team member as probable bugcapi

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions