Java SDK for programmatic control of GitHub Copilot CLI via JSON-RPC.
📦 The Java SDK is maintained in a separate repository:
github/copilot-sdk-javaNote: This SDK is in public preview and may change in breaking ways.
import com.github.copilot.sdk.CopilotClient;
import com.github.copilot.sdk.events.AssistantMessageEvent;
import com.github.copilot.sdk.events.SessionIdleEvent;
import com.github.copilot.sdk.json.MessageOptions;
import com.github.copilot.sdk.json.PermissionHandler;
import com.github.copilot.sdk.json.SessionConfig;
public class QuickStart {
public static void main(String[] args) throws Exception {
// Create and start client
try (var client = new CopilotClient()) {
client.start().get();
// Create a session (onPermissionRequest is required)
var session = client.createSession(
new SessionConfig()
.setModel("gpt-5")
.setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
).get();
var done = new java.util.concurrent.CompletableFuture<Void>();
// Handle events
session.on(AssistantMessageEvent.class, msg ->
System.out.println(msg.getData().content()));
session.on(SessionIdleEvent.class, idle ->
done.complete(null));
// Send a message and wait for completion
session.send(new MessageOptions().setPrompt("What is 2+2?"));
done.get();
}
}
}Run the SDK without setting up a full project using JBang:
jbang https://github.com/github/copilot-sdk-java/blob/main/jbang-example.java| Resource | Link |
|---|---|
| Full Documentation | github.github.io/copilot-sdk-java |
| Getting Started Guide | Documentation |
| API Reference (Javadoc) | javadoc.io |
| MCP Servers Integration | MCP Guide |
| Cookbook | Recipes |
| Source Code | github/copilot-sdk-java |
| Issues & Feature Requests | GitHub Issues |
| Releases | GitHub Releases |
| Copilot Instructions | copilot-sdk-java.instructions.md |
Contributions are welcome! Please see the Contributing Guide in the GitHub Copilot SDK for Java repository.
MIT — see LICENSE for details.