Copilot SDK for Java
⚠️ Disclaimer: This is the official Java SDK for GitHub Copilot. This repository treats the official .NET and nodejs SDKs for GitHub Copilot as reference implementations. These SDKS are all officially supported as GitHub open source projects. The Java implementation follows the backward compatibility guarantees offered by the reference implementations. As such this implementation may introduce breaking changes, according to the policy declared by the reference implementations. Use at your own risk.
Welcome to the documentation for the Copilot SDK for Java — a Java SDK for programmatic control of GitHub Copilot CLI, enabling you to build AI-powered applications and agentic workflows.
Getting Started
Requirements
- Java 17 or later
- GitHub Copilot CLI 0.0.411-1 or later installed and in PATH (or provide custom
cliPath)
Installation
Add the dependency to your project:
Note: If this is a
-SNAPSHOTversion, clone the project repository and run./mvnw installlocally first so the artifact is available in your local Maven cache. Otherwise, the version is available on Maven Central.
Maven:
<dependency>
<groupId>com.github</groupId>
<artifactId>copilot-sdk-java</artifactId>
<version>0.1.33-java.0-SNAPSHOT</version>
</dependency>
Gradle:
implementation 'com.github:copilot-sdk-java:0.1.33-java.0-SNAPSHOT'
Quick Example
import com.github.copilot.sdk.*;
import com.github.copilot.sdk.events.*;
import com.github.copilot.sdk.json.*;
import java.util.concurrent.CompletableFuture;
public class Example {
public static void main(String[] args) throws Exception {
try (var client = new CopilotClient()) {
client.start().get();
var session = client.createSession(
new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL).setModel("claude-sonnet-4.5")
).get();
var done = new CompletableFuture<Void>();
session.on(AssistantMessageEvent.class, msg -> {
System.out.println(msg.getData().content());
});
session.on(SessionIdleEvent.class, idle -> done.complete(null));
session.send(new MessageOptions().setPrompt("What is 2+2?")).get();
done.get();
}
}
}
Documentation
| Document | Description |
|---|---|
| Documentation | Basic usage, streaming, handling responses, and session management |
| Advanced Usage | Tools, BYOK, MCP servers, infinite sessions, skills, and more |
| MCP Servers | Integrating Model Context Protocol servers |
| Javadoc | Generated API documentation |
Try it with JBang
You can quickly try the SDK without setting up a full project using JBang:
# Install JBang (if not already installed)
# macOS: brew install jbang
# Linux/Windows: curl -Ls https://sh.jbang.dev | bash -s - app setup
# Create a simple script
cat > hello-copilot.java << 'EOF'
//DEPS com.github:copilot-sdk-java:0.1.33-java.0-SNAPSHOT
import com.github.copilot.sdk.*;
import com.github.copilot.sdk.events.*;
import com.github.copilot.sdk.json.*;
import java.util.concurrent.CompletableFuture;
class hello {
public static void main(String[] args) throws Exception {
try (var client = new CopilotClient()) {
client.start().get();
var session = client.createSession(new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL)).get();
var done = new CompletableFuture<Void>();
session.on(AssistantMessageEvent.class, msg -> {
System.out.print(msg.getData().content());
});
session.on(SessionIdleEvent.class, idle -> done.complete(null));
session.send(new MessageOptions().setPrompt("Say hello!")).get();
done.get();
}
}
}
EOF
# Run it
jbang hello-copilot.java
