# github/copilot-sdk-java architecture

> Architecture diagram of the GitHub repository github/copilot-sdk-java, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/github/copilot-sdk-java
- Repository: https://github.com/github/copilot-sdk-java

## Overview

1. **What this repository is**
   - This is a Java 17+ SDK for controlling the GitHub Copilot CLI programmatically.
   - The runtime boundary is not a hosted web service; the SDK is a local client library that launches or connects to the Copilot CLI process and communicates with it over JSON-RPC.

2. **Primary runtime layers**
   - The top-level handwritten API lives in `src/main/java/com/github/copilot`.
   - The lower-level data model and transport-facing types live in `src/main/java/com/github/copilot/rpc`.
   - A large generated surface in `src/generated/java/com/github/copilot/generated` and `src/generated/java/com/github/copilot/generated/rpc` mirrors the CLI protocol, events, requests, and responses.

3. **Client/session boundary**
   - `CopilotClient` is the main entry point for applications.
   - It manages process/session startup via `CliServerManager`, connection state, and lifecycle coordination.
   - `CopilotSession` is the primary unit of work once connected: it represents an active Copilot conversation/session and exposes send, resume, event subscription, and session-scoped operations.

4. **Transport and protocol handling**
   - `JsonRpcClient`, `JsonRpcRequest`, `JsonRpcResponse`, and `JsonRpcException` implement the messaging layer over the CLI boundary.
   - `RpcHandlerDispatcher` routes incoming RPC callbacks/events to the appropriate handlers.
   - `SessionRequestBuilder` assembles request payloads for session operations.
   - This means the architecture separates transport concerns from Copilot semantics rather than exposing raw CLI I/O to consumers.

5. **Event-driven core**
   - The SDK is strongly event-driven: session activity is surfaced through generated event classes such as assistant messages, tool execution events, usage updates, warnings, and shutdown notifications.
   - `LifecycleEventManager` and related classes coordinate session lifecycle events and dispatch them to consumers.
   - Tests like `SessionEventHandlingTest`, `StreamingFidelityTest`, and `EventFidelityTest` suggest event ordering and payload accuracy are important architectural guarantees.

6. **Domain model and configuration**
   - The handwritten `com.github.copilot.rpc` package contains the SDK’s public domain objects and configuration types: session config, message options, model info, permissions, telemetry, attachments, agents, tools, hooks, and remote-session options.
   - These types are the stable API boundary for Java users, while the generated models track the underlying Copilot protocol more directly.
   - The distinction between handwritten API objects and generated wire types is a major architectural seam.

7. **Hooks, permissions, and user interaction**
   - The SDK supports several callback boundaries where application code can intervene: permission requests, user input requests, tool execution hooks, pre/post tool use hooks, MCP tool call hooks, elicitation, exit-plan mode, session start/end hooks, and user-prompt submission hooks.
   - These callbacks are modeled as explicit handlers and invocation/result objects in `com.github.copilot.rpc`.
   - Architecturally, this is where the SDK becomes an orchestration layer for agentic workflows rather than a simple request/response client.

8. **Tools, MCP, skills, and agents**
   - The SDK exposes higher-level integration points for tools, built-in tools, custom agents, skills, and Model Context Protocol (MCP) servers.
   - Generated RPC APIs cover discovery, enable/disable, execute, reload, list, and status operations for these subsystems.
   - This indicates the Copilot CLI is treated as a local agent runtime that can be extended through plugin/tool ecosystems, with the SDK acting as the control plane.

9. **Sessions as managed state**
   - Session-related APIs cover creation, resume, fork, close, list, metadata, compaction, history truncation, workspace file operations, and foreground/background handling.
   - The SDK therefore manages more than chat messages: it also models persistent session state, workspace context, and session scheduling/queueing.
   - Several response types show the SDK can interrogate and mutate session metadata and execution state directly.

10. **Generated protocol surface**
   - The generated classes are extensive and intentionally verbose because they mirror the underlying CLI schema and RPC contract.
   - They cover event types, enums, request/response records, and per-area API namespaces such as sessions, tools, MCP, permissions, workspace, models, auth, telemetry, and usage.
   - The architecture uses generation to keep the Java client aligned with the reference implementation and reduce hand-maintained protocol drift.

11. **Build, codegen, and release pipeline**
   - `pom.xml` plus the Maven Wrapper define the Java build.
   - `scripts/codegen` uses TypeScript/Node tooling to generate protocol bindings, showing that code generation is a first-class part of the repo.
   - GitHub Actions handles build/test, site deployment, Maven publishing, snapshot publishing, release notes/changelog updates, and syncing with the reference implementation.
   - The CI/CD surface is tightly coupled to protocol synchronization and documentation publication.

12. **Documentation and site generation**
   - `src/site` contains the Maven site content and documentation examples, including getting started, advanced usage, hooks, MCP, and cookbooks.
   - `docs/WORKFLOWS.md` and ADRs document architectural decisions and release/sync mechanics.
   - This repo ships both a library and a documentation site, so diagramming should include the docs build as a separate output from the runtime SDK.

13. **Testing strategy**
   - Tests are broad and layered: unit tests for wrappers and models, fidelity tests for event and stream behavior, end-to-end tests against the official Copilot test harness, and coverage tests for generated code.
   - The test suite validates not only business logic but also protocol compatibility, JSON serialization/deserialization, and module/package boundaries.
   - That suggests the main engineering risk here is keeping the Java façade synchronized with a fast-moving CLI protocol.

14. **Key architectural takeaway**
   - The repo is best understood as a three-part system: a public Java SDK surface, a generated protocol mirror, and a JSON-RPC bridge to the local Copilot CLI.
   - Around that core are extensibility boundaries for hooks, permissions, tools, MCP, and agent/session lifecycle management, plus a CI/codegen pipeline that keeps the SDK aligned with the upstream reference implementation.

Main entry points: [`src/main/java/com/github/copilot/rpc/package-info.java`](https://github.com/github/copilot-sdk-java/blob/main/src/main/java/com/github/copilot/rpc/package-info.java) (RPC domain), [`src/generated/java/com/github/copilot/generated/SessionEvent.java`](https://github.com/github/copilot-sdk-java/blob/main/src/generated/java/com/github/copilot/generated/SessionEvent.java) (Generated events), [`src/main/java/com/github/copilot/CopilotSession.java`](https://github.com/github/copilot-sdk-java/blob/main/src/main/java/com/github/copilot/CopilotSession.java) (CopilotSession), [`src/main/java/com/github/copilot/CopilotClient.java`](https://github.com/github/copilot-sdk-java/blob/main/src/main/java/com/github/copilot/CopilotClient.java) (CopilotClient)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime SDK"]
  node_copilot_client["CopilotClient<br/>entrypoint<br/>[CopilotClient.java]"]
  node_copilot_session["CopilotSession<br/>session api"]
  node_cli_server_manager["CLI server<br/>process manager"]
  node_json_rpc_client["JSON-RPC<br/>transport<br/>[JsonRpcClient.java]"]
  node_rpc_dispatcher["Dispatcher<br/>callback router"]
  node_lifecycle_manager(("Lifecycle<br/>event manager"))
  node_request_builder["Request builder<br/>payload builder"]
  node_rpc_domain["RPC domain<br/>public model layer<br/>[package-info.java]"]
  node_session_config["Session config<br/>configuration<br/>[SessionConfig.java]"]
  node_hook_boundaries{{"Hooks<br/>callbacks<br/>[SessionHooks.java]"}}
  node_tool_agent_boundary{{"Tools & agents<br/>extension layer<br/>[ToolSet.java]"}}
end

subgraph group_generated["Generated Protocol"]
  node_generated_events["Generated events<br/>protocol mirror<br/>[SessionEvent.java]"]
  node_generated_rpc["Generated RPC<br/>protocol mirror<br/>[SessionRpc.java]"]
end

subgraph group_delivery["Delivery"]
  node_codegen["Codegen<br/>generator<br/>[java.ts]"]
  node_maven_build["Maven build<br/>[pom.xml]"]
  node_ci_release["CI/CD<br/>automation<br/>[build-test.yml]"]
  node_site_docs["Docs site<br/>documentation<br/>[index.md]"]
end

subgraph group_tests["Tests"]
  node_test_suite["Test suite<br/>validation"]
  node_fidelity_tests["Fidelity tests<br/>compatibility tests"]
end

node_copilot_client -->|"starts/connects"| node_cli_server_manager
node_copilot_client -->|"uses transport"| node_json_rpc_client
node_copilot_client -->|"creates sessions"| node_copilot_session
node_copilot_session -->|"builds requests"| node_request_builder
node_copilot_session -->|"handles callbacks"| node_rpc_dispatcher
node_copilot_session -->|"emits lifecycle"| node_lifecycle_manager
node_json_rpc_client -->|"speaks protocol"| node_generated_rpc
node_rpc_dispatcher -->|"dispatches events"| node_generated_events
node_lifecycle_manager -->|"publishes events"| node_generated_events
node_request_builder -->|"uses domain types"| node_rpc_domain
node_rpc_domain -->|"includes config"| node_session_config
node_rpc_domain -->|"defines callbacks"| node_hook_boundaries
node_rpc_domain -->|"defines extensions"| node_tool_agent_boundary
node_generated_rpc -->|"mirrors schema"| node_generated_events
node_codegen -->|"produces"| node_generated_rpc
node_codegen -->|"produces"| node_generated_events
node_maven_build -->|"invokes"| node_codegen
node_ci_release -->|"runs"| node_maven_build
node_ci_release -->|"syncs"| node_codegen
node_site_docs -->|"documents"| node_rpc_domain
node_test_suite -->|"verifies"| node_copilot_client
node_test_suite -->|"verifies"| node_rpc_domain
node_fidelity_tests -->|"checks"| node_generated_events
node_fidelity_tests -->|"checks"| node_generated_rpc

click node_copilot_client "https://github.com/github/copilot-sdk-java/blob/main/src/main/java/com/github/copilot/CopilotClient.java"
click node_copilot_session "https://github.com/github/copilot-sdk-java/blob/main/src/main/java/com/github/copilot/CopilotSession.java"
click node_cli_server_manager "https://github.com/github/copilot-sdk-java/blob/main/src/main/java/com/github/copilot/CliServerManager.java"
click node_json_rpc_client "https://github.com/github/copilot-sdk-java/blob/main/src/main/java/com/github/copilot/JsonRpcClient.java"
click node_rpc_dispatcher "https://github.com/github/copilot-sdk-java/blob/main/src/main/java/com/github/copilot/RpcHandlerDispatcher.java"
click node_lifecycle_manager "https://github.com/github/copilot-sdk-java/blob/main/src/main/java/com/github/copilot/LifecycleEventManager.java"
click node_request_builder "https://github.com/github/copilot-sdk-java/blob/main/src/main/java/com/github/copilot/SessionRequestBuilder.java"
click node_rpc_domain "https://github.com/github/copilot-sdk-java/blob/main/src/main/java/com/github/copilot/rpc/package-info.java"
click node_session_config "https://github.com/github/copilot-sdk-java/blob/main/src/main/java/com/github/copilot/rpc/SessionConfig.java"
click node_hook_boundaries "https://github.com/github/copilot-sdk-java/blob/main/src/main/java/com/github/copilot/rpc/SessionHooks.java"
click node_tool_agent_boundary "https://github.com/github/copilot-sdk-java/blob/main/src/main/java/com/github/copilot/rpc/ToolSet.java"
click node_generated_events "https://github.com/github/copilot-sdk-java/blob/main/src/generated/java/com/github/copilot/generated/SessionEvent.java"
click node_generated_rpc "https://github.com/github/copilot-sdk-java/blob/main/src/generated/java/com/github/copilot/generated/rpc/SessionRpc.java"
click node_codegen "https://github.com/github/copilot-sdk-java/blob/main/scripts/codegen/java.ts"
click node_maven_build "https://github.com/github/copilot-sdk-java/blob/main/pom.xml"
click node_ci_release "https://github.com/github/copilot-sdk-java/blob/main/.github/workflows/build-test.yml"
click node_site_docs "https://github.com/github/copilot-sdk-java/blob/main/src/site/markdown/index.md"
click node_test_suite "https://github.com/github/copilot-sdk-java/blob/main/src/test/java/com/github/copilot/CopilotClientTest.java"
click node_fidelity_tests "https://github.com/github/copilot-sdk-java/blob/main/src/test/java/com/github/copilot/StreamingFidelityTest.java"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_copilot_client,node_copilot_session,node_cli_server_manager,node_json_rpc_client,node_rpc_dispatcher,node_lifecycle_manager,node_request_builder,node_rpc_domain,node_session_config,node_hook_boundaries,node_tool_agent_boundary toneBlue
class node_generated_events,node_generated_rpc toneAmber
class node_codegen,node_maven_build,node_ci_release,node_site_docs toneMint
class node_test_suite,node_fidelity_tests toneRose
```

## Components

### Runtime SDK

Handwritten client, session, transport, and public domain API.

- [CopilotClient](https://github.com/github/copilot-sdk-java/blob/main/src/main/java/com/github/copilot/CopilotClient.java): entrypoint · Main public entry point for applications using the SDK. · `src/main/java/com/github/copilot/CopilotClient.java`
- [CopilotSession](https://github.com/github/copilot-sdk-java/blob/main/src/main/java/com/github/copilot/CopilotSession.java): session api · Active session facade for send, resume, events, and session-scoped operations. · `src/main/java/com/github/copilot/CopilotSession.java`
- [CLI server](https://github.com/github/copilot-sdk-java/blob/main/src/main/java/com/github/copilot/CliServerManager.java): process manager · Launches and coordinates the local Copilot CLI process/session boundary. · `src/main/java/com/github/copilot/CliServerManager.java`
- [JSON-RPC](https://github.com/github/copilot-sdk-java/blob/main/src/main/java/com/github/copilot/JsonRpcClient.java): transport · Messaging layer over the local CLI boundary. · `src/main/java/com/github/copilot/JsonRpcClient.java`
- [Dispatcher](https://github.com/github/copilot-sdk-java/blob/main/src/main/java/com/github/copilot/RpcHandlerDispatcher.java): callback router · Routes inbound RPC callbacks and events to the right handlers. · `src/main/java/com/github/copilot/RpcHandlerDispatcher.java`
- [Lifecycle](https://github.com/github/copilot-sdk-java/blob/main/src/main/java/com/github/copilot/LifecycleEventManager.java): event manager · Coordinates session lifecycle events and consumer dispatch. · `src/main/java/com/github/copilot/LifecycleEventManager.java`
- [Request builder](https://github.com/github/copilot-sdk-java/blob/main/src/main/java/com/github/copilot/SessionRequestBuilder.java): payload builder · Assembles session request payloads and operation inputs. · `src/main/java/com/github/copilot/SessionRequestBuilder.java`
- [RPC domain](https://github.com/github/copilot-sdk-java/blob/main/src/main/java/com/github/copilot/rpc/package-info.java): public model layer · Handwritten stable API types for sessions, models, permissions, hooks, tools, MCP, telemetry, and user interaction. · `src/main/java/com/github/copilot/rpc/package-info.java`
- [Session config](https://github.com/github/copilot-sdk-java/blob/main/src/main/java/com/github/copilot/rpc/SessionConfig.java): configuration · Session, client, model, telemetry, permission, and workspace configuration objects. · `src/main/java/com/github/copilot/rpc/SessionConfig.java`
- [Hooks](https://github.com/github/copilot-sdk-java/blob/main/src/main/java/com/github/copilot/rpc/SessionHooks.java): callbacks · Permission, user input, tool, MCP, elicitation, and lifecycle callback contracts. · `src/main/java/com/github/copilot/rpc/SessionHooks.java`
- [Tools & agents](https://github.com/github/copilot-sdk-java/blob/main/src/main/java/com/github/copilot/rpc/ToolSet.java): extension layer · Tool sets, agents, skills, MCP server configs, and related invocation/result types. · `src/main/java/com/github/copilot/rpc/ToolSet.java`

### Generated Protocol

Protocol mirror and RPC namespaces generated from the Copilot CLI schema.

- [Generated events](https://github.com/github/copilot-sdk-java/blob/main/src/generated/java/com/github/copilot/generated/SessionEvent.java): protocol mirror · Generated session/event classes that mirror the CLI protocol stream. · `src/generated/java/com/github/copilot/generated/SessionEvent.java`
- [Generated RPC](https://github.com/github/copilot-sdk-java/blob/main/src/generated/java/com/github/copilot/generated/rpc/SessionRpc.java): protocol mirror · Generated request/response records and per-area RPC namespaces. · `src/generated/java/com/github/copilot/generated/rpc/SessionRpc.java`

### Delivery

Build, code generation, documentation, and CI/release pipeline.

- [Codegen](https://github.com/github/copilot-sdk-java/blob/main/scripts/codegen/java.ts): generator · TypeScript/Node generation pipeline for protocol bindings. · `scripts/codegen/java.ts`
- [Maven build](https://github.com/github/copilot-sdk-java/blob/main/pom.xml): build · Java build, wrapper, packaging, and site publication entrypoints. · `pom.xml`
- [CI/CD](https://github.com/github/copilot-sdk-java/blob/main/.github/workflows/build-test.yml): automation · GitHub Actions for build/test, sync, publish, release notes, and site deployment. · `.github/workflows/build-test.yml`
- [Docs site](https://github.com/github/copilot-sdk-java/blob/main/src/site/markdown/index.md): documentation · Maven site content, examples, and architecture/release docs. · `src/site/markdown/index.md`

### Tests

Architecture- and protocol-fidelity test layers.

- [Test suite](https://github.com/github/copilot-sdk-java/blob/main/src/test/java/com/github/copilot/CopilotClientTest.java): validation · Layered tests for wrappers, fidelity, compatibility, and end-to-end behavior. · `src/test/java/com/github/copilot/CopilotClientTest.java`
- [Fidelity tests](https://github.com/github/copilot-sdk-java/blob/main/src/test/java/com/github/copilot/StreamingFidelityTest.java): compatibility tests · Event streaming and serialization fidelity checks against the CLI protocol. · `src/test/java/com/github/copilot/StreamingFidelityTest.java`

## Connections

- CopilotClient → CLI server: starts/connects · Client coordinates local CLI process startup and connection lifecycle.
- CopilotClient → JSON-RPC: uses transport · Client delegates protocol messaging to JSON-RPC.
- CopilotClient → CopilotSession: creates sessions · Client hands back the primary session unit of work.
- CopilotSession → Request builder: builds requests · Session-scoped operations are assembled into protocol payloads.
- CopilotSession → Dispatcher: handles callbacks · Incoming events and callbacks are routed to handlers.
- CopilotSession → Lifecycle: emits lifecycle · Session lifecycle changes are coordinated and dispatched.
- JSON-RPC → Generated RPC: speaks protocol · Transport operates on generated wire records and APIs.
- Dispatcher → Generated events: dispatches events · Dispatcher maps protocol event types to consumers.
- Lifecycle → Generated events: publishes events · Lifecycle state changes surface as generated session events.
- Request builder → RPC domain: uses domain types · Request assembly depends on handwritten API objects.
- RPC domain → Session config: includes config · The public domain layer carries stable configuration objects.
- RPC domain → Hooks: defines callbacks · Permission, user input, tool, and lifecycle hooks live here.
- RPC domain → Tools & agents: defines extensions · Tools, agents, skills, and MCP integration boundaries are modeled here.
- Generated RPC → Generated events: mirrors schema · Generated RPC surface aligns with generated protocol event/model types.
- Codegen → Generated RPC: produces · Generator emits the RPC protocol mirror.
- Codegen → Generated events: produces · Generator emits event and enum surfaces from upstream schema.
- Maven build → Codegen: invokes · Build coordinates generation as part of the repo workflow.
- CI/CD → Maven build: runs · CI validates, packages, publishes, and deploys the library/site.
- CI/CD → Codegen: syncs · Automation keeps generated bindings and upstream protocol in step.
- Docs site → RPC domain: documents · Documentation explains public SDK usage and extension points.
- Test suite → CopilotClient: verifies · Tests cover the public entry point and session lifecycle.
- Test suite → RPC domain: verifies · Tests cover handwritten wrappers and models.
- Fidelity tests → Generated events: checks · Event fidelity tests validate generated event shapes and ordering.
- Fidelity tests → Generated RPC: checks · Protocol compatibility tests validate generated RPC contracts.
