How github/copilot-sdk works
1. Repository purpose
This is a multi-language SDK monorepo for embedding GitHub Copilot CLI’s agent runtime into applications. The primary architectural boundary is between user applications and the Copilot CLI server process, with the SDKs acting as client-side orchestration layers.
2. Top-level runtime model
The core data flow is:
application code → language SDK client → JSON-RPC transport → Copilot CLI in server mode → model/tool execution → streamed events and results back to the app.
The SDKs can either launch/manage the CLI process themselves or connect to an externally running CLI server.
3. Language-specific SDK packages
The repo contains first-party SDK implementations for Node.js/TypeScript, Python, Go, and .NET. Each language folder has the same general shape: a public client/session API, generated protocol bindings, telemetry helpers, tests, and small samples. The Java SDK is not in this repo; it lives in a separate repository.
4. Shared protocol layer
A major architectural invariant is that all SDKs speak the same Copilot CLI protocol. Generated RPC and session-event types appear in each language (generated/ in TS/Python, Generated/ in .NET, rpc/ plus generated_session_events.go in Go). The file sdk-protocol-version.json and per-language protocol version files keep the SDKs aligned to the CLI protocol.
5. Core SDK responsibilities
Across languages, the SDKs expose similar concepts: Client, Session, typed request/response models, permissions handling, telemetry, and event streaming. These layers translate language-native APIs into protocol messages, and they shield consumers from the raw JSON-RPC wire format.
6. Session-centric architecture
Sessions are the main unit of state. They handle conversation history, persistence/resume, multi-turn interactions, compaction, streaming deltas, and lifecycle events. Tests and snapshots show the session boundary is where most behavior accumulates: create, resume, list, delete, emit events, and recover state across runs.
7. Tooling, hooks, and extensibility surface
The repository’s feature set is centered on Copilot’s agentic extensions: built-in tools, custom tools, MCP servers, custom agents, skills, hooks, permissions, and prompt/system-message transforms. These are all treated as configuration and event-driven extensions to the session runtime rather than separate subsystems.
8. CLI process and transport boundary
The SDKs depend on a real Copilot CLI binary and communicate with it over JSON-RPC. Transport scenarios and tests cover stdio, TCP, reconnect behavior, and process lifecycle concerns. This makes the CLI a hard external runtime dependency, not just an implementation detail.
9. Telemetry and observability
Telemetry is a cross-cutting concern in every SDK. Each language has a telemetry module, and the docs include an OpenTelemetry guide. Telemetry is used to preserve tool execution metadata, event fidelity, and session behavior without forcing callers to parse raw protocol details.
10. Code generation pipeline
Shared protocol definitions are generated into each language package using scripts under scripts/codegen/. There are separate generators for TypeScript, Python, Go, and C#. This means the SDKs are deliberately kept structurally similar and are updated in lockstep when the protocol changes.
11. Test strategy
The repo has a layered test model:
- language-level unit tests for serialization, permissions, telemetry, and protocol helpers
- end-to-end tests per SDK
- snapshot-based assertions under test/snapshots/
- cross-language scenario tests under test/scenarios/
This is a strong indicator that protocol fidelity and behavior parity are central architectural goals.
12. Scenario harnesses and compatibility validation
The test/scenarios/ tree contains many real-world integration cases, each replicated across C#, Go, Python, and TypeScript. These scenarios verify auth modes, bundling, callbacks, session behavior, tool usage, transport, and prompt handling. The harnesses under test/harness/ and language-specific e2e/testharness/ directories support those integration runs.
13. Docs and repo automation
Documentation is a first-class subsystem: setup, auth, hooks, MCP, observability, troubleshooting, and feature docs live under docs/. GitHub Actions workflows cover SDK tests, docs validation, code generation checks, publishing, changelog handling, and issue/workflow automation. This repo is therefore both an SDK source tree and a release/verification system.
14. Packaging and samples
Each SDK includes samples and language-native packaging metadata: npm/package-lock, Python pyproject, Go modules, and .NET solution/project files. These are not separate products; they are the distribution boundary for the same underlying CLI-backed agent runtime.
15. What to show in an architecture diagram
The diagram should emphasize one central external dependency: Copilot CLI server mode. Around it, show four equivalent SDK client implementations, each with:
application-facing API
protocol serialization/deserialization
session state and event streaming
tool/permission/hook extensibility
telemetry
process/transport management
Then connect those to docs, codegen, and the shared test/scenario harnesses as supporting subsystems.
Main entry points: nodejs/src TypeScript SDK · copilot Python SDK · go Go SDK · dotnet/src .NET SDK
Components 22
SDKs
Language-specific client libraries that wrap the Copilot CLI protocol.
- TypeScript SDK · Node.js/TypeScript client, session, generated protocol bindings, telemetry, and extension surface.
nodejs/src - Python SDK · Python client, session, generated protocol bindings, telemetry, and tool helpers.
python/copilot - Go SDK · Go client, session, RPC bindings, telemetry, and embedded CLI/process support.
go - .NET SDK · C# client, session, generated protocol bindings, telemetry, and permissions helpers.
dotnet/src - TS session · Session-centric state, streaming, resume, compaction, and lifecycle handling.
nodejs/src/session.ts - Py session · Session state and event-stream orchestration for Python consumers.
python/copilot/session.py - Go session · Session state and event-stream orchestration for Go consumers.
go/session.go - .NET session · Session state and event-stream orchestration for .NET consumers.
dotnet/src/Session.cs - TS transport · Launches or attaches to the CLI process and handles JSON-RPC transport concerns.
nodejs/src/client.ts - Py transport · Launches or attaches to the CLI process and handles JSON-RPC transport concerns.
python/copilot/_jsonrpc.py - Go transport · Launches or attaches to the CLI process and handles JSON-RPC transport concerns.
go/embeddedcli/installer.go - .NET transport · Launches or attaches to the CLI process and handles JSON-RPC transport concerns.
dotnet/src/Client.cs - Extensions · Tools, permissions, hooks, MCP servers, agents, skills, and prompt transforms.
nodejs/src/extension.ts
Shared Infra
Cross-language protocol, code generation, docs, and repo-level tooling.
- JSON-RPC · Transport boundary used by all SDKs to talk to the CLI server process.
go/internal/jsonrpc2/jsonrpc2.go - Protocol version · Shared protocol version source used to keep SDKs aligned with the CLI.
sdk-protocol-version.json - Codegen · Generates language-specific RPC and session-event bindings from shared protocol definitions.
scripts/codegen - Docs · Setup, auth, hooks, MCP, observability, and troubleshooting guidance.
docs - Telemetry · Language-specific telemetry surfaces that preserve event and tool metadata.
nodejs/src/telemetry.ts
Verification
Tests, scenarios, and harnesses used to validate protocol fidelity and behavior parity.
Other components
- App code · Application code embeds the SDK and consumes session/event APIs.
- Copilot CLI · Server-mode Copilot CLI process that executes the agent runtime and tool/model work.
Connections 40
- App code → TypeScript SDK: uses · Applications call the SDK-facing API.
- App code → Python SDK: uses · Applications call the SDK-facing API.
- App code → Go SDK: uses · Applications call the SDK-facing API.
- App code → .NET SDK: uses · Applications call the SDK-facing API.
- TypeScript SDK → TS session: owns · The SDK exposes session-centric APIs and stateful conversation management.
- Python SDK → Py session: owns · The SDK exposes session-centric APIs and stateful conversation management.
- Go SDK → Go session: owns · The SDK exposes session-centric APIs and stateful conversation management.
- .NET SDK → .NET session: owns · The SDK exposes session-centric APIs and stateful conversation management.
- TypeScript SDK → TS transport: connects · The SDK launches or attaches to the CLI and speaks JSON-RPC.
- Python SDK → Py transport: connects · The SDK launches or attaches to the CLI and speaks JSON-RPC.
- Go SDK → Go transport: connects · The SDK launches or attaches to the CLI and speaks JSON-RPC.
- .NET SDK → .NET transport: connects · The SDK launches or attaches to the CLI and speaks JSON-RPC.
- TS transport → JSON-RPC: speaks · Language transport implementations normalize the wire protocol.
- Py transport → JSON-RPC: speaks · Language transport implementations normalize the wire protocol.
- Go transport → JSON-RPC: speaks · Language transport implementations normalize the wire protocol.
- .NET transport → JSON-RPC: speaks · Language transport implementations normalize the wire protocol.
- JSON-RPC → Copilot CLI: reaches · JSON-RPC carries requests and streamed events to the CLI server process.
- Copilot CLI → Telemetry: emits · Execution metadata and event fidelity are preserved through telemetry surfaces.
- TypeScript SDK → Extensions: exposes · TypeScript exposes tools, hooks, permissions, agents, skills, and transforms.
- Python SDK → Extensions: exposes · Python exposes tools, hooks, permissions, agents, skills, and transforms.
- Go SDK → Extensions: exposes · Go exposes tools, hooks, permissions, agents, skills, and transforms.
- .NET SDK → Extensions: exposes · .NET exposes tools, hooks, permissions, agents, skills, and transforms.
- Codegen → TypeScript SDK: generates · Shared protocol definitions are generated into the TypeScript package.
- Codegen → Python SDK: generates · Shared protocol definitions are generated into the Python package.
- Codegen → Go SDK: generates · Shared protocol definitions are generated into the Go package.
- Codegen → .NET SDK: generates · Shared protocol definitions are generated into the .NET package.
- Protocol version → Codegen: aligns · Version files keep generated SDKs in lockstep with the CLI protocol.
- Docs → TypeScript SDK: documents · Docs explain setup, features, and usage for SDK consumers.
- Docs → Python SDK: documents · Docs explain setup, features, and usage for SDK consumers.
- Docs → Go SDK: documents · Docs explain setup, features, and usage for SDK consumers.
- Docs → .NET SDK: documents · Docs explain setup, features, and usage for SDK consumers.
- Scenarios → TypeScript SDK: validates · Cross-language scenarios exercise TypeScript behavior.
- Scenarios → Python SDK: validates · Cross-language scenarios exercise Python behavior.
- Scenarios → Go SDK: validates · Cross-language scenarios exercise Go behavior.
- Scenarios → .NET SDK: validates · Cross-language scenarios exercise .NET behavior.
- Harnesses → Scenarios: supports · Shared harnesses provide proxies, servers, and replay support for scenarios.
- Telemetry → TypeScript SDK: instrumented in · Telemetry is part of the TypeScript SDK surface.
- Telemetry → Python SDK: instrumented in · Telemetry is part of the Python SDK surface.
- Telemetry → Go SDK: instrumented in · Telemetry is part of the Go SDK surface.
- Telemetry → .NET SDK: instrumented in · Telemetry is part of the .NET SDK surface.