Repository navigation
Description
Summary
Claude Code auto-updates are silently deleting session .jsonl files from ~/.claude/projects/ directories, resulting in permanent loss of conversation history and token usage data. The /stats dashboard shows drastically reduced totals because it can only read surviving files.
Evidence
Environment: macOS, Claude Code 2.1.87, upgraded through multiple auto-updates since Jan 2, 2026.
Two batch deletion events observed
Event 1 — Mar 25, 10:43:20
All .jsonl session files deleted from older project dirs (-Users-andrew-Documents-Coram-repos-*). Every directory under these paths received the exact same mtime, indicating a single batch operation.
Event 2 — Mar 30, 10:51:58
Same pattern on newer project dirs (-Users-andrew-Documents-work-coram-code-*). This occurred exactly 10 minutes after Claude Code 2.1.87 auto-installed at 10:41:29.
What was lost
- 520 out of 520 sessions referenced in
sessions-index.jsonfiles have their.jsonlfiles missing - 282 session directories exist with only
subagents/data inside — the main conversation.jsonlis gone - Session dates span Jan 2 – ~Mar 1, 2026 — roughly 2 months of daily heavy usage
/statsshows 13.7m tokens (from ~1 month of surviving data); actual usage was likely 30m+
What survived
- Session directories with subagent
.jsonlfiles (11,207 files containing real token usage data) sessions-index.jsonfiles — still reference the deleted.jsonlpaths with metadata (session summaries, message counts, dates, branches) but no token countshistory.jsonl— prompt history going back to Jan 2- Session
.jsonlfiles dated Mar 2+ — these were apparently written by a newer storage format or path and were not targeted by the cleanup
Proof the files existed
The sessions-index.json entries contain fileMtime values corresponding to dates when the .jsonl files were last written (Jan–Feb 2026). These are not stale references from a format migration — the files were actively maintained and then deleted.
Example from sessions-index.json:
{
"sessionId": "7ae2c6c3-acd8-4f61-baec-d467a21cbd9e",
"fullPath": "~/.claude/projects/-Users-andrew-Documents-Coram-repos-logistics-app/7ae2c6c3-....jsonl",
"fileMtime": 1769033018707,
"messageCount": 57,
"created": "2026-01-08T23:10:07.576Z",
"summary": "LLM config Langfuse logging EDGE-898"
}The fullPath .jsonl file no longer exists. The directory for this session ID also no longer exists. But the index proves the file was there.
Root cause (likely)
The session listing function (visible in the binary as Y79) scans for .jsonl files:
if(!O.endsWith(".jsonl"))return nullA cleanup or migration step during auto-update appears to delete .jsonl files from project directories it considers stale — possibly based on project path changes (the working directory path changed over time as repos moved). The cleanup does not update or remove the corresponding sessions-index.json entries, leaving orphaned references.
Impact
- Permanent, unrecoverable loss of conversation history
/statstoken counts are wrong (showing ~45% of actual usage)sessions-index.jsonfiles are orphaned tombstones- No warning, no backup, no opt-out
Expected behavior
- Auto-updates should never delete session data without explicit user consent
- If a storage format migration is needed, old data should be migrated, not deleted
- At minimum, if cleanup is intentional,
sessions-index.jsonshould be updated to reflect the deletion
Versions affected
Cannot confirm exact version that introduced the cleanup, as older binaries are removed during auto-update. Observed across the upgrade path leading to 2.1.86 → 2.1.87 → 2.1.88.
Activity
github-actions commentedon Mar 31, 2026
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
AndrewTKent commentedon Mar 31, 2026
Updated findings: Feb 2 migration is the root cause
After deeper investigation, the data loss traces back to a single migration event on Feb 2, 2026, not the Mar 25/30 auto-updates I originally suspected.
Evidence: Feb 2 migration built
sessions-index.jsonand deleted source filesThe
sessions-index.jsonfiles containfileMtimetimestamps for every session's.jsonlfile. Across 351 entries in one project dir, the fileMtimes cluster overwhelmingly on Feb 2:This is a migration processing sessions throughout the day — not normal user activity. A Claude Code update on or around Feb 2 appears to have:
.jsonlfiles across every project directorysessions-index.json(version 1) with metadata extracted from each file.jsonlfiles after indexing themThe index preserved metadata (session ID, first prompt, summary, message count, dates, git branch) but no token usage data. The conversation content and token counts are gone.
Timeline reconstruction
<project>/<uuid>.jsonlfiles with<uuid>/subagents/dirs alongsidesessions-index.jsonfrom existing.jsonlfiles. Deletes the.jsonlfiles after indexing. ~300+ files processed over several hours..jsonlfiles. Index is periodically updated..jsonlfiles that are never indexed.Coram-repos-*) touched/scanned by Claude Code startup — their.jsonlfiles were already long gone.What survives from the deleted sessions
sessions-index.json— metadata only (no tokens): session ID, summary, message count, first prompt, dates, git branchsubagents/directories — contain full.jsonlfiles with real token usage data for every subagent spawned during those sessionshistory.jsonl— user prompt history going back to Jan 2Key distinction from original report
The Mar 25/30 directory modifications I initially flagged as "deletion events" were actually just Claude Code scanning/touching project dirs on startup. The actual data loss happened on Feb 2 during a migration that built the sessions-index system. The migration extracted metadata but discarded the conversation data.
Suggestions
.jsonlfiles — or at minimum should have preserved token usage data in the indexsessions-index.jsonformat (version 1) stores no token information, making it impossible to reconstruct/statstotals for indexed-but-deleted sessionstokenUsagefield to future index versions so stats survive even if session files are cleaned upAndrewTKent commentedon Mar 31, 2026
Additional finding: /stats never counts subagent tokens
Separate from the data loss issue —
/statshas always undercounted token usage because it excludes subagent tokens entirely.Evidence
tokensByModeltotal: 13.6m (input + output from main.jsonlfiles only)The stats computation (
Y79function in the binary) only scans<project>/<uuid>.jsonlfiles. It does not walk into<project>/<uuid>/subagents/directories. This means any user who spawns subagents (via the Agent tool, parallel investigations, etc.) sees a/statstotal that's 2-4x lower than their real usage.Suggested fix
The stats computation should also scan
subagents/*.jsonlfiles within each session directory and include theirinput_tokens+output_tokensindailyModelTokensandmodelUsage. The deduplication-by-requestId approach is already needed for streaming messages in main sessions — the same logic applies to subagent files.Impact
This affects all users who use subagents, but disproportionately affects power users who spawn many parallel agents. For this user's workflow (frequent
/investigate,/sweep,/review-prwith 5-10+ agents), 3/4 of token usage was invisible.ChTauchmann commentedon Apr 24, 2026
Confirming this bug reproduces on Linux / HPC — not macOS-specific
Adding forensic data to support this issue from a Linux (RHEL 9, VAST/NFS filesystem) system affected by the same pattern.
Environment: Linux 5.14, Claude Code self-installed (not npm auto-update),
autoUpdates: falsein.claude.jsonMigration event timestamp: 2026-04-03 15:04:13 UTC
Version path:
lastReleaseNotesSeen: 2.1.41→ current2.1.119(crossed 2.1.87, the version implicated in the original report)Evidence of upgrade migration at the deletion moment:
~/.claude.json:autoUpdaterStatus: "migrated"(Claude Code's own flag indicating data migration ran)~/.claude/plugins/marketplaces/claude-plugins-official/(hundreds of files — suggests the upgrade installed the plugin subsystem for the first time).bash_historylast-modified)~/.claude/projects/directory and four-repos-*subdirectories had ctimes updated within the same second — matching a single batch operation by Claude Code itself, 4.5 minutes after the user's shell had already closedSymptom matches #41591 exactly:
sessions-index.jsoncontains 17 indexed sessions withfullPathreferences to<uuid>.jsonlfiles.jsonlfiles exist at the paths the index claims<uuid>/subagents/agent-*.jsonldirectories survive with ~206 agent logs (110+ in one project alone)<uuid>.jsonlfiles are present; the losses are concentrated in projects inactive at the time of the migrationScale of loss (one user):
Ruled out as causes via forensic audit:
rm/find -delete/mvcommands referencing.claudein.bash_history.jsonlfiles or archives anywhere on disk that match the missing session UUIDsThis strengthens the case that the cleanup logic runs across platforms, not just macOS, and is tied to the version-upgrade migration path rather than a platform-specific npm hook. Happy to share the full file-ctime timeline or
sessions-index.jsonsamples privately if an engineer wants to inspect repro data.Gotchaha commentedon Apr 30, 2026
Confirming this also occurred on v2.1.114 → 2.1.123 update (Apr 30, 2026). 4 sessions from Feb 18–24 lost across 2 projects. Session directories with subagent JSONLs intact, parent JSONL files gone. sessions-index.json also missing from one project.
--resumeshows nothing #54907 as a duplicate of this issuegithub-actions commentedon May 31, 2026
Closing for now — inactive for too long. Please open a new issue if this is still relevant.
github-actions commentedon Aug 2, 2026
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.