# Key Source Files in the GitHub Copilot SDK Repository: A Complete Guide

> Explore key source files in the GitHub Copilot SDK repository. Understand how client.ts, session.ts, and rpc.ts manage process lifecycle and conversations for a seamless development experience.

- Repository: [GitHub/copilot-sdk](https://github.com/github/copilot-sdk)
- Tags: deep-dive
- Published: 2026-06-06

---

**The GitHub Copilot SDK is organized as a TypeScript/Node.js client library that wraps the Copilot CLI via JSON-RPC, with its architecture defined by pivotal source files including [`nodejs/src/client.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/client.ts) for process lifecycle management, [`nodejs/src/session.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/session.ts) for conversation handling, and generated protocol bindings in [`nodejs/src/generated/rpc.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/generated/rpc.ts).**

The GitHub Copilot SDK provides developers with a TypeScript/Node.js client library for integrating GitHub Copilot capabilities into custom applications. Understanding the key source files in the GitHub Copilot SDK repository enables developers to effectively extend functionality, debug integration issues, and leverage the full JSON-RPC interface. The codebase follows a layered architecture that separates public API surfaces from low-level protocol bindings and runtime management.

## Public API and Entry Points

The SDK exposes a clean public interface while delegating implementation details to specialized internal modules.

### Main Entry Point ([`nodejs/src/index.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/index.ts))

The **[`nodejs/src/index.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/index.ts)** file serves as the **public entry point** for the entire SDK. It re-exports the client, session, tools, canvas utilities, core types, and generated event types, providing a unified import surface for consumers. This file aggregates functionality from across the codebase, ensuring developers can access all necessary classes and type definitions through a single import statement.

### Type Definitions ([`nodejs/src/types.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/types.ts))

Centralized type safety is handled in **[`nodejs/src/types.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/types.ts)**, which contains all SDK-exposed types including client options, session configuration, RPC signatures, telemetry definitions, and canvas types. This file also provides helper functions for schema conversion and runtime-connection factories, acting as the single source of truth for TypeScript interfaces throughout the project.

## Client and Session Management

The runtime layer manages the Copilot CLI process lifecycle and conversation state abstraction.

### Client Implementation ([`nodejs/src/client.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/client.ts))

The **[`nodejs/src/client.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/client.ts)** file implements the **`CopilotClient`** class, which manages the lifecycle of the Copilot CLI process (or an external server). It establishes the JSON-RPC connection, handles protocol version negotiation, sets up the environment, and manages graceful shutdown sequences. Key methods include **`createSession`** and **`resumeSession`**, which instantiate new conversation contexts or restore existing ones from persistent storage.

### Session Abstraction ([`nodejs/src/session.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/session.ts))

Individual conversations are encapsulated in **[`nodejs/src/session.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/session.ts)**, which defines the session abstraction representing a single conversation with the Copilot model. This file provides methods for sending messages, registering tools and canvases, handling commands, and processing incoming events through event listeners. It wires up tool registration and translates user-friendly interactions into RPC calls specific to that session.

## Tools and Extensions

Specialized modules handle tool composition, visual output, observability, and persistence.

### Tool Management ([`nodejs/src/toolSet.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/toolSet.ts))

The **[`nodejs/src/toolSet.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/toolSet.ts)** file supplies the **`ToolSet`** class, allowing developers to compose built-in tools, MCP (Model Context Protocol) tools, and custom implementations. It converts developer-friendly tool definitions into the wire format expected by the Copilot runtime, managing tool filters and execution contexts.

### Canvas API ([`nodejs/src/canvas.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/canvas.ts))

Visual interactions and image generation capabilities are defined in **[`nodejs/src/canvas.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/canvas.ts)**. This file implements the high-level Canvas API used for drawing operations and visual outputs, including error handling and host-context capabilities for rendering environments.

### Telemetry and Persistence ([`nodejs/src/telemetry.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/telemetry.ts), [`nodejs/src/sessionFsProvider.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/sessionFsProvider.ts))

Observability features reside in **[`nodejs/src/telemetry.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/telemetry.ts)**, which captures trace context and sends telemetry payloads alongside RPC calls to monitor SDK usage. For state management, **[`nodejs/src/sessionFsProvider.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/sessionFsProvider.ts)** enables the SDK to plug in custom session-filesystem adapters, such as SQLite-backed persistence layers, allowing sessions to survive process restarts.

## Protocol Bindings and Generated Code

Type-safe communication with the Copilot CLI relies on auto-generated bindings derived from the protocol specification.

### RPC Contracts ([`nodejs/src/generated/rpc.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/generated/rpc.ts))

The **[`nodejs/src/generated/rpc.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/generated/rpc.ts)** file contains auto-generated TypeScript bindings for all JSON-RPC methods exposed by the Copilot CLI. These definitions serve as the definitive source of request and response shapes, ensuring compile-time safety for both client-side and internal RPC interactions. The generation process guarantees the SDK remains synchronized with the underlying CLI protocol.

### Session Event Types ([`nodejs/src/generated/session-events.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/generated/session-events.ts))

Similarly, **[`nodejs/src/generated/session-events.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/generated/session-events.ts)** provides auto-generated type definitions for every session event, including `assistant.message`, `tool.result`, and `session.lifecycle` events. These types are re-exported from the public API for convenient consumption by SDK users, enabling strongly-typed event handling.

## Development and Validation Utilities

Supporting infrastructure ensures protocol compatibility and code quality.

### Protocol Version Management ([`nodejs/src/sdkProtocolVersion.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/sdkProtocolVersion.ts))

The **[`nodejs/src/sdkProtocolVersion.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/sdkProtocolVersion.ts)** file implements the protocol version helper, which reads the runtime protocol version from the bundled CLI and validates compatibility between the SDK and the underlying runtime. This prevents version mismatches that could cause communication failures.

### Code Generation Scripts ([`scripts/codegen/typescript.ts`](https://github.com/github/copilot-sdk/blob/main/scripts/codegen/typescript.ts))

Build-time automation is handled by **[`scripts/codegen/typescript.ts`](https://github.com/github/copilot-sdk/blob/main/scripts/codegen/typescript.ts)**, a convenience script for generating TypeScript bindings, updating protocol versions, and validating documentation. This script processes the CLI's protocol definitions to produce the contents of the `generated/` directory.

### Integration Testing ([`nodejs/test/e2e/session.e2e.test.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/test/e2e/session.e2e.test.ts))

The **[`nodejs/test/e2e/session.e2e.test.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/test/e2e/session.e2e.test.ts)** file contains extensive end-to-end integration tests that drive a real Copilot CLI instance to verify client behavior. These tests validate the public API against actual runtime responses, ensuring the SDK remains functional across version updates.

## Practical Implementation Example

Below is a runnable example demonstrating typical SDK usage, referencing the key source files described above:

```typescript
import { CopilotClient, approveAll } from '@github/copilot-sdk';

// Create a client (see nodejs/src/client.ts for implementation)
const client = new CopilotClient();

// Start the client (spawns the CLI if needed)
await client.start();

// Create a session with custom tools (see nodejs/src/toolSet.ts & nodejs/src/types.ts)
const session = await client.createSession({
  onPermissionRequest: approveAll,
  model: 'gpt-4',
  tools: [
    {
      name: 'weather',
      description: 'Fetches current weather for a location',
      parameters: {
        type: 'object',
        properties: {
          location: { type: 'string' }
        },
        required: ['location']
      },
      handler: async ({ location }) => ({
        temperature: 72,
        condition: 'Sunny'
      })
    }
  ]
});

// Send prompts and handle responses (see nodejs/src/session.ts)
session.on(event => {
  if (event.type === 'assistant.message') {
    console.log('Assistant:', event.data.content);
  }
});
await session.send({ prompt: 'What is the weather in Paris?' });

// Gracefully shutdown (see nodejs/src/client.ts)
await client.stop();

```

## Summary

Understanding the key source files in the GitHub Copilot SDK repository reveals a well-architected TypeScript client library:

- **[`nodejs/src/index.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/index.ts)** provides the unified public API surface for all SDK imports.
- **[`nodejs/src/client.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/client.ts)** manages the Copilot CLI process lifecycle and JSON-RPC connections.
- **[`nodejs/src/session.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/session.ts)** handles individual conversation state and event processing.
- **[`nodejs/src/toolSet.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/toolSet.ts)** and **[`nodejs/src/canvas.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/canvas.ts)** extend functionality with custom tools and visual outputs.
- **[`nodejs/src/generated/rpc.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/generated/rpc.ts)** and **[`nodejs/src/generated/session-events.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/generated/session-events.ts)** ensure type-safe protocol communication through auto-generated bindings.
- **[`nodejs/src/telemetry.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/telemetry.ts)** and **[`nodejs/src/sessionFsProvider.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/sessionFsProvider.ts)** add observability and persistence capabilities.
- Test and build scripts in **`scripts/`** and **`nodejs/test/`** maintain code quality and protocol compatibility.

## Frequently Asked Questions

### What is the main entry point for the GitHub Copilot SDK?

The main entry point is **[`nodejs/src/index.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/index.ts)**, which re-exports all public APIs including the `CopilotClient` class, session types, tool definitions, and generated event types. This file allows developers to import all necessary SDK components through a single statement: `import { CopilotClient } from '@github/copilot-sdk'`.

### How does the SDK communicate with the Copilot CLI?

The SDK communicates via JSON-RPC over stdin/stdout, implemented primarily in **[`nodejs/src/client.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/client.ts)**. This file spawns the CLI process (or connects to an external server), manages protocol version negotiation, and handles graceful shutdown. The actual message formatting uses type-safe bindings defined in **[`nodejs/src/generated/rpc.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/generated/rpc.ts)**.

### Where are the type-safe RPC bindings defined?

Auto-generated RPC bindings are located in **[`nodejs/src/generated/rpc.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/generated/rpc.ts)**, which contains TypeScript definitions for every JSON-RPC method exposed by the Copilot CLI. Session-specific event types are defined in **[`nodejs/src/generated/session-events.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/generated/session-events.ts)**. These files are generated by **[`scripts/codegen/typescript.ts`](https://github.com/github/copilot-sdk/blob/main/scripts/codegen/typescript.ts)** to ensure the SDK stays synchronized with the CLI protocol.

### How does session persistence work in the SDK?

Session persistence is handled through the **[`nodejs/src/sessionFsProvider.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/sessionFsProvider.ts)** file, which defines an adapter interface for custom filesystem implementations. Developers can plug in providers such as SQLite-backed storage to enable sessions to survive process restarts. The **`CopilotClient`** class in **[`nodejs/src/client.ts`](https://github.com/github/copilot-sdk/blob/main/nodejs/src/client.ts)** provides **`resumeSession`** methods that leverage these adapters to restore conversation state.