Quickstart
Get a Copilot-powered app running in minutes.
Prerequisites
- GitHub account with Copilot access (Individual, Business, or Enterprise)
- GitHub CLI (
gh) installed and authenticated - Node.js 18+ (or Python 3.10+, Go 1.21+, .NET 8+)
Verify setup
# Check GitHub CLI authentication
gh auth status
# Should show:
# ✓ Logged in to github.com as YOUR_USERNAME
# ✓ Git operations for github.com configured to use https protocol.
Your First App
1. Create project
mkdir copilot-hello && cd copilot-hello
npm init -y
npm install @anthropic-ai/copilot-sdk # Placeholder - use actual package name
Note: Check
copilot-sdk/nodejs/for the actual package name and installation instructions.
2. Write the code
Create index.ts:
import { CopilotClient } from "@github/copilot-sdk"; // Adjust import as needed
async function main() {
// Create client (spawns Copilot CLI)
const client = await CopilotClient.create({
agent: {
name: "hello-copilot",
version: "1.0.0"
}
});
try {
// Create a session
const session = await client.createSession();
// Send a message and get response
const response = await session.send("What is the Copilot SDK?");
console.log(response.text);
} finally {
// Clean up
await client.close();
}
}
main().catch(console.error);
3. Run it
npx tsx index.ts
You should see Copilot’s explanation of what the SDK is.
Add Streaming
Update the code to see responses as they’re generated:
import { CopilotClient } from "@github/copilot-sdk";
async function main() {
const client = await CopilotClient.create({
agent: { name: "hello-copilot", version: "1.0.0" }
});
try {
const session = await client.createSession();
// Stream the response
console.log("Copilot: ");
for await (const event of session.send("Explain async/await in one paragraph")) {
if (event.type === "textDelta") {
process.stdout.write(event.delta);
}
}
console.log("\n");
} finally {
await client.close();
}
}
main().catch(console.error);
Add a Custom Tool
Give Copilot the ability to get the current time:
import { CopilotClient } from "@github/copilot-sdk";
// Define the tool
const timeTool = {
name: "get_current_time",
description: "Get the current time in a specified timezone",
parameters: {
type: "object",
properties: {
timezone: {
type: "string",
description: "Timezone name like 'America/New_York' or 'UTC'"
}
},
required: ["timezone"]
}
};
// Implement the tool
function getCurrentTime(timezone: string): string {
try {
return new Date().toLocaleString("en-US", { timeZone: timezone });
} catch {
return `Invalid timezone: ${timezone}`;
}
}
async function main() {
const client = await CopilotClient.create({
agent: { name: "time-bot", version: "1.0.0" }
});
try {
const session = await client.createSession({
tools: [timeTool]
});
console.log("Copilot: ");
for await (const event of session.send("What time is it in Tokyo?")) {
switch (event.type) {
case "textDelta":
process.stdout.write(event.delta);
break;
case "toolCall":
if (event.name === "get_current_time") {
const args = JSON.parse(event.arguments);
const result = getCurrentTime(args.timezone);
await session.submitToolResult(event.callId, result);
}
break;
}
}
console.log("\n");
} finally {
await client.close();
}
}
main().catch(console.error);
Interactive Chat Loop
Build a simple REPL:
import { CopilotClient } from "@github/copilot-sdk";
import * as readline from "readline";
async function main() {
const client = await CopilotClient.create({
agent: { name: "chat-bot", version: "1.0.0" }
});
const session = await client.createSession({
systemMessage: "You are a helpful assistant. Be concise."
});
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
console.log("Chat with Copilot (type 'exit' to quit)\n");
const prompt = () => {
rl.question("You: ", async (input) => {
if (input.toLowerCase() === "exit") {
await client.close();
rl.close();
return;
}
process.stdout.write("Copilot: ");
for await (const event of session.send(input)) {
if (event.type === "textDelta") {
process.stdout.write(event.delta);
}
}
console.log("\n");
prompt();
});
};
prompt();
}
main().catch(console.error);
Troubleshooting
”CLI not found”
The SDK needs the Copilot CLI. Install it:
gh extension install github/gh-copilot
Authentication errors
Make sure you’re logged in:
gh auth login
gh auth refresh -s copilot
“Model not available”
Your Copilot subscription determines available models. Check your plan’s capabilities.
Next Steps
- Deep dive: Explore Tools and Streaming
- Cookbook: See
copilot-sdk/cookbook/for production patterns - Experiment: Build something in experiments/