Skip to content

Commit 12610e0

Browse files
committed
feat: add list_sessions top-level function
Ports listSessions() from the TypeScript SDK as a filesystem-reading implementation (not a CLI passthrough). Scans ~/.claude/projects/ for .jsonl session files and extracts metadata via stat + head/tail reads without full JSONL parsing. - Add SDKSessionInfo dataclass to types.py (session_id, summary, last_modified, file_size, custom_title, first_prompt, git_branch, cwd) - Add _internal/sessions.py with path sanitization, JSON field extraction, first-prompt parsing, and git worktree detection - Export list_sessions() and SDKSessionInfo from __init__.py - Filter sidechain sessions and empty metadata-only sessions (no '(session)' placeholder fallback) - Support include_worktrees option (default True) to scan all git worktree paths for a project - 38 tests covering helpers and integration scenarios
1 parent a58d3ab commit 12610e0

4 files changed

Lines changed: 1254 additions & 0 deletions

File tree

src/claude_agent_sdk/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
CLINotFoundError,
1414
ProcessError,
1515
)
16+
from ._internal.sessions import list_sessions
1617
from ._internal.transport import Transport
1718
from ._version import __version__
1819
from .client import ClaudeSDKClient
@@ -52,6 +53,7 @@
5253
SandboxSettings,
5354
SdkBeta,
5455
SdkPluginConfig,
56+
SDKSessionInfo,
5557
SettingSource,
5658
StopHookInput,
5759
SubagentStartHookInput,
@@ -378,6 +380,9 @@ async def call_tool(name: str, arguments: dict[str, Any]) -> Any:
378380
"SettingSource",
379381
# Plugin support
380382
"SdkPluginConfig",
383+
# Session listing
384+
"list_sessions",
385+
"SDKSessionInfo",
381386
# Beta support
382387
"SdkBeta",
383388
# Sandbox support

0 commit comments

Comments
 (0)