Session lifecycle events
Session lifecycle events notify you about session creation, deletion, updates, and foreground/background state changes (in TUI + server mode).Event types
TheSessionLifecycleEventType enum defines five event types:
Subscribe to events
UseonLifecycle() to subscribe to session lifecycle events:
SessionLifecycleEvent
SessionLifecycleEvent is a readonly class with lifecycle event details:
SessionLifecycleEventMetadata
This class includes session metadata (not included for delete events):Foreground session management
When connected to a server running in TUI + server mode (--ui-server), you can manage the foreground session.
Get current foreground session
Set foreground session
ForegroundSessionInfo
ForegroundSessionInfo is a readonly class with foreground session details:
TCP mode usage
Run Copilot CLI in TUI + server mode, then connect from the SDK to use lifecycle events:Notes
session.foregroundandsession.backgroundevents occur only in TUI + server mode.- On session delete (
session.deleted),metadataisnull. onLifecycle()returns a callback for unsubscribing.
For the latest updates, see the GitHub repository.