Skip to main content

Session lifecycle events

Session lifecycle events notify you about session creation, deletion, updates, and foreground/background state changes (in TUI + server mode).

Event types

The SessionLifecycleEventType enum defines five event types:

Subscribe to events

Use onLifecycle() 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.foreground and session.background events occur only in TUI + server mode.
  • On session delete (session.deleted), metadata is null.
  • onLifecycle() returns a callback for unsubscribing.
For the latest updates, see the GitHub repository.
Last modified on April 22, 2026