Skip to content

session

Class info

Classes

Name Children Inherits
ConversationTurn
clawd_code_sdk.session
Collected result of a single send/receive cycle.
    Session
    clawd_code_sdk.session
    A managed Claude session wrapping a ClaudeSDKClient.
      SessionManager
      clawd_code_sdk.session
      Manages multiple concurrent Claude SDK sessions.
        SessionSnapshot
        clawd_code_sdk.session
        Read-only snapshot of session metadata at a point in time.
          ToolCallSummary
          clawd_code_sdk.session
          Summary of a single tool invocation within a conversation turn.

            🛈 DocStrings

            Session manager for managing multiple Claude SDK client sessions.

            INTERRUPT_DRAIN_TIMEOUT module-attribute

            INTERRUPT_DRAIN_TIMEOUT = 30.0
            

            Seconds send() waits for an abandoned turn to end after interrupting it.

            ConversationTurn dataclass

            Collected result of a single send/receive cycle.

            Source code in src/clawd_code_sdk/session.py
            @dataclass(frozen=True)
            class ConversationTurn:
                """Collected result of a single send/receive cycle."""
            
                messages: tuple[Message, ...]
                result: ResultMessage
                text: str
                tool_calls: tuple[ToolCallSummary, ...]
                cost_usd: float | None
                duration_ms: int
            

            Session

            A managed Claude session wrapping a ClaudeSDKClient.

            Not constructed directly — use SessionManager.create_session().

            Source code in src/clawd_code_sdk/session.py
            class Session:
                """A managed Claude session wrapping a ClaudeSDKClient.
            
                Not constructed directly — use ``SessionManager.create_session()``.
                """
            
                def __init__(self, session_id: str, client: ClaudeSDKClient) -> None:
                    self._session_id = session_id
                    self._client = client
                    self._state: SessionState = "created"
                    self._turns: list[ConversationTurn] = []
                    self._created_at = datetime.now(UTC)
                    self._last_activity = self._created_at
            
                @property
                def session_id(self) -> str:
                    return self._session_id
            
                @property
                def state(self) -> SessionState:
                    return self._state
            
                @property
                def client(self) -> ClaudeSDKClient:
                    """Access the underlying client for low-level operations."""
                    return self._client
            
                @property
                def turns(self) -> list[ConversationTurn]:
                    """All completed conversation turns in this session."""
                    return list(self._turns)
            
                @property
                def total_cost_usd(self) -> float:
                    """Accumulated cost across all turns."""
                    return sum(t.cost_usd for t in self._turns if t.cost_usd is not None)
            
                @property
                def snapshot(self) -> SessionSnapshot:
                    """Current metadata snapshot."""
                    return SessionSnapshot(
                        session_id=self._session_id,
                        state=self._state,
                        model=self._client.options.model,
                        cwd=str(self._client.options.cwd) if self._client.options.cwd else None,
                        created_at=self._created_at,
                        last_activity=self._last_activity,
                        turn_count=len(self._turns),
                        total_cost_usd=self.total_cost_usd,
                    )
            
                async def send(self, prompt: str) -> AsyncIterator[Message]:
                    """Send a prompt and stream response messages.
            
                    Combines ``client.query()`` + ``client.receive_response()`` into one call.
                    Yields every message including the final ``ResultMessage``, then stops.
                    The completed ``ConversationTurn`` is appended to ``self.turns``.
            
                    Raises:
                        RuntimeError: If the session is not in IDLE state.
                    """
                    if self._state != "idle":
                        msg = (
                            f"Cannot send: session {self._session_id!r} is in state "
                            f"{self._state!r}, expected 'idle'"
                        )
                        raise RuntimeError(msg)
            
                    self._state = "responding"
                    self._last_activity = datetime.now(UTC)
                    collected: list[Message] = []
            
                    completed = False
                    sent = False
                    try:
                        # Shielded (anyio scopes): once the write starts, the prompt is sent, so
                        # `sent` tells whether a turn may be running.
                        with anyio.CancelScope(shield=True):
                            await self._client.query(prompt)
                        sent = True
                        async for message in self._client.receive_response():
                            collected.append(message)
                            if isinstance(message, ResultMessage):
                                # Before the yield: a consumer stopping at the result ends a full turn.
                                completed = True
                                turn = _extract_turn(collected, message)
                                self._turns.append(turn)
                                self._last_activity = datetime.now(UTC)
                            yield message
                        self._state = "idle"
                    except Exception:
                        self._state = "error"
                        raise
                    except BaseException:
                        # The consumer broke out (GeneratorExit) or was cancelled: stop the turn
                        # if it is still running, so the next send() starts from a quiet session.
                        if completed or not sent:
                            self._state = "idle"
                        else:
                            self._state = "error"  # unless the turn is wound down below
                            with anyio.CancelScope(shield=True):
                                try:
                                    await self._finish_interrupted_turn()
                                except Exception:
                                    logger.warning("Could not stop the interrupted turn", exc_info=True)
                                else:
                                    self._state = "idle"
                        raise
            
                async def _finish_interrupted_turn(self) -> None:
                    """Interrupt the running turn and read it to its end (its result message).
            
                    Otherwise the next ``send()`` would receive the rest of this turn.
            
                    Raises:
                        TimeoutError: The turn didn't end within ``INTERRUPT_DRAIN_TIMEOUT``.
                    """
                    await self._client.interrupt()
                    with anyio.fail_after(INTERRUPT_DRAIN_TIMEOUT):
                        async for message in self._client.receive_response():
                            if isinstance(message, ResultMessage):
                                break
            
                async def send_and_collect(self, prompt: str) -> ConversationTurn:
                    """Send a prompt and return the full collected response.
            
                    Convenience for cases where streaming is not needed.
            
                    Raises:
                        RuntimeError: If the session is not in IDLE state or no
                            ResultMessage was received.
                    """
                    last_turn_count = len(self._turns)
                    async for _ in self.send(prompt):
                        pass
                    if len(self._turns) <= last_turn_count:
                        msg = "No ResultMessage received — response may have been interrupted"
                        raise RuntimeError(msg)
                    return self._turns[-1]
            
                async def interrupt(self) -> None:
                    """Send interrupt signal to the current response."""
                    await self._client.interrupt()
            
                async def set_model(self, model: str | None = None) -> None:
                    """Change the AI model during conversation."""
                    await self._client.set_model(model)
            
                async def set_permission_mode(
                    self, mode: PermissionMode
                ) -> SDKControlSetPermissionModeResponse | None:
                    """Change permission mode during conversation (returns the mode now in effect)."""
                    return await self._client.set_permission_mode(mode)
            
                async def set_max_thinking_tokens(self, max_thinking_tokens: int) -> None:
                    """Set the maximum number of thinking tokens."""
                    await self._client.set_max_thinking_tokens(max_thinking_tokens)
            
                async def close(self) -> None:
                    """Disconnect and release resources. Idempotent."""
                    if self._state == "disconnected":
                        return
                    try:
                        await self._client.disconnect()
                    finally:
                        self._state = "disconnected"
            

            client property

            Access the underlying client for low-level operations.

            snapshot property

            snapshot: SessionSnapshot
            

            Current metadata snapshot.

            total_cost_usd property

            total_cost_usd: float
            

            Accumulated cost across all turns.

            turns property

            turns: list[ConversationTurn]
            

            All completed conversation turns in this session.

            close async

            close() -> None
            

            Disconnect and release resources. Idempotent.

            Source code in src/clawd_code_sdk/session.py
            async def close(self) -> None:
                """Disconnect and release resources. Idempotent."""
                if self._state == "disconnected":
                    return
                try:
                    await self._client.disconnect()
                finally:
                    self._state = "disconnected"
            

            interrupt async

            interrupt() -> None
            

            Send interrupt signal to the current response.

            Source code in src/clawd_code_sdk/session.py
            async def interrupt(self) -> None:
                """Send interrupt signal to the current response."""
                await self._client.interrupt()
            

            send async

            send(prompt: str) -> AsyncIterator[Message]
            

            Send a prompt and stream response messages.

            Combines client.query() + client.receive_response() into one call. Yields every message including the final ResultMessage, then stops. The completed ConversationTurn is appended to self.turns.

            Raises:

            Type Description
            RuntimeError

            If the session is not in IDLE state.

            Source code in src/clawd_code_sdk/session.py
            async def send(self, prompt: str) -> AsyncIterator[Message]:
                """Send a prompt and stream response messages.
            
                Combines ``client.query()`` + ``client.receive_response()`` into one call.
                Yields every message including the final ``ResultMessage``, then stops.
                The completed ``ConversationTurn`` is appended to ``self.turns``.
            
                Raises:
                    RuntimeError: If the session is not in IDLE state.
                """
                if self._state != "idle":
                    msg = (
                        f"Cannot send: session {self._session_id!r} is in state "
                        f"{self._state!r}, expected 'idle'"
                    )
                    raise RuntimeError(msg)
            
                self._state = "responding"
                self._last_activity = datetime.now(UTC)
                collected: list[Message] = []
            
                completed = False
                sent = False
                try:
                    # Shielded (anyio scopes): once the write starts, the prompt is sent, so
                    # `sent` tells whether a turn may be running.
                    with anyio.CancelScope(shield=True):
                        await self._client.query(prompt)
                    sent = True
                    async for message in self._client.receive_response():
                        collected.append(message)
                        if isinstance(message, ResultMessage):
                            # Before the yield: a consumer stopping at the result ends a full turn.
                            completed = True
                            turn = _extract_turn(collected, message)
                            self._turns.append(turn)
                            self._last_activity = datetime.now(UTC)
                        yield message
                    self._state = "idle"
                except Exception:
                    self._state = "error"
                    raise
                except BaseException:
                    # The consumer broke out (GeneratorExit) or was cancelled: stop the turn
                    # if it is still running, so the next send() starts from a quiet session.
                    if completed or not sent:
                        self._state = "idle"
                    else:
                        self._state = "error"  # unless the turn is wound down below
                        with anyio.CancelScope(shield=True):
                            try:
                                await self._finish_interrupted_turn()
                            except Exception:
                                logger.warning("Could not stop the interrupted turn", exc_info=True)
                            else:
                                self._state = "idle"
                    raise
            

            send_and_collect async

            send_and_collect(prompt: str) -> ConversationTurn
            

            Send a prompt and return the full collected response.

            Convenience for cases where streaming is not needed.

            Raises:

            Type Description
            RuntimeError

            If the session is not in IDLE state or no ResultMessage was received.

            Source code in src/clawd_code_sdk/session.py
            async def send_and_collect(self, prompt: str) -> ConversationTurn:
                """Send a prompt and return the full collected response.
            
                Convenience for cases where streaming is not needed.
            
                Raises:
                    RuntimeError: If the session is not in IDLE state or no
                        ResultMessage was received.
                """
                last_turn_count = len(self._turns)
                async for _ in self.send(prompt):
                    pass
                if len(self._turns) <= last_turn_count:
                    msg = "No ResultMessage received — response may have been interrupted"
                    raise RuntimeError(msg)
                return self._turns[-1]
            

            set_max_thinking_tokens async

            set_max_thinking_tokens(max_thinking_tokens: int) -> None
            

            Set the maximum number of thinking tokens.

            Source code in src/clawd_code_sdk/session.py
            async def set_max_thinking_tokens(self, max_thinking_tokens: int) -> None:
                """Set the maximum number of thinking tokens."""
                await self._client.set_max_thinking_tokens(max_thinking_tokens)
            

            set_model async

            set_model(model: str | None = None) -> None
            

            Change the AI model during conversation.

            Source code in src/clawd_code_sdk/session.py
            async def set_model(self, model: str | None = None) -> None:
                """Change the AI model during conversation."""
                await self._client.set_model(model)
            

            set_permission_mode async

            set_permission_mode(mode: PermissionMode) -> SDKControlSetPermissionModeResponse | None
            

            Change permission mode during conversation (returns the mode now in effect).

            Source code in src/clawd_code_sdk/session.py
            async def set_permission_mode(
                self, mode: PermissionMode
            ) -> SDKControlSetPermissionModeResponse | None:
                """Change permission mode during conversation (returns the mode now in effect)."""
                return await self._client.set_permission_mode(mode)
            

            SessionManager

            Manages multiple concurrent Claude SDK sessions.

            Usage::

            async with SessionManager() as manager:
                s1 = await manager.create_session("coding", options=opts)
                turn = await s1.send_and_collect("Explain this codebase")
                print(turn.text)
            
                s2 = await manager.create_session("review", options=opts, prompt="Review my PR")
                async for msg in s2.send("What issues did you find?"):
                    ...
            
            Source code in src/clawd_code_sdk/session.py
            class SessionManager:
                """Manages multiple concurrent Claude SDK sessions.
            
                Usage::
            
                    async with SessionManager() as manager:
                        s1 = await manager.create_session("coding", options=opts)
                        turn = await s1.send_and_collect("Explain this codebase")
                        print(turn.text)
            
                        s2 = await manager.create_session("review", options=opts, prompt="Review my PR")
                        async for msg in s2.send("What issues did you find?"):
                            ...
                """
            
                def __init__(self, *, max_concurrent_sessions: int | None = None) -> None:
                    """Initialize the session manager.
            
                    Args:
                        max_concurrent_sessions: Optional cap on simultaneous connected
                            sessions. ``create_session`` raises if exceeded.
                    """
                    self._sessions: dict[str, Session] = {}
                    self._max_concurrent_sessions = max_concurrent_sessions
            
                # ── Session lifecycle ────────────────────────────────────────
            
                async def create_session(
                    self,
                    session_id: str | None = None,
                    *,
                    options: ClaudeAgentOptions | None = None,
                    transport: Transport | None = None,
                    prompt: str | None = None,
                    connect: bool = True,
                ) -> Session:
                    """Create and optionally connect a new session.
            
                    Args:
                        session_id: Explicit ID, or auto-generated UUID if None.
                        options: Session-specific options.
                        transport: Optional custom transport.
                        prompt: If provided, sent as the initial prompt on connect.
                        connect: If True (default), connect immediately.
            
                    Raises:
                        ValueError: If session_id already exists.
                        RuntimeError: If max_concurrent_sessions would be exceeded.
                    """
                    sid = session_id or uuid.uuid4().hex
                    if sid in self._sessions:
                        msg = f"Session {sid!r} already exists"
                        raise ValueError(msg)
            
                    if self._max_concurrent_sessions is not None:
                        active_count = sum(
                            1
                            for s in self._sessions.values()
                            if s.state in ("idle", "responding", "connecting")
                        )
                        if active_count >= self._max_concurrent_sessions:
                            msg = f"Maximum concurrent sessions ({self._max_concurrent_sessions}) reached"
                            raise RuntimeError(msg)
            
                    client = ClaudeSDKClient(options=options, transport=transport)
                    session = Session(sid, client)
                    self._sessions[sid] = session
            
                    if connect:
                        session._state = "connecting"
                        try:
                            await client.connect()
                            if prompt:
                                await client.query(prompt)
                            session._state = "idle"
                            session._last_activity = datetime.now(UTC)
                        except Exception:
                            session._state = "error"
                            raise
            
                    return session
            
                async def resume_session(
                    self,
                    session_id: str,
                    *,
                    options: ClaudeAgentOptions | None = None,
                    transport: Transport | None = None,
                ) -> Session:
                    """Resume a previously persisted session by ID.
            
                    Sets ``session`` to a :class:`ResumeSession` config on the options,
                    then connects.
            
                    Args:
                        session_id: The session ID to resume.
                        options: Session-specific options (``session`` is set automatically).
                        transport: Optional custom transport.
            
                    Raises:
                        ValueError: If session_id already exists in this manager.
                    """
                    from clawd_code_sdk.models.options import ResumeSession
            
                    base = options or Opts()
                    merged = replace(base, session=ResumeSession(session_id=session_id))
                    return await self.create_session(
                        session_id=session_id,
                        options=merged,
                        transport=transport,
                    )
            
                # ── Session access ───────────────────────────────────────────
            
                def get_session(self, session_id: str) -> Session:
                    """Get a session by ID.
            
                    Raises:
                        KeyError: If session_id not found.
                    """
                    try:
                        return self._sessions[session_id]
                    except KeyError:
                        msg = f"Session {session_id!r} not found"
                        raise KeyError(msg) from None
            
                def __getitem__(self, session_id: str) -> Session:
                    """Alias for ``get_session()``."""
                    return self.get_session(session_id)
            
                def __contains__(self, session_id: str) -> bool:
                    return session_id in self._sessions
            
                def __len__(self) -> int:
                    return len(self._sessions)
            
                def __iter__(self) -> Iterator[str]:
                    """Iterate over session IDs."""
                    return iter(self._sessions)
            
                @property
                def sessions(self) -> dict[str, Session]:
                    """All sessions (any state). Returns a copy."""
                    return dict(self._sessions)
            
                @property
                def active_sessions(self) -> dict[str, Session]:
                    """Sessions in IDLE or RESPONDING state."""
                    return {sid: s for sid, s in self._sessions.items() if s.state in ("idle", "responding")}
            
                # ── Cleanup ──────────────────────────────────────────────────
            
                async def close_session(self, session_id: str) -> None:
                    """Close and remove a specific session.
            
                    Raises:
                        KeyError: If session_id not found.
                    """
                    session = self.get_session(session_id)
                    await session.close()
                    del self._sessions[session_id]
            
                async def close_all(self) -> None:
                    """Close all sessions, concurrently. Errors during individual closes are suppressed."""
                    sessions = list(self._sessions.values())
                    await asyncio.gather(*(s.close() for s in sessions), return_exceptions=True)
                    self._sessions.clear()
            
                # ── Aggregate stats ──────────────────────────────────────────
            
                @property
                def total_cost_usd(self) -> float:
                    """Sum of costs across all sessions."""
                    return sum(s.total_cost_usd for s in self._sessions.values())
            
                def snapshots(self) -> dict[str, SessionSnapshot]:
                    """Snapshots of all sessions."""
                    return {sid: s.snapshot for sid, s in self._sessions.items()}
            
                # ── Context manager ──────────────────────────────────────────
            
                async def __aenter__(self) -> Self:
                    return self
            
                async def __aexit__(self, *args: object) -> None:
                    await self.close_all()
            

            active_sessions property

            active_sessions: dict[str, Session]
            

            Sessions in IDLE or RESPONDING state.

            sessions property

            sessions: dict[str, Session]
            

            All sessions (any state). Returns a copy.

            total_cost_usd property

            total_cost_usd: float
            

            Sum of costs across all sessions.

            __getitem__

            __getitem__(session_id: str) -> Session
            

            Alias for get_session().

            Source code in src/clawd_code_sdk/session.py
            def __getitem__(self, session_id: str) -> Session:
                """Alias for ``get_session()``."""
                return self.get_session(session_id)
            

            __init__

            __init__(*, max_concurrent_sessions: int | None = None) -> None
            

            Initialize the session manager.

            Parameters:

            Name Type Description Default
            max_concurrent_sessions int | None

            Optional cap on simultaneous connected sessions. create_session raises if exceeded.

            None
            Source code in src/clawd_code_sdk/session.py
            def __init__(self, *, max_concurrent_sessions: int | None = None) -> None:
                """Initialize the session manager.
            
                Args:
                    max_concurrent_sessions: Optional cap on simultaneous connected
                        sessions. ``create_session`` raises if exceeded.
                """
                self._sessions: dict[str, Session] = {}
                self._max_concurrent_sessions = max_concurrent_sessions
            

            __iter__

            __iter__() -> Iterator[str]
            

            Iterate over session IDs.

            Source code in src/clawd_code_sdk/session.py
            def __iter__(self) -> Iterator[str]:
                """Iterate over session IDs."""
                return iter(self._sessions)
            

            close_all async

            close_all() -> None
            

            Close all sessions, concurrently. Errors during individual closes are suppressed.

            Source code in src/clawd_code_sdk/session.py
            async def close_all(self) -> None:
                """Close all sessions, concurrently. Errors during individual closes are suppressed."""
                sessions = list(self._sessions.values())
                await asyncio.gather(*(s.close() for s in sessions), return_exceptions=True)
                self._sessions.clear()
            

            close_session async

            close_session(session_id: str) -> None
            

            Close and remove a specific session.

            Raises:

            Type Description
            KeyError

            If session_id not found.

            Source code in src/clawd_code_sdk/session.py
            async def close_session(self, session_id: str) -> None:
                """Close and remove a specific session.
            
                Raises:
                    KeyError: If session_id not found.
                """
                session = self.get_session(session_id)
                await session.close()
                del self._sessions[session_id]
            

            create_session async

            create_session(
                session_id: str | None = None,
                *,
                options: ClaudeAgentOptions | None = None,
                transport: Transport | None = None,
                prompt: str | None = None,
                connect: bool = True,
            ) -> Session
            

            Create and optionally connect a new session.

            Parameters:

            Name Type Description Default
            session_id str | None

            Explicit ID, or auto-generated UUID if None.

            None
            options ClaudeAgentOptions | None

            Session-specific options.

            None
            transport Transport | None

            Optional custom transport.

            None
            prompt str | None

            If provided, sent as the initial prompt on connect.

            None
            connect bool

            If True (default), connect immediately.

            True

            Raises:

            Type Description
            ValueError

            If session_id already exists.

            RuntimeError

            If max_concurrent_sessions would be exceeded.

            Source code in src/clawd_code_sdk/session.py
            async def create_session(
                self,
                session_id: str | None = None,
                *,
                options: ClaudeAgentOptions | None = None,
                transport: Transport | None = None,
                prompt: str | None = None,
                connect: bool = True,
            ) -> Session:
                """Create and optionally connect a new session.
            
                Args:
                    session_id: Explicit ID, or auto-generated UUID if None.
                    options: Session-specific options.
                    transport: Optional custom transport.
                    prompt: If provided, sent as the initial prompt on connect.
                    connect: If True (default), connect immediately.
            
                Raises:
                    ValueError: If session_id already exists.
                    RuntimeError: If max_concurrent_sessions would be exceeded.
                """
                sid = session_id or uuid.uuid4().hex
                if sid in self._sessions:
                    msg = f"Session {sid!r} already exists"
                    raise ValueError(msg)
            
                if self._max_concurrent_sessions is not None:
                    active_count = sum(
                        1
                        for s in self._sessions.values()
                        if s.state in ("idle", "responding", "connecting")
                    )
                    if active_count >= self._max_concurrent_sessions:
                        msg = f"Maximum concurrent sessions ({self._max_concurrent_sessions}) reached"
                        raise RuntimeError(msg)
            
                client = ClaudeSDKClient(options=options, transport=transport)
                session = Session(sid, client)
                self._sessions[sid] = session
            
                if connect:
                    session._state = "connecting"
                    try:
                        await client.connect()
                        if prompt:
                            await client.query(prompt)
                        session._state = "idle"
                        session._last_activity = datetime.now(UTC)
                    except Exception:
                        session._state = "error"
                        raise
            
                return session
            

            get_session

            get_session(session_id: str) -> Session
            

            Get a session by ID.

            Raises:

            Type Description
            KeyError

            If session_id not found.

            Source code in src/clawd_code_sdk/session.py
            def get_session(self, session_id: str) -> Session:
                """Get a session by ID.
            
                Raises:
                    KeyError: If session_id not found.
                """
                try:
                    return self._sessions[session_id]
                except KeyError:
                    msg = f"Session {session_id!r} not found"
                    raise KeyError(msg) from None
            

            resume_session async

            resume_session(
                session_id: str,
                *,
                options: ClaudeAgentOptions | None = None,
                transport: Transport | None = None,
            ) -> Session
            

            Resume a previously persisted session by ID.

            Sets session to a :class:ResumeSession config on the options, then connects.

            Parameters:

            Name Type Description Default
            session_id str

            The session ID to resume.

            required
            options ClaudeAgentOptions | None

            Session-specific options (session is set automatically).

            None
            transport Transport | None

            Optional custom transport.

            None

            Raises:

            Type Description
            ValueError

            If session_id already exists in this manager.

            Source code in src/clawd_code_sdk/session.py
            async def resume_session(
                self,
                session_id: str,
                *,
                options: ClaudeAgentOptions | None = None,
                transport: Transport | None = None,
            ) -> Session:
                """Resume a previously persisted session by ID.
            
                Sets ``session`` to a :class:`ResumeSession` config on the options,
                then connects.
            
                Args:
                    session_id: The session ID to resume.
                    options: Session-specific options (``session`` is set automatically).
                    transport: Optional custom transport.
            
                Raises:
                    ValueError: If session_id already exists in this manager.
                """
                from clawd_code_sdk.models.options import ResumeSession
            
                base = options or Opts()
                merged = replace(base, session=ResumeSession(session_id=session_id))
                return await self.create_session(
                    session_id=session_id,
                    options=merged,
                    transport=transport,
                )
            

            snapshots

            snapshots() -> dict[str, SessionSnapshot]
            

            Snapshots of all sessions.

            Source code in src/clawd_code_sdk/session.py
            def snapshots(self) -> dict[str, SessionSnapshot]:
                """Snapshots of all sessions."""
                return {sid: s.snapshot for sid, s in self._sessions.items()}
            

            SessionSnapshot dataclass

            Read-only snapshot of session metadata at a point in time.

            Source code in src/clawd_code_sdk/session.py
            @dataclass(frozen=True)
            class SessionSnapshot:
                """Read-only snapshot of session metadata at a point in time."""
            
                session_id: str
                state: SessionState
                model: str | None
                cwd: str | None
                created_at: datetime
                last_activity: datetime
                turn_count: int
                total_cost_usd: float
            

            ToolCallSummary dataclass

            Summary of a single tool invocation within a conversation turn.

            Source code in src/clawd_code_sdk/session.py
            @dataclass(frozen=True)
            class ToolCallSummary:
                """Summary of a single tool invocation within a conversation turn."""
            
                tool_use_id: str
                tool_name: str
                input: ToolInput | dict[str, Any]