Stats cache loses historical data after v2.1.27 update - firstSessionDate incorrectly reset
Bug Description
After updating to Claude Code v2.1.27, the /stats command shows incorrect data. The stats-cache.json file has firstSessionDate set to a recent date (Dec 24, 2025) instead of the actual first session date (Sept 29, 2025), causing ~84 days of historical activity to be missing from stats.
Environment
- Claude Code Version: 2.1.27
- OS: macOS (Darwin 25.2.0)
- Platform: darwin arm64
Steps to Reproduce
- Have been using Claude Code since Sept 2025 with extensive history
- Update to v2.1.27 (from v2.1.25)
- Run
/statscommand - Observe incorrect/missing historical data
Expected Behavior
- Stats should show all historical data from
history.jsonl firstSessionDateshould reflect the actual first session (Sept 29, 2025)- Active days count should include all days with activity (~122 days)
Actual Behavior
- Stats only show data from Dec 24, 2025 onwards
firstSessionDateinstats-cache.jsonis incorrectly set to2025-12-24- 84 days of activity before Dec 24 are missing from the cache
- Total sessions shows 344 instead of actual count
Investigation Findings
Raw data (history.jsonl) is intact:
First entry: 2025-09-29 11:04:04
Last entry: 2026-01-31 00:17:58
Total entries: 8,805
Unique active days: 123
Days before Dec 24: 84
Cache file (stats-cache.json) is incorrect:
{
"firstSessionDate": "2025-12-24T19:28:55.109Z", // WRONG - should be Sept 29
"totalSessions": 344, // Missing many sessions
"dailyActivity": [...] // Only 32 entries, missing 84+ days
}
Timeline:
| Time | Event |
|------|-------|
| Jan 29 13:11 | v2.1.25 installed |
| Jan 30 15:18 | v2.1.27 installed |
| Jan 30 21:28 | stats-cache.json regenerated (data loss occurs) |
Workaround Attempted
Deleting ~/.claude/stats-cache.json and running /stats again may regenerate the cache, but if the bug is in the computation logic, it will reproduce the same incorrect data.
Additional Context
The history.jsonl file contains complete data - this appears to be a bug in how the stats cache is computed/regenerated from the history file, specifically in determining firstSessionDate and aggregating dailyActivity.
---
🤖 Generated with Claude Code
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗