Skip to content

Agent Mode reports incorrect context windows for Claude and Codex sessions #506

Description

@BetaFold3

Summary

Agent Mode can report a context-window denominator that does not match the provider’s effective runtime limit.

This makes the context percentage misleading at exactly the point where users rely on it to decide whether to add more context, compact, or start a new session.

Examples observed in the CE debug app:

  • A Claude model with a 1M model maximum and a configured 400K auto-compact window initially reports 1M.
  • After the first response, the same Claude session can incorrectly switch to 200K.
  • Fresh Codex GPT-5.5 and GPT-5.6 sessions can briefly show the internal 200K fallback before runtime usage reports the model’s actual context window. GPT-5.5 was observed at approximately 258.4K after the first response. In case of GPT 5.6, it was 353.4K.

Reproduction

Claude

  1. Configure CLAUDE_CODE_AUTO_COMPACT_WINDOW=400000.
  2. Start a new Agent Mode session with a 1M-capable Claude model.
  3. Inspect the context tooltip before sending a message, while waiting for the first response, and after the response arrives.

Expected: the effective window remains 400K, while the 1M model maximum is available as separate detail.

Actual: the UI can show 1M initially and later switch to 200K.

Codex

  1. Start a new Agent Mode session with GPT-5.5 or GPT-5.6.
  2. Send the first message and inspect the context indicator before the response arrives.
  3. Inspect it again after runtime usage is received.

Expected: an unknown denominator is shown honestly until Codex reports its runtime window.

Actual: the internal 200K fallback can appear as though it were the real window, then change when the runtime-reported value arrives. For GPT-5.5, this was observed at approximately 258.4K.

Additional bug found during investigation

Claude result events can contain modelUsage entries for both the main model and background models such as Haiku. The translator previously selected the first positive entry from an unordered dictionary, allowing a background model’s 200K window to be attributed to a 1M main-model session.

The investigation also found that the 200K display fallback was being used as a validation ceiling while the real window was unknown. This could silently discard legitimate context readings above 200K in fresh 1M sessions and after restoring persisted usage.

Acceptance criteria

  • Configured provider limits are used as the effective denominator when known.
  • Canonical model capacity remains available separately from the effective limit.
  • Multi-model Claude usage events are attributed to the active main model.
  • Valid usage readings above 200K are retained while the canonical window is still unknown.
  • Unknown windows are shown without presenting an internal fallback as fact.
  • Model switches, process restarts, and session/workspace changes do not retain stale window values.
  • Focused regression coverage exists for Claude, Codex, persistence, and sidebar presentation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions