claude-code - 💡(How to fix) Fix [BUG] Status line cost counter resets on context compaction — undercounts session cost [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#46466Fetched 2026-04-11 06:19:33
View on GitHub
Comments
1
Participants
2
Timeline
6
Reactions
0
Timeline (top)
labeled ×5commented ×1

The $X.XX cost displayed in the Claude Code status line resets to zero when context is compacted mid-session. After compaction, the counter only tracks cost from the new context window, silently dropping all pre-compaction spend.

Error Message

  • Before compaction: Status line showed ~$5-6 (roughly correct for 77 turns up to 164k context)
  • After compaction: Status line showed ~$4.97 total (approximately post-compaction cost only)
  • Actual total from JSONL: $8.35 (calculated from full transcript with correct Opus 4.6 pricing)

Root Cause

The $X.XX cost displayed in the Claude Code status line resets to zero when context is compacted mid-session. After compaction, the counter only tracks cost from the new context window, silently dropping all pre-compaction spend.

RAW_BUFFERClick to expand / collapse

Description

The $X.XX cost displayed in the Claude Code status line resets to zero when context is compacted mid-session. After compaction, the counter only tracks cost from the new context window, silently dropping all pre-compaction spend.

Reproduction

  1. Start a session that generates heavy context (e.g., iterative code review with many tool calls)
  2. Let the session compact (hit context limits, or the conversation gets continued after running out of context)
  3. Observe the status line cost drops dramatically

Observed behavior

  • Before compaction: Status line showed ~$5-6 (roughly correct for 77 turns up to 164k context)
  • After compaction: Status line showed ~$4.97 total (approximately post-compaction cost only)
  • Actual total from JSONL: $8.35 (calculated from full transcript with correct Opus 4.6 pricing)

The status line was missing ~$3.50 of pre-compaction spend.

Expected behavior

The status line cost counter should be cumulative across the entire session, including all context windows before and after compaction events.

Verification

Calculated cost from the JSONL transcript (~/.claude/projects/{path}/{session_id}.jsonl) which contains all turns including pre-compaction ones. The JSONL-derived cost accounts for all 90 turns across the compaction boundary, while the status line only reflects the 13 post-compaction turns plus subagents.

Environment

  • Model: Claude Opus 4.6 (1M context)
  • Session had 90 main-thread turns, 23 subagent turns
  • Context compacted at turn 77 (164k → 34k tokens)
  • macOS, CLI

extent analysis

TL;DR

The cost displayed in the Claude Code status line can be made cumulative across the entire session by modifying the cost tracking logic to account for pre-compaction spend.

Guidance

  • Review the cost calculation logic to ensure it accumulates costs across compaction events, rather than resetting.
  • Verify that the JSONL transcript contains all turns, including pre-compaction ones, to use as a reference for correct total cost.
  • Consider modifying the status line update logic to read from the JSONL transcript or a similar cumulative cost tracker.
  • Check if the compaction event is properly handled in the cost tracking logic, ensuring that pre-compaction costs are not lost.

Example

No code snippet is provided due to lack of specific implementation details in the issue.

Notes

The provided information suggests a logic issue in the cost tracking mechanism, but the exact implementation details are not available. The solution may involve modifying the existing cost tracking logic or introducing a new cumulative cost tracker.

Recommendation

Apply a workaround by modifying the cost tracking logic to accumulate costs across compaction events, as the root cause appears to be a logic issue rather than a version-specific problem.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

The status line cost counter should be cumulative across the entire session, including all context windows before and after compaction events.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING