Sort completed sessions by modification time instead of filename#2
Merged
Sort completed sessions by modification time instead of filename#2
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
statSyncto the fs imports to enable file stat queriesfindRecentSession()to sort files by modification time in descending ordergetMostRecentCompletedId()to sort files by modification time in descending orderlistCompletedSessions()to sort files by modification time in descending orderImplementation Details
.sort().reverse()chains with custom comparators that usestatSync(join(compDir, file)).mtimeMshttps://claude.ai/code/session_01Y33sCLqbB9YHAJNsPzEJgp