claude-code - 💡(How to fix) Fix Session picker sorts by file mtime; OS/IDE events that touch mtime scramble chronological order [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#52071Fetched 2026-04-23 07:37:20
View on GitHub
Comments
1
Participants
2
Timeline
6
Reactions
0
Timeline (top)
labeled ×5commented ×1

The VSCode extension session picker ("Local" tab) appears to sort sessions by the .jsonl file's filesystem mtime rather than by the last message timestamp inside the file. Any event that restamps mtimes without editing content — a VSCode update, an extension reload, a Time Machine pass, a Spotlight reindex, a Dropbox/iCloud sync, a find … -exec touch — silently reorders the picker and can bury the actual most-recent session under older ones.

Root Cause

Sort the picker by lastMessageAt read from the JSONL (last timestamp field, or a cached field on the session), not by file mtime. mtime is not a reliable proxy for "time of last conversation activity" because many OS-level and IDE-level events modify mtime without editing content.

Code Example

for f in ~/.claude/projects/<project>/*.jsonl; do
    echo \"$(tail -c 30000 \"$f\" | grep -oE '\"timestamp\":\"[^\"]+\"' | tail -1) $f\"
  done | sort -r | head -5
RAW_BUFFERClick to expand / collapse

Summary

The VSCode extension session picker ("Local" tab) appears to sort sessions by the .jsonl file's filesystem mtime rather than by the last message timestamp inside the file. Any event that restamps mtimes without editing content — a VSCode update, an extension reload, a Time Machine pass, a Spotlight reindex, a Dropbox/iCloud sync, a find … -exec touch — silently reorders the picker and can bury the actual most-recent session under older ones.

Repro (what I hit today)

  1. Had a long active session in this project (6+ hours of work, last message at 2026-04-22T17:38:31Z).
  2. Updated VSCode (~30s). The update run touched ~200 .jsonl files in ~/.claude/projects/<project>/, rewriting their mtimes to within a ~30-second window at roughly 2026-04-22 10:40 local.
  3. Reopened Claude Code → new chat auto-started.
  4. Opened the session picker to resume. Every session showed the same relative label ("5m"), and the ordering no longer reflected recency. A session whose last internal message was 2 days ago (2026-04-20T20:39Z) ranked near the top; the session I'd been working in (true last message 6 min ago) was buried several entries down.

Evidence the data itself is fine

  • Inside each .jsonl, message timestamp fields are correct.
  • Sorting by the last internal timestamp across all files instantly gives the true most-recent session:
    for f in ~/.claude/projects/<project>/*.jsonl; do
      echo \"$(tail -c 30000 \"$f\" | grep -oE '\"timestamp\":\"[^\"]+\"' | tail -1) $f\"
    done | sort -r | head -5
  • ls -lat showed ~200 files all sharing the same Apr 22 10:40 mtime — physically impossible for genuine activity; the OS/extension touched them all inside one short window.

Suggested fix

Sort the picker by lastMessageAt read from the JSONL (last timestamp field, or a cached field on the session), not by file mtime. mtime is not a reliable proxy for "time of last conversation activity" because many OS-level and IDE-level events modify mtime without editing content.

Why it matters

When a user has many sessions per project (I have 218 in this one), the picker ordering is the only way to find a specific conversation to resume. If ordering silently breaks after routine events like an IDE update, the user reasonably concludes their chat history was lost (I did). Recovery is possible by reading internal timestamps, but that requires a shell and knowing where the files live.

Environment

  • macOS (Darwin 25.3.0)
  • VSCode native extension
  • Shell: zsh
  • Session count in affected project: 218 files
  • Update that triggered it: routine VSCode update (~30s), no extension-specific action taken

Nice-to-haves (optional)

  • Show absolute last-activity time, not just a relative 5m label, so users can spot a stale sort.
  • A "Reindex by internal timestamp" action in the picker for recovery after this class of event.

extent analysis

TL;DR

The VSCode extension session picker should be sorted by the lastMessageAt timestamp from the JSONL files instead of the file's mtime to ensure accurate ordering.

Guidance

  • Verify that the issue is caused by the file mtime being updated without editing the content by checking the ls -lat output, which should show multiple files with the same mtime.
  • To mitigate the issue, use the provided bash script to sort the sessions by the last internal timestamp: for f in ~/.claude/projects/<project>/*.jsonl; do echo "$(tail -c 30000 "$f" | grep -oE '\"timestamp\":\"[^\"]+\"' | tail -1) $f"; done | sort -r | head -5.
  • Consider implementing a "Reindex by internal timestamp" action in the picker to allow users to recover from this issue after events like IDE updates.
  • To ensure accurate sorting, the session picker should be updated to read the lastMessageAt timestamp from the JSONL files instead of relying on the file mtime.

Example

No code snippet is provided as the issue is more related to the logic of the session picker rather than a specific code error.

Notes

The issue is specific to the VSCode extension and the way it handles session sorting. The provided bash script can be used as a temporary workaround to sort the sessions correctly.

Recommendation

Apply a workaround by using the provided bash script to sort the sessions by the last internal timestamp until the session picker is updated to sort by the lastMessageAt timestamp. This will ensure accurate ordering of the sessions and prevent the issue caused by file mtime updates.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix Session picker sorts by file mtime; OS/IDE events that touch mtime scramble chronological order [1 comments, 2 participants]