Status line shows stale token count after /compact operation
Problem Summary
After running the /compact command to compress conversation history, the status line continues to display the token count from the old transcript rather than updating to reflect the new, compacted transcript.
Expected Behavior
When /compact creates a new conversation transcript, the status line should immediately update to show the reduced token count from the compacted conversation.
Actual Behavior
- Before compact: Status line correctly showed token usage
- After compact: Status line shows old token count (146k/200k - 73%)
- Actual usage (per
/contextcommand): 97k/200k (49%) - Root cause: Status line using old transcript file path
Investigation Findings
Token Count Comparison
Three different token counts were observed:
- Status line: 146k tokens (73%) - Bug: reading from old transcript
/contextcommand: 97k tokens (49%) - correct, from Claude API- Token calculator on new transcript: 78k tokens (39%) - reading new file
Transcript Analysis
Two transcript files found for this project:
Old transcript (pre-compact):
- File:
26263a5e-0722-4cff-b071-eb9eb558181a.jsonl - Size: 1.6M, 561 messages
- Last update: 2025-10-01T16:33:56.376Z
- Token count: 146,967 tokens ← Matches status line bug\!
- Active chain: 449 messages
New transcript (post-compact):
- File:
eaba8dbb-c175-4465-9013-1620f156aa9f.jsonl - Size: 156 messages
- Last update: 2025-10-01T16:43:55.530Z (10 minutes later)
- Token count: 77,967 tokens
- Active chain: 123 messages
Verification
Tested custom status line script with both transcript paths:
# Using NEW transcript (correct)
echo '{"transcript_path":".../eaba8dbb-c175-4465-9013-1620f156aa9f.jsonl"}' | ./.claude/statusline.sh
# Output: 79k/200k (39%) ✓
# Using OLD transcript (bug reproduction)
echo '{"transcript_path":".../26263a5e-0722-4cff-b071-eb9eb558181a.jsonl"}' | ./.claude/statusline.sh
# Output: 146k/200k (73%) ← Matches user's buggy status line\!
Root Cause Analysis
After /compact operation:
- Claude Code creates new transcript file with compacted history
- Claude Code switches internal conversation to use new transcript
- Bug: Status line hook continues receiving old transcript path
- Status line calculates tokens from stale file
- User sees inflated token count that doesn't match reality
Status Line Implementation Details
The status line uses custom scripts:
.claude/statusline.sh- Readstranscript_pathfrom JSON input.claude/token-calculator.js- Parses transcript JSONL and calculates:
``javascript``
contextLength = input_tokens + cache_read + cache_creation
The algorithm:
- Parses all messages from transcript JSONL
- Filters to main chain (isSidechain: false)
- Finds most recent message with usage data
- Returns token count from that message
The bug: Status line receives stale transcript_path value after compact, so it reads the old file.
Steps to Reproduce
- Start a long conversation that builds up significant context (e.g., 140k+ tokens)
- Note the status line token count
- Run
/compactcommand to compress conversation history - Observe: status line still shows old token count
- Run
/contextcommand - Compare:
/contextshows much lower count than status line
Impact
- User confusion: Status line shows 146k when actual usage is 97k (49k difference\!)
- Premature compacting: Users may think they're running out of context when they have plenty left
- Trust issues: Discrepancy between status line and
/contextcommand undermines confidence
Affected Components
- [x] Status Line (receives stale transcript_path)
- [x] Compact Operation (doesn't update status line input)
- [ ] Token Calculator (works correctly when given right path)
System Information
- Working Directory: /home/ikme/repos/ifs-accounting
- Platform: Linux (WSL2) -
6.6.87.2-microsoft-standard-WSL2 - Status Line Type: Custom command (
./.claude/statusline.sh) - Old Transcript:
26263a5e-0722-4cff-b071-eb9eb558181a.jsonl(1.6M, 561 msgs) - New Transcript:
eaba8dbb-c175-4465-9013-1620f156aa9f.jsonl(156 msgs)
Proposed Fix
After /compact operation completes:
- Ensure status line hook receives updated
transcript_pathpointing to new file - Consider forcing status line refresh/recalculation
- Verify all hooks receive updated context information
Additional Context
- Issue discovered by user after noticing status line didn't update post-compact
- Custom status line implementation in project uses
token-calculator.js - The
/contextcommand correctly shows updated count from API - Token calculator algorithm works correctly when given proper transcript path
---
Investigation conducted using custom status line debugging
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗