Note
Copilot SDK is currently in public preview. Functionality and availability are subject to change.
GitHub Copilot SDK communicates with GitHub Copilot CLI via JSON-RPC protocol. Features must be explicitly exposed through this protocol to be available in the SDK. Many interactive CLI features are terminal-specific and not available programmatically.
Feature comparison
Available in SDK
Not available in SDK (CLI-only)
| Feature | CLI command/option | Reason |
|---|---|---|
| Session Export | ||
| Export to file | --share, /share | Not in protocol |
| Export to gist | --share-gist, /share gist | Not in protocol |
| Interactive UI | ||
| Slash commands | /help, /clear, /exit, etc. | Terminal UI (TUI)-only |
| Agent picker dialog | /agent | Interactive UI |
| Diff mode dialog | /diff | Interactive UI |
| Feedback dialog | /feedback | Interactive UI |
| Theme picker | /theme | Terminal UI |
| Model picker | /model | Interactive UI (use SDK setModel() instead) |
| Copy to clipboard | /copy | Terminal-specific |
| Context management | /context | Interactive UI |
| Research & History | ||
| Deep research | /research | TUI workflow with web search |
| Session history tools | /chronicle | Standup, tips, improve, reindex |
| Terminal Features | ||
| Color output | --no-color | Terminal-specific |
| Screen reader mode | --screen-reader | Accessibility |
| Rich diff rendering | --plain-diff | Terminal rendering |
| Startup banner | --banner | Visual element |
| Alternate screen buffer | --alt-screen, --no-alt-screen | Terminal rendering |
| Mouse support | --mouse, --no-mouse | Terminal input |
| Path/Permission Shortcuts | ||
| Allow all paths | --allow-all-paths | Use permission handler |
| Allow all URLs | --allow-all-urls | Use permission handler |
| Allow all permissions | --yolo, --allow-all, /allow-all | Use permission handler |
| Granular tool permissions | --allow-tool, --deny-tool | Use onPreToolUse hook |
| URL access control | --allow-url, --deny-url | Use permission handler |
| Reset allowed tools | /reset-allowed-tools | TUI command |
| Directory Management | ||
| Add directory | /add-dir, --add-dir | Configure in session |
| List directories | /list-dirs | TUI command |
| Change directory | /cwd | TUI command |
| Plugin/MCP Management | ||
| Plugin commands | /plugin | Interactive management |
| MCP server management | /mcp | Interactive UI |
| Account Management | ||
| Login flow | /login, copilot auth login | OAuth device flow |
| Logout | /logout, copilot auth logout | Direct CLI |
| User info | /user | TUI command |
| Session Operations | ||
| Clear conversation | /clear | TUI-only |
| Plan view | /plan | TUI-only (use SDK session.rpc.plan.* instead) |
| Session management | /session, /resume, /rename | TUI workflow |
| Fleet mode (interactive) | /fleet | TUI-only (use SDK session.rpc.fleet.start() instead) |
| Skills Management | ||
| Manage skills | /skills | Interactive UI |
| Task Management | ||
| View background tasks | /tasks | TUI command |
| Usage & Stats | ||
| Token usage | /usage | Subscribe to usage events |
| Code Review | ||
| Review changes | /review | TUI command |
| Delegation | ||
| Delegate to PR | /delegate | TUI workflow |
| Terminal Setup | ||
| Shell integration | /terminal-setup | Shell-specific |
| Development | ||
| Toggle experimental | /experimental, --experimental | Runtime flag |
| Custom instructions control | --no-custom-instructions | CLI flag |
| Diagnose session | /diagnose | TUI command |
| View/manage instructions | /instructions | TUI command |
| Collect debug logs | /collect-debug-logs | Diagnostic tool |
| Reindex workspace | /reindex | TUI command |
| IDE integration | /ide | IDE-specific workflow |
| Non-interactive Mode | ||
| Prompt mode | -p, --prompt | Single-shot execution |
| Interactive prompt | -i, --interactive | Auto-execute then interactive |
| Silent output | -s, --silent | Script-friendly |
| Continue session | --continue | Resume most recent |
| Agent selection | --agent <agent> | CLI flag |
Workarounds
Session export
The --share option is not available via SDK. To work around this:
-
Collect events manually: Subscribe to session events and build your own export:
TypeScript const events: SessionEvent[] = []; session.on((event) => events.push(event)); // ... after conversation ... const messages = await session.getMessages(); // Format as markdown yourself
const events: SessionEvent[] = []; session.on((event) => events.push(event)); // ... after conversation ... const messages = await session.getMessages(); // Format as markdown yourself -
Use the CLI directly for one-off exports.
Permission control
The SDK uses a deny-by-default permission model. All permission requests (file writes, shell commands, URL fetches, and others) are denied unless your app provides an onPermissionRequest handler.
Instead of --allow-all-paths or --yolo, use the permission handler:
const session = await client.createSession({
onPermissionRequest: approveAll,
});
const session = await client.createSession({
onPermissionRequest: approveAll,
});
Token usage tracking
Instead of /usage, subscribe to usage events:
session.on("assistant.usage", (event) => {
console.log("Tokens used:", {
input: event.data.inputTokens,
output: event.data.outputTokens,
});
});
session.on("assistant.usage", (event) => {
console.log("Tokens used:", {
input: event.data.inputTokens,
output: event.data.outputTokens,
});
});
Context compaction
Instead of /compact, configure automatic compaction or trigger it manually:
// Automatic compaction via config
const session = await client.createSession({
infiniteSessions: {
enabled: true,
backgroundCompactionThreshold: 0.80, // Start background compaction at 80% context utilization
bufferExhaustionThreshold: 0.95, // Block and compact at 95% context utilization
},
});
// Manual compaction (experimental)
const result = await session.rpc.compaction.compact();
console.log(`Removed ${result.tokensRemoved} tokens, ${result.messagesRemoved} messages`);
// Automatic compaction via config
const session = await client.createSession({
infiniteSessions: {
enabled: true,
backgroundCompactionThreshold: 0.80, // Start background compaction at 80% context utilization
bufferExhaustionThreshold: 0.95, // Block and compact at 95% context utilization
},
});
// Manual compaction (experimental)
const result = await session.rpc.compaction.compact();
console.log(`Removed ${result.tokensRemoved} tokens, ${result.messagesRemoved} messages`);
Note
Thresholds are context utilization ratios (0.0-1.0), not absolute token counts.
Plan management
Read and write session plans programmatically:
// Read the current plan
const plan = await session.rpc.plan.read();
if (plan.exists) {
console.log(plan.content);
}
// Update the plan
await session.rpc.plan.update({ content: "# My Plan\n- Step 1\n- Step 2" });
// Delete the plan
await session.rpc.plan.delete();
// Read the current plan
const plan = await session.rpc.plan.read();
if (plan.exists) {
console.log(plan.content);
}
// Update the plan
await session.rpc.plan.update({ content: "# My Plan\n- Step 1\n- Step 2" });
// Delete the plan
await session.rpc.plan.delete();
Message steering
Inject a message into the current LLM turn without aborting:
// Steer the agent mid-turn
await session.send({ prompt: "Focus on error handling first", mode: "immediate" });
// Default: enqueue for next turn
await session.send({ prompt: "Next, add tests" });
// Steer the agent mid-turn
await session.send({ prompt: "Focus on error handling first", mode: "immediate" });
// Default: enqueue for next turn
await session.send({ prompt: "Next, add tests" });
Protocol limitations
The SDK can only access features exposed through the CLI's JSON-RPC protocol. If you need a CLI feature that's not available:
- Check for alternatives: Many features have SDK equivalents (see Workarounds above).
- Use the CLI directly: For one-off operations, invoke the CLI.
- Request the feature: Open an issue in the github/copilot-sdk repository to request protocol support.
Version compatibility
The SDK negotiates protocol versions with the CLI at startup. The SDK supports protocol versions 2 through 3. When connecting to a v2 CLI server, the SDK automatically adapts tool.call and permission.request messages to the v3 event model—no code changes required.
You can check versions at runtime:
const status = await client.getStatus();
console.log("Protocol version:", status.protocolVersion);
const status = await client.getStatus();
console.log("Protocol version:", status.protocolVersion);
