Skip to main content

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 the SessionLifecycleEventType enum.

Subscribing to events

Use the onLifecycle() 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.foreground and session.background events fire only in TUI + server mode.
  • On session deletion (session.deleted), the metadata property is null.
  • onLifecycle() returns an unsubscribe callback.
  • This is a separate feature from onSessionStart and onSessionEnd in Session hooks.
For the latest updates, see the GitHub repository.
Last modified on August 2, 2026