Skip to content

Auto-update deletes session .jsonl files, wiping token usage history and conversation data #41591

Closed as not planned

Description

@AndrewTKent

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.json files have their .jsonl files missing
  • 282 session directories exist with only subagents/ data inside — the main conversation .jsonl is gone
  • Session dates span Jan 2 – ~Mar 1, 2026 — roughly 2 months of daily heavy usage
  • /stats shows 13.7m tokens (from ~1 month of surviving data); actual usage was likely 30m+

What survived

  • Session directories with subagent .jsonl files (11,207 files containing real token usage data)
  • sessions-index.json files — still reference the deleted .jsonl paths with metadata (session summaries, message counts, dates, branches) but no token counts
  • history.jsonl — prompt history going back to Jan 2
  • Session .jsonl files 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 null

A 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
  • /stats token counts are wrong (showing ~45% of actual usage)
  • sessions-index.json files 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.json should 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

  1. github-actions commented on Mar 31, 2026

    @github-actions

    Found 3 possible duplicate issues:

    1. [BUG] CLI silently deletes session .jsonl files created on v2.1.37–v2.1.39 during later auto-updates #36272
    2. [BUG] cleanupPeriodDays: 99999 ignored — 490 sessions silently deleted despite explicit setting #41458
    3. VS Code extension auto-update deletes CLI session history files #35367

    This issue will be automatically closed as a duplicate in 3 days.

    • If your issue is a duplicate, please close it and 👍 the existing issue instead
    • To prevent auto-closure, add a comment or 👎 this comment

    🤖 Generated with Claude Code

  2. AndrewTKent commented on Mar 31, 2026

    @AndrewTKent
    Author

    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.json and deleted source files

    The sessions-index.json files contain fileMtime timestamps for every session's .jsonl file. Across 351 entries in one project dir, the fileMtimes cluster overwhelmingly on Feb 2:

    2026-02-02 10:31: 3 files
    2026-02-02 12:15: 2 files
    2026-02-02 12:39: 7 files
    2026-02-02 12:48: 8 files
    2026-02-02 12:49: 11 files
    2026-02-02 13:07-13:32: ~80 files (spread across minutes)
    2026-02-02 14:32-14:41: ~35 files
    2026-02-02 15:35-15:42: ~38 files
    2026-02-02 17:41-17:43: 20 files
    2026-02-02 20:24: 10 files
    

    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:

    1. Scanned all existing session .jsonl files across every project directory
    2. Built sessions-index.json (version 1) with metadata extracted from each file
    3. Deleted the source .jsonl files after indexing them

    The 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

    Date Event
    Jan 2 – Jan 31 Sessions stored as <project>/<uuid>.jsonl files with <uuid>/subagents/ dirs alongside
    Feb 2 Claude Code update runs migration. Builds sessions-index.json from existing .jsonl files. Deletes the .jsonl files after indexing. ~300+ files processed over several hours.
    Feb 2 – Mar 1 New sessions continue writing .jsonl files. Index is periodically updated.
    ~Mar 2 Another format change — index stops being updated. Sessions after this date write .jsonl files that are never indexed.
    Mar 25 Old project dirs (Coram-repos-*) touched/scanned by Claude Code startup — their .jsonl files were already long gone.
    Mar 30 Version 2.1.87 auto-installs, scans project dirs (all modified at same second 10:51:58).

    What survives from the deleted sessions

    • sessions-index.json — metadata only (no tokens): session ID, summary, message count, first prompt, dates, git branch
    • subagents/ directories — contain full .jsonl files with real token usage data for every subagent spawned during those sessions
    • history.jsonl — user prompt history going back to Jan 2

    Key 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

    1. The sessions-index migration should not have deleted source .jsonl files — or at minimum should have preserved token usage data in the index
    2. The sessions-index.json format (version 1) stores no token information, making it impossible to reconstruct /stats totals for indexed-but-deleted sessions
    3. Consider adding a tokenUsage field to future index versions so stats survive even if session files are cleaned up
  3. AndrewTKent commented on Mar 31, 2026

    @AndrewTKent
    Author

    Additional finding: /stats never counts subagent tokens

    Separate from the data loss issue — /stats has always undercounted token usage because it excludes subagent tokens entirely.

    Evidence

    • Original stats-cache tokensByModel total: 13.6m (input + output from main .jsonl files only)
    • Subagent input + output across 11,252 surviving subagent files: 43.5m
    • Subagent tokens represent 76% of actual token usage for this user

    The stats computation (Y79 function in the binary) only scans <project>/<uuid>.jsonl files. 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 /stats total that's 2-4x lower than their real usage.

    Suggested fix

    The stats computation should also scan subagents/*.jsonl files within each session directory and include their input_tokens + output_tokens in dailyModelTokens and modelUsage. 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-pr with 5-10+ agents), 3/4 of token usage was invisible.

  4. ChTauchmann commented on Apr 24, 2026

    @ChTauchmann

    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: false in .claude.json

    Migration event timestamp: 2026-04-03 15:04:13 UTC

    Version path: lastReleaseNotesSeen: 2.1.41 → current 2.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)
    • 2026-04-03 14:46:01 UTC: Plugin marketplace files mass-created under ~/.claude/plugins/marketplaces/claude-plugins-official/ (hundreds of files — suggests the upgrade installed the plugin subsystem for the first time)
    • 2026-04-03 14:59:54 UTC: User shell session ended (.bash_history last-modified)
    • 2026-04-03 15:04:13 UTC: ~/.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 closed

    Symptom matches #41591 exactly:

    • sessions-index.json contains 17 indexed sessions with fullPath references to <uuid>.jsonl files
    • 0 of those .jsonl files exist at the paths the index claims
    • <uuid>/subagents/agent-*.jsonl directories survive with ~206 agent logs (110+ in one project alone)
    • Active project (current working dir) unaffected — its <uuid>.jsonl files are present; the losses are concentrated in projects inactive at the time of the migration

    Scale of loss (one user):

    • 27 sessions total across 8 projects (17 indexed + 10 orphan UUID dirs)
    • ~305 conversation messages lost from indexed sessions alone; estimated 400–500 total
    • Concentrated in intensive multi-session research work (multilingual model training, ablation studies) from Dec 2025 – Jan 2026

    Ruled out as causes via forensic audit:

    • No rm/find -delete/mv commands referencing .claude in .bash_history
    • User-level cron only touches SLURM logs
    • No systemd user services affecting home
    • VAST filesystem snapshots inaccessible / unavailable for recovery
    • Independent file-moving operation on the same system happened 2026-04-19 (16 days after the loss event)
    • Home directory contains no orphan .jsonl files or archives anywhere on disk that match the missing session UUIDs

    This 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.json samples privately if an engineer wants to inspect repro data.

  5. Gotchaha commented on Apr 30, 2026

    @Gotchaha

    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.

  6. github-actions commented on May 31, 2026

    @github-actions

    Closing for now — inactive for too long. Please open a new issue if this is still relevant.

  7. github-actions commented on Aug 2, 2026

    @github-actions

    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.

  8. locked as resolved and limited conversation to collaborators on Aug 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdata-losshas reproHas detailed reproduction stepsplatform:macosIssue specifically occurs on macOSstaleIssue is inactive

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions