-
Notifications
You must be signed in to change notification settings - Fork 137
feat: implement unstable_listSessions for session/list RFD #254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@remorses thanks for this! I was planning to just deal with file parsing as well in the meantime. I'll give this a look, but would be great to have for sure, thanks for taking a look! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements the draft session/list RFD specification by adding the ability to list Claude Code sessions stored in the local filesystem. The implementation reads and parses JSONL session files from ~/.claude/projects/, extracts session metadata (title, timestamp, cwd), and provides pagination support.
Changes:
- Added
unstable_listSessionsmethod that parses session files from local storage - Advertised
listcapability in thesessionCapabilitiesinitialization response - Implemented cursor-based pagination with page size of 50 sessions
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Ok I will add tests. I wanted to make sure this feature was welcome first |
Adds support for the draft session/list RFD spec by reading Claude Code's local session files from ~/.claude/projects/. - Parse JSONL session files to extract sessionId, cwd, title, updatedAt - Support filtering by cwd parameter - Implement cursor-based pagination (50 sessions per page) - Advertise list capability in sessionCapabilities
Tests cover: - Empty/missing projects directory - Session file parsing (sessionId, cwd, title, updatedAt) - Title extraction from string and array message formats - Filtering by cwd parameter - Sorting by updatedAt descending - Skipping agent-* files and malformed files - Cursor-based pagination
Claude encodes paths as: /Users/morse/project -> -Users-morse-project (leading dash, all slashes become dashes)
- Add comment explaining agent-*.jsonl file filtering - Use safer firstLine variable instead of lines[0]! assertion - Improve title extraction with explicit type guards for array content
- Add decodeProjectPath() helper that handles both Unix and Windows paths - Unix: '-Users-morse-project' -> '/Users/morse/project' - Windows: 'C-Users-morse-project' -> 'C:\Users\morse\project' - Update test helper to encode Windows paths correctly - Add 3 new tests for Windows path handling
The upstream codebase uses process.env.CLAUDE to override the config dir, but this is undocumented and could conflict with user env vars. Tests save/restore the original value to avoid side effects.
- Use CLAUDE_CONFIG_DIR const instead of runtime env check - Use async fs.promises for non-blocking operations - Add this.logger.error() for error logging - Add comment explaining pagination rationale - Update tests to use vi.resetModules() for proper CLAUDE_CONFIG_DIR handling
ddb6e43 to
c65764c
Compare
|
thanks! It is working for me, so I'll merge and we can see what feedback we get |
Adds support for the draft session/list RFD spec by reading Claude Code's local session files.
unstable_listSessionsmethod that parses JSONL session files from~/.claude/projects/listcapability insessionCapabilitiescwdparameterupdatedAtRelated: https://agentclientprotocol.com/rfds/session-list
What do you think @benbrandt? Is it ok to do the json files parsing ourselves? I also opened an issue in the claude agent sdk repo but I doubt they will add that functionality in the sdk npm package