Stats cache drops days on reinstall when session JSONLs are purged but history.jsonl retains activity
Bug
Reinstalling/updating the Claude Code desktop Mac app caused the active-day streak to reset. stats-cache.json was rebuilt but days whose session JSONLs in ~/.claude/projects/ were purged during the install/update dropped out of dailyActivity entirely — even though ~/.claude/history.jsonl still had the prompt timestamps for those days. The cache rebuild only scans projects/**/*.jsonl and does not fall back to history.jsonl.
Related (not duplicates — same mechanism, different surface)
- #41591 (OPEN) — "Auto-update deletes session .jsonl files, wiping token usage history and conversation data". Same underlying mechanism (update deletes session files) but focuses on permanent token/conversation data loss. This report focuses specifically on the streak-counter break that results from the same class of deletion.
- #35367 (OPEN) — "VS Code extension auto-update deletes CLI session history files". The VS Code variant of the deletion behavior.
- #48213 (OPEN) — "Stats dashboard streak broken despite valid session data on disk". Same symptom (streak break), different trigger: session files present but ignored due to uniform mtime.
- #22123 (CLOSED NOT_PLANNED) — firstSessionDate reset after v2.1.25 → v2.1.27. Older, unrelated trigger; already dismissed by maintainers.
Evidence (this case)
- Reinstalled/updated the Claude Code desktop Mac app on 2026-04-18 (bundled CLI at
~/.local/bin/claudebumped to v2.1.114) find ~/.claude/projects -name "*.jsonl" -newermt "2026-04-17" ! -newermt "2026-04-18"→ 0 files (session JSONLs for 04-17 wiped)- Prompts on 04-17 in
history.jsonl: 17 (bucketed by local date, timestamps 1776376800000–1776463199999) - Prompts on 04-18 in
history.jsonl: 18 (before the streak broke) stats-cache.json.dailyActivityended at 2026-04-16stats-cache.json.lastComputedDate: "2026-04-17"(orphan — no matching entry)- Streak counter broke because the most recent
dailyActivityentry (04-16) is 2 days before today
Repro
- Use Claude Code (via the desktop Mac app) on day N — session files written to
~/.claude/projects/<project>/<sessionId>.jsonl - Reinstall or allow the desktop app to auto-update on day N+1, before day-N session files are rotated/persisted in a way that survives the update
- The install/update path purges
.jsonlfiles from~/.claude/projects/(see #41591 for the mechanism) - Cache rebuild scans
projects/**/*.jsonl, which no longer contains day-N sessions - Day N is dropped from
dailyActivity; streak resets
Prior occurrence for me
Same class of streak-break also triggered 2 months ago (2026-02-11) when switching from the npm-installed CLI to the native binary. That time session JSONLs only went back to a few days before the switch — everything older was lost from the rebuilt cache despite history.jsonl going back months. Consistent pattern across install-path changes.
Suggested fix
When rebuilding dailyActivity, merge from BOTH:
~/.claude/projects/**/*.jsonl(source of truth for token counts, tool calls, model breakdown — permanently lost if the files are gone, per #41591)~/.claude/history.jsonl(source of truth for presence-of-activity per day — survives installs/updates)
The merge should union days: if a date has a history.jsonl entry but no session file, still record it in dailyActivity with messageCount from history and toolCallCount: 0. Token and session counts would be unavailable for those days (that's #41591's scope), but the streak stays intact.
Addressing #41591 would also fix this — if .jsonl files stopped being deleted in the first place, the streak wouldn't break. The history.jsonl fallback is a defense-in-depth for cases where files have already been lost.
Workaround
Hand-edit ~/.claude/stats-cache.json to inject missing dailyActivity entries (counts derived from history.jsonl timestamps bucketed by local date) and update lastComputedDate. JSON validates; the stats dashboard reads the cache on next run.
Environment
- Claude Code 2.1.114 (bundled CLI in the desktop Mac app)
- macOS (Darwin 25.3.0)
- Install path: Claude Code desktop Mac app.
/Applications/Claude.appmtime 2026-04-16; bundled CLI symlink at~/.local/bin/claude→~/.local/share/claude/versions/2.1.114updated 2026-04-18 20:37 local. Exact sub-mechanism (fresh DMG drag vs in-app auto-update) uncertain — the reliable signal is that a desktop-app-level install/update event rebuilt the stats cache and dropped days whose session JSONLs were purged during the rebuild.
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗