Skip to main content

Session context and filtering

Since GitHub Copilot SDK v0.1.24, sessions include context with working directory and Git metadata. You can also filter session lists by this context.

SessionContext

SessionContext stores working directory and Git repository information from when a session was created.

Properties

  • cwd (string): Absolute path of the working directory
  • gitRoot (?string): Git repository root directory (null outside a Git repository)
  • repository (?string): GitHub repository in owner/repo format (for example invokable/laravel-copilot-sdk)
  • branch (?string): Current Git branch name

Example

SessionListFilter

Use SessionListFilter to fetch only sessions from a specific working directory or repository.

Properties

  • cwd (?string): Exact-match filter by working directory
  • gitRoot (?string): Filter by Git root directory
  • repository (?string): Filter by repository in owner/repo format
  • branch (?string): Filter by branch name

Examples

Pass filters as an array

Use the SessionListFilter class

session.context_changed event

When the working directory changes during a session, a session.context_changed event is emitted.

Event type

Event data

The event data includes updated context details:

SessionMetadata

SessionMetadata now includes the context, clientName, and lastClientName properties.

New properties

  • context (?SessionContext): Working directory and Git metadata for the session
  • clientName (?string): Name of the client that created the session (for example github/cli), or null when unknown
  • lastClientName (?string): Name of the client that last ran the session. This is the creating client or a client that resumed and ran it. Resuming only to view the session does not change it. It is null for older sessions where the value is unknown

Example

Practical examples

Get sessions for a specific project

Manage sessions on feature branches

Organize sessions by working directory

Notes

  • context includes Git fields (gitRoot, repository, branch) only if the session was created inside a Git repository.
  • The context field is available with Copilot CLI v0.0.409 or later. Older versions return null.
  • Filtering is exact match only. Partial match and wildcards are not supported.
  • All SessionListFilter fields are optional. If you pass no filters, all sessions are returned.
For the latest updates, see the GitHub repository.
Last modified on November 9, 2026