Skip to main content

Module 20: Session Management

List, resume, and close sessions: the full session lifecycle from both sides.

What You’ll Learn

  • Enumerating sessions with session/list, optionally filtered by working directory
  • Reconnecting to a session with session/resume, without history replay
  • Closing a session with session/close to free its resources
  • The difference between resumeSession and loadSession (Module 09)

The Code

Client: list, resume, close

Agent: implement the lifecycle handlers

The agent keeps its own session state. Each lifecycle method has its own handler:

Resume vs Load

session/list, session/resume, and session/close were added in SDK 0.12.0.

Source Code

View on GitHub

Running the Example

The demo launches the agent, creates three sessions, lists them with and without a cwd filter, resumes one and keeps talking to it, then closes all three and lists again to show they are gone. No API key required.

Next Module

Module 21: Async Client — use the reactive, non-blocking client API.