Skip to content

Sort completed sessions by modification time instead of filename#2

Merged
notkurt merged 1 commit intomainfrom
claude/fix-session-sorting-w3RhW
Feb 13, 2026
Merged

Sort completed sessions by modification time instead of filename#2
notkurt merged 1 commit intomainfrom
claude/fix-session-sorting-w3RhW

Conversation

@notkurt
Copy link
Owner

@notkurt notkurt commented Feb 13, 2026

Summary

Updated session sorting logic to use file modification time (mtime) instead of alphabetical filename sorting. This ensures that the most recently modified session files are consistently returned first, regardless of their naming scheme.

Key Changes

  • Added statSync to the fs imports to enable file stat queries
  • Modified findRecentSession() to sort files by modification time in descending order
  • Modified getMostRecentCompletedId() to sort files by modification time in descending order
  • Modified listCompletedSessions() to sort files by modification time in descending order

Implementation Details

  • Replaced .sort().reverse() chains with custom comparators that use statSync(join(compDir, file)).mtimeMs
  • The comparator sorts in descending order (most recent first) by subtracting the earlier file's mtime from the later file's mtime
  • This change makes the sorting behavior more reliable and semantically correct, as it now reflects actual file recency rather than lexicographic order

https://claude.ai/code/session_01Y33sCLqbB9YHAJNsPzEJgp

Session IDs use the format YYYY-MM-DD-<random>, so alphabetical sorting
picks whichever session has the highest random hex suffix, not the most
recent one. This caused checkpoint() to always attach the same session's
git note to every commit when multiple sessions existed for the same day.

Sort by file modification time in getMostRecentCompletedId,
listCompletedSessions, and findRecentSession.

https://claude.ai/code/session_01Y33sCLqbB9YHAJNsPzEJgp
@notkurt notkurt merged commit 01ed980 into main Feb 13, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments