Skip to content

[Bug]: Context Window Calculation wrong for claude code #2034

Closed

Description

@parzival1l

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/desktop

Steps to reproduce

Hi,
I've been running into this issue for a couple of days. The context window calculation was stuck on 5% after multiple turns for a day and then suddenly shot up to 100% even though the usage was only 15% (confirmed with claude code cli) -see attached images.

Image Image

Expected behavior

Other threads with codex seems okay no issues.

Actual behavior

Active and Working context window calculator.

Impact

Blocks work completely

Version or commit

No response

Environment

MACOS Tahoe 26.4

Logs or stack traces

Screenshots, recordings, or supporting files

No response

Workaround

No response

Activity

  1. added
    bugSomething is broken or behaving incorrectly.
    needs-triageIssue needs maintainer review and initial categorization.
    on Apr 15, 2026
  2. shresthkapoor7 commented on Apr 16, 2026

    @shresthkapoor7
    Image

    facing the exact same issue, how did you open the chat in claude code terminal?

  3. Sergiogd112 commented on Apr 16, 2026

    @Sergiogd112

    claude -r should show the sessions.

     -r, --resume [value]                              Resume a conversation by session ID, or open
                                                       interactive picker with optional search term
    
  4. fireMarshall88 commented on Apr 16, 2026

    @fireMarshall88

    same for me

    Image
  5. madebyjulz commented on Apr 16, 2026

    @madebyjulz

    same here
    Image

  6. mvanhorn commented on Apr 19, 2026

    @mvanhorn
    Contributor

    Traced this to apps/web/src/lib/contextWindow.ts deriveLatestContextWindowSnapshot. It walks activities newest->oldest and returns the first context-window.updated payload where usedTokens > 0, then computes percent as Math.min(100, (usedTokens / maxTokens) * 100).

    The 5% stuck -> 100% spike pattern while claude code cli reports 15% points at the Claude Code adapter emitting different context-window.updated payloads than Codex: either a stale usedTokens between turns, or a post-compaction snapshot that sends a cumulative usedTokens without a matching maxTokens bump.

    To pin it, it would help to see a console dump of the last 3-4 context-window.updated activities around the spike:

    useOrchestrationStore.getState().activities.filter(a => a.kind === 'context-window.updated').slice(-5)

    That shows which field is off (usedTokens spiking, maxTokens missing, or a mismatch between inputTokens + outputTokens and usedTokens). Without that, any fix here is guessing at which of those three paths the Claude Code adapter is hitting.

    cc @shresthkapoor7 @fireMarshall88 @madebyjulz (all reported the same symptom).

  7. juliusmarminge commented on Apr 19, 2026

    @juliusmarminge
    Member

    we rely on Claude emitting task_progress events to get the compacted context window. Sometimes it doens't emit these, causing us to fallback to the accumulative token spend (not greate). Not sure if there's a better way?

  8. amitbet commented on May 6, 2026

    @amitbet

    this bugged me as well - so I created a PR:
    #2551

  9. muslimdevhamid commented on May 12, 2026

    @muslimdevhamid

    Facing the same issue.

    Image
  10. mvanhorn commented on May 15, 2026

    @mvanhorn
    Contributor

    Sorry for the slow reply, @juliusmarminge - missed the ping.

    @amitbet's PR #2551 looks like the right answer. Normalizing at ClaudeAdapter.ts (the BE emitter) is cleaner than what I was thinking (downstream handling in contextWindow.ts) - it treats the accumulated total as processed-token telemetry only when there's no context-accurate used-token field, which is exactly the fallback you described. Same fix, applied at the source.

    Might be worth a quick look from a maintainer; coderabbit and macroscope already flagged it as approvable.

  11. juliusmarminge commented on Jun 20, 2026

    @juliusmarminge
    Member

    Claude usage accounting now separates active context usage from cumulative processed tokens and preserves the last context-accurate reading when only cumulative totals arrive. This removes the 5%-to-100% fallback behavior reported here.

    This was closed as part of a large repo-wide maintenance sweep. If you think it's still relevant, please reopen.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is broken or behaving incorrectly.needs-triageIssue needs maintainer review and initial categorization.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions