[Bug] Session restoration causes incorrect token usage reporting after auto-compact

Status Fixed / completed
Reported on v2.1.113
Maintainer reply None cached
Activity 4 comments · opened Apr 18, 2026 · closed Apr 18, 2026

Bug Description
My 5 hours session was just reset and somehow the 5 hours tokens jumped to 7%!!! this keeps happening for me in the past session restorations. Even if it did session restore there is no way it filled my context to 7%... i haven't ran anything i just reopened this terminal and it asked me if i want to compact and i clicked yes and than immediately it jumped to 7%.. This is either a bug or something with the usage counting wrong. This is worth alot of money to me since we are paying per usage

Environment Info

  • Platform: win32
  • Terminal: null
  • Version: 2.1.113
  • Feedback ID: e11b3a8b-ce05-458a-a253-cd91f176f8b4

Errors

[{"error":"Error: Plugin MCP server error - mcp-config-invalid: MCP server github invalid: Missing environment variables: GITHUB_PERSONAL_ACCESS_TOKEN\n    at PjH (B:/~BUN/root/src/entrypoints/cli.js:2807:30077)\n    at processTicksAndRejections (native:7:39)","timestamp":"2026-04-18T13:01:03.589Z"},{"error":"Error: Plugin MCP server error - mcp-config-invalid: MCP server github invalid: Missing environment variables: GITHUB_PERSONAL_ACCESS_TOKEN\n    at PjH (B:/~BUN/root/src/entrypoints/cli.js:2807:30077)\n    at async V (B:/~BUN/root/src/entrypoints/cli.js:6187:11830)\n    at processTicksAndRejections (native:7:39)","timestamp":"2026-04-18T13:01:07.889Z"},{"error":"Error: Plugin MCP server error - mcp-config-invalid: MCP server github invalid: Missing environment variables: GITHUB_PERSONAL_ACCESS_TOKEN\n    at PjH (B:/~BUN/root/src/entrypoints/cli.js:2807:30077)\n    at async G (B:/~BUN/root/src/entrypoints/cli.js:6187:11023)\n    at processTicksAndRejections (native:7:39)","timestamp":"2026-04-18T13:01:07.890Z"}]

View original on GitHub ↗

4 Comments

0xbrainkid · 6 months ago

Session restoration causing token usage to jump to 7% immediately after auto-compact — for a freshly opened terminal that has not run any commands — is a token accounting bug during the session restore + compact sequence.

The 7% jump on a fresh session start suggests the compact operation itself is consuming tokens, and those tokens are being attributed to the new session rather than the old one, or the compact result is being pre-loaded as context that counts against the new session's budget.

The likely cause: When a session is restored after auto-compact, the compacted summary is injected as context for the new session. If that summary is large (which it can be after a long session), it consumes a significant portion of the session's context budget immediately. The 7% you see is the compacted summary consuming roughly 7% of the session's total context allocation at start time.

This is a known cost of compaction — the summary replaces the full history — but the billing/reporting should reflect this accurately:

  1. The compact summary tokens should be attributed to the compaction operation, not to "usage during this session." If the user has not done anything in the new session yet, the usage should show 0% for their actions and separately account for the base context load.
  1. The 5-hour limit reset should not immediately charge tokens for context that existed before the reset. The compact summary is a continuation of prior context — it represents work done before the reset, not new work in the new session window.

The related concern about financial impact is legitimate — if compact summaries consistently count against the session's usage metrics, users are being charged for prior work every time they start a new session after compaction.

github-actions[bot] · 6 months ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/42492
  2. https://github.com/anthropics/claude-code/issues/42009
  3. https://github.com/anthropics/claude-code/issues/38029

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

chenvaltzer · 6 months ago

same issue as the other issues

github-actions[bot] · 5 months ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.