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 directorygitRoot(?string): Git repository root directory (nulloutside a Git repository)repository(?string): GitHub repository inowner/repoformat (for exampleinvokable/laravel-copilot-sdk)branch(?string): Current Git branch name
Example
SessionListFilter
UseSessionListFilter to fetch only sessions from a specific working directory or repository.
Properties
cwd(?string): Exact-match filter by working directorygitRoot(?string): Filter by Git root directoryrepository(?string): Filter by repository inowner/repoformatbranch(?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 a context property.
New property
context(?SessionContext): Working directory and Git metadata for the session
Example
Practical examples
Get sessions for a specific project
Manage sessions on feature branches
Organize sessions by working directory
Notes
contextincludes Git fields (gitRoot,repository,branch) only if the session was created inside a Git repository.- The
contextfield is available with Copilot CLI v0.0.409 or later. Older versions returnnull. - Filtering is exact match only. Partial match and wildcards are not supported.
- All
SessionListFilterfields are optional. If you pass no filters, all sessions are returned.
For the latest updates, see the GitHub repository.