Skip to content

Latest commit

 

History

History
82 lines (62 loc) · 4.66 KB

File metadata and controls

82 lines (62 loc) · 4.66 KB

GitHub Copilot SDK for Java

Java SDK for programmatic control of GitHub Copilot CLI via JSON-RPC.

Build Maven Central Java 17+ Documentation Javadoc

Quick Start

📦 The Java SDK is maintained in a separate repository: github/copilot-sdk-java

Note: This SDK is in technical 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();
        }
    }
}

Try it with JBang

Run the SDK without setting up a full project using JBang:

jbang https://github.com/github/copilot-sdk-java/blob/main/jbang-example.java

Documentation & Resources

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

Contributing

Contributions are welcome! Please see the Contributing Guide in the GitHub Copilot SDK for Java repository.

License

MIT — see LICENSE for details.