GitHub Copilot SDK NuGet Package: Installation and Usage in .NET
The official GitHub Copilot SDK NuGet package is GitHub.Copilot.SDK, and you can add it to any .NET project by running dotnet add package GitHub.Copilot.SDK.
The github/copilot-sdk repository hosts the official .NET client for integrating GitHub Copilot into your applications. When you need to add Copilot chat, tool support, or authentication to a .NET project, the GitHub Copilot SDK NuGet package provides the supported, production-ready distribution. The package identity and build configuration are defined directly in the source tree, ensuring the published artifact on NuGet stays in sync with the codebase.
Package Identity and Installation
According to the github/copilot-sdk source code, the file dotnet/src/GitHub.Copilot.SDK.csproj explicitly declares the NuGet package ID as GitHub.Copilot.SDK. This project file contains the metadata used to publish the library to the public NuGet gallery.
The repository's top-level README.md also links to the package via a NuGet badge, confirming the official distribution point at https://www.nuget.org/packages/GitHub.Copilot.SDK.
To install the package in your project, run the following command from your solution directory:
dotnet add package GitHub.Copilot.SDK
Creating a CopilotClient
Once installed, the main API surface is in the GitHub.Copilot namespace. The CopilotClient class is the primary entry point, and it automatically manages the underlying Copilot CLI process for you.
Sending Your First Prompt
The following example, based on the sample at dotnet/samples/Chat.cs, shows how to instantiate the client and send a message with ChatAsync:
using System;
using System.Threading.Tasks;
using GitHub.Copilot; // Namespace provided by the SDK
using Microsoft.Extensions.Logging; // Optional: logging support
class Program
{
static async Task Main(string[] args)
{
// Build a client – the SDK automatically starts the Copilot CLI process
var client = new CopilotClient();
// Send a prompt to the Copilot engine
var response = await client.ChatAsync("Write a C# method that returns the factorial of a number.");
Console.WriteLine("Copilot response:");
Console.WriteLine(response);
}
}
Key implementation details:
- CopilotClient handles the lifecycle of the Copilot CLI process.
- ChatAsync accepts a natural-language prompt and returns the model's response as a string.
Authentication Options
By default, the SDK authenticates using the token from the logged-in GitHub CLI. You can override this behavior with environment variables or bring-your-own-key (BYOK) configurations.
Using GitHub Tokens or BYOK
The code below demonstrates all three authentication patterns:
using System;
using System.Threading.Tasks;
using GitHub.Copilot;
using Microsoft.Extensions.Logging;
class Program
{
static async Task Main(string[] args)
{
// Option 1 – use the logged‑in GitHub CLI token (default)
var client = new CopilotClient();
// Option 2 – provide a personal access token via environment variable
// Environment.SetEnvironmentVariable("COPILOT_GITHUB_TOKEN", "<your‑token>");
// Option 3 – use BYOK (e.g., OpenAI API key)
// client.Options.ApiKey = "<your‑openai‑key>";
// client.Options.BaseUrl = "https://api.openai.com/v1";
var result = await client.ChatAsync("Explain the difference between async and await in C#.");
Console.WriteLine(result);
}
}
Invoking Built-In Tools
The SDK ships with tools such as FileEditTool in the GitHub.Copilot.Tools namespace. You must explicitly enable a tool on the client before the Copilot engine can use it during a chat session.
Enabling the File Edit Tool
This pattern mirrors the logic found in dotnet/samples/ManualToolResume.cs:
using System;
using System.Threading.Tasks;
using GitHub.Copilot;
using GitHub.Copilot.Tools; // Namespace for built‑in tools
class Program
{
static async Task Main(string[] args)
{
var client = new CopilotClient();
// Enable the built‑in file‑edit tool
client.EnableTool(FileEditTool.Name);
var prompt = @"
Create a new file called HelloWorld.cs with a simple 'Hello, World!' program.
";
var response = await client.ChatAsync(prompt);
Console.WriteLine(response);
}
}
Build Validation and Packaging
The repository verifies its NuGet output through unit tests in dotnet/test/Unit/MSBuildTargetsTests.cs. These tests confirm that GitHub.Copilot.SDK.targets is correctly included in the package, ensuring that consuming .NET projects receive the required build-time assets when they reference the SDK.
Summary
- The official GitHub Copilot SDK NuGet package is named
GitHub.Copilot.SDK, declared indotnet/src/GitHub.Copilot.SDK.csproj. - Install it using
dotnet add package GitHub.Copilot.SDKfrom the public NuGet gallery. - The CopilotClient class automatically manages the Copilot CLI process; use ChatAsync to send prompts.
- Authentication defaults to the GitHub CLI token, but supports
COPILOT_GITHUB_TOKENand BYOK settings. - Enable tools like FileEditTool through the client before invoking chat operations.
- MSBuild target tests in the repository ensure the NuGet package bundles the correct build assets.
Frequently Asked Questions
What is the exact NuGet package name for the GitHub Copilot SDK in .NET?
The exact package name is GitHub.Copilot.SDK. This ID is set in dotnet/src/GitHub.Copilot.SDK.csproj and is the name listed on the public NuGet gallery.
How do I install the GitHub Copilot SDK in a .NET project?
Run dotnet add package GitHub.Copilot.SDK in your project directory. The package is hosted publicly on NuGet, so no additional package sources are required.
Does the SDK require manual authentication configuration?
No. By default, CopilotClient automatically uses the authentication token from the logged-in GitHub CLI. You can optionally supply a token through the COPILOT_GITHUB_TOKEN environment variable or configure a BYOK endpoint via client.Options.
Can the SDK invoke Copilot tools such as file editing?
Yes. You can enable built-in tools by calling client.EnableTool(FileEditTool.Name) before sending a prompt. This registers the tool with the Copilot engine so it can perform file operations during the chat session.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →