Session lifecycle events
Session lifecycle events notify you of session creation, deletion, updates, and foreground/background state changes (in TUI + server mode).Event types
Five event types are defined by theSessionLifecycleEventType enum.
Subscribing to events
Use theonLifecycle() method to subscribe to session lifecycle events.
SessionLifecycleEvent
SessionLifecycleEvent is a readonly class containing the details of a lifecycle event.
SessionLifecycleEventMetadata
A class containing session metadata (not included on delete events).Foreground session management
When connected to a server running in TUI + server mode (--ui-server), you can manage the foreground session.
Get the current foreground session
Set the foreground session
ForegroundSessionInfo
A readonly class that contains information about the foreground session.Using it in TCP mode
Launch the Copilot CLI in TUI + server mode and connect from the SDK to make use of lifecycle events.Notes
session.foregroundandsession.backgroundevents fire only in TUI + server mode.- On session deletion (
session.deleted), themetadataproperty isnull. onLifecycle()returns an unsubscribe callback.- This is a separate feature from
onSessionStartandonSessionEndin Session hooks.
For the latest updates, see the GitHub repository.