This document outlines which Copilot CLI features are available through the SDK and which are CLI-only.
The Copilot SDK communicates with the Copilot runtime 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 | SDK Method | Notes |
|---|---|---|
| Session Management | ||
| Create session | createSession() | Full config support |
| Resume session | resumeSession() | With infinite session workspaces |
| Disconnect session | disconnect() | Release in-memory resources |
| Delete session | deleteSession() | Remove from storage |
| List sessions | listSessions() | All stored sessions |
| Get last session | getLastSessionId() | For quick resume |
| Get foreground session | getForegroundSessionId() | Multi-session coordination |
| Set foreground session | setForegroundSessionId() | Multi-session coordination |
| Messaging | ||
| Send message | send() | With attachments |
| Send and wait | sendAndWait() | Blocks until complete |
| Steering (immediate mode) | send({ mode: "immediate" }) | Inject mid-turn without aborting |
| Queueing (enqueue mode) | send({ mode: "enqueue" }) | Buffer for sequential processing (default) |
| File attachments | send({ attachments: [{ type: "file", path }] }) | Images auto-encoded and resized |
| Directory attachments | send({ attachments: [{ type: "directory", path }] }) | Attach directory context |
| Get history | getEvents() | All session events |
| Abort | abort() | Cancel in-flight request |
| Tools | ||
| Register custom tools | tools.definitions in session config | Full JSON Schema support |
| Replace custom tools (mid-session) | session.setTools() | Experimental; see Changing tools during a session |
| Tool permission control | onPreToolUse hook | Allow/deny/ask |
| Tool result modification | onPostToolUse hook | Transform results |
| Available/excluded tools | tools.availableTools, tools.excludedTools config | Filter tools |
| Models | ||
| List models | listModels() | With capabilities, billing, policy |
| Set model (at creation) | model in session config | Per-session |
| Switch model (mid-session) | session.setModel() | Also via session.rpc.model.switchTo() |
| Get current model | session.rpc.model.getCurrent() | Query active model |
| Reasoning effort | inference.reasoningEffort config | For supported models |
| Agent Mode | ||
| Get current mode | session.rpc.mode.get() | Returns current mode |
| Set mode | session.rpc.mode.set() | Switch between modes |
| Plan Management | ||
| Read plan | session.rpc.plan.read() | Get plan.md content and path |
| Update plan | session.rpc.plan.update() | Write plan.md content |
| Delete plan | session.rpc.plan.delete() | Remove plan.md |
| Workspace Files | ||
| List workspace files | session.rpc.workspaces.listFiles() | Files in session workspace |
| Read workspace file | session.rpc.workspaces.readFile() | Read file content |
| Create workspace file | session.rpc.workspaces.createFile() | Create file in workspace |
| Authentication | ||
| Get auth status | getAuthStatus() | Check login state |
| Use token | github.token option | Programmatic auth |
| Connectivity | ||
| Ping | client.ping() | Health check with runtime timestamp |
| Get runtime status | client.getStatus() | Runtime version and protocol version |
| MCP Servers | ||
| Local/stdio servers | mcp.servers config | Spawn processes |
| Remote HTTP/SSE | mcp.servers config | Connect to services |
| Hooks | ||
| Pre-tool use | onPreToolUse | Permission, modify args |
| Pre-MCP tool call | onPreMcpToolCall | Attach or remove MCP request metadata |
| Post-tool use (success) | onPostToolUse | Modify results |
| Post-tool use (failure) | onPostToolUseFailure | Observe failed tool calls, inject retry guidance |
| User prompt | onUserPromptSubmitted | Modify prompts |
| User prompt transformed | onUserPromptTransformed | Inspect or replace model-facing content |
| Session start/end | onSessionStart, onSessionEnd | Lifecycle with source/reason |
| Error handling | onErrorOccurred | Custom handling |
| Agent stop | onAgentStop | Validate completion or request another turn |
| Sub-agent lifecycle | onSubagentStart, onSubagentStop | Prepend context to a sub-agent's prompt, request another turn or replace its response |
| Events | ||
| All session events | on() | 40+ event types |
| Streaming | events.streaming: true | Delta events |
| Session Config | ||
| Custom agents | agents.definitions config | Define specialized agents |
| System message | systemMessage config | Append or replace |
| Named providers | inference.providers connections | BYOK support |
| Infinite sessions | state.infiniteSessions config | Auto-compaction |
| Permission handler | permissions.onRequest | Approve/deny; decisionContext.userFeedback collects explanations only in restricted telemetry |
| User input handler | interaction.onUserInputRequest | Handle ask_user |
| Shell authentication handler | interaction.onShellAuthenticationRequest | Answer shell password prompts; see Shell password prompts |
| Skills | skills.directories config | Custom skills |
| Disabled skills | skills.disabledSkills config | Disable specific skills |
| Config directory | configDirectory config | Override default config location |
| Client name | clientName config | Identify app in User-Agent |
| Working directory | workingDirectory config | Set session cwd |
| Additional directories | filesystem.additionalDirectories config | Grant session access beyond the working directory; re-supply on resume |
| Experimental | ||
| Agent management | session.rpc.agent.* | List, select, deselect, get current agent |
| Fleet mode | session.rpc.fleet.start() | Parallel sub-agent execution; see Fleet mode |
| Manual compaction | session.rpc.history.compact() | Trigger compaction on demand |
| Compaction settings | session.rpc.history.setCompactionConfig() | Override the compaction model, prompt and reasoning effort for a live session; {} restores defaults; re-apply after resume |
| Context clearing | session.rpc.history.clearContext() | Replace conversation context from a terminal tool |
| History truncation | session.rpc.history.truncate() | Remove events from a point onward |
| Session forking | client.rpc.sessions.fork() | Fork a session at a point in history |
| 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. | 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 (use SDK session.rpc.metadata.contextInfo() instead) |
| 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 |
| Startup banner | --banner | Visual element |
| 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 (use SDK session.rpc.metadata.setWorkingDirectory() instead) |
| Plugin/MCP Management | ||
| Plugin commands | /plugin | Interactive management (use SDK client.rpc.plugins.* for installed plugins and marketplaces, or session.rpc.plugins.* to change plugins in a live session) |
| MCP server management | /mcp | Interactive UI (use SDK client.rpc.mcp.config.* to edit saved MCP configuration, which does not restart running servers, or session.rpc.mcp.* to list, start, stop and reload servers in a live session) |
| Account Management | ||
| Login flow | /login, copilot login | OAuth device flow |
| Logout | /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 (use SDK resumeSession() to resume and session.rpc.name.set() to rename) |
| Fleet mode (interactive) | /fleet | TUI-only (use SDK session.rpc.fleet.start() instead) |
| Skills Management | ||
| Manage skills | /skills | Interactive UI (use SDK session.rpc.skills.* instead) |
| Task Management | ||
| View background tasks | /tasks | TUI command (use SDK session.rpc.tasks.* instead) |
| 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 (use SDK instructions.skipCustomInstructions config instead) |
| Diagnose session | /diagnose | TUI command |
| View/manage instructions | /instructions | TUI command (use SDK session.rpc.instructions.getSources() instead) |
| Collect debug logs | /collect-debug-logs | Diagnostic tool (use SDK session.rpc.debug.collectLogs() instead) |
| 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 (use SDK client.rpc.sessions.getLastForContext({ context }) with resumeSession() to prefer sessions from the working directory, or getLastSessionId() for the most recent session overall) |
| Agent selection | --agent <agent> | CLI flag (use SDK agents.selected config or session.rpc.agent.select() instead) |
Fleet mode is available through session.rpc.fleet.start() for SDK applications that want the runtime to dispatch parallel sub-agents for a larger objective. Use it when independent subtasks can run concurrently and then be summarized by the main session. For a full guide, see Fleet mode.
The --share option is not available via SDK. Workarounds:
Collect events manually - Subscribe to session events and build your own export:
import type { SessionEvent } from "copilot-sdk-supercharged";
const events: SessionEvent[] = [];
session.on((event) => events.push(event));
// ... after conversation ...
const messages = await session.getEvents();
// Format as markdown yourself
Use CLI directly for export - Run the CLI with --share for one-off exports.
The SDK uses a deny-by-default permission model. All permission requests (file writes, shell commands, URL fetches, etc.) are denied unless your app provides a permissions.onRequest handler.
Instead of --allow-all-paths or --yolo, use the permission handler:
import { approveAll } from "copilot-sdk-supercharged";
const session = await client.createSession({
permissions: {
onRequest: approveAll,
},
});
Instead of /usage, subscribe to usage events:
session.on("assistant.usage", (event) => {
console.log("Tokens used:", {
input: event.data.inputTokens,
output: event.data.outputTokens,
});
});
Instead of /compact, configure automatic compaction or trigger it manually:
// Automatic compaction via config
const session = await client.createSession({
state: {
infiniteSessions: {
enabled: true,
backgroundCompactionThreshold: 0.8, // 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.history.compact();
console.log(`Removed ${result.tokensRemoved} tokens, ${result.messagesRemoved} messages`);
note
Thresholds are context utilization ratios (0.0-1.0), not absolute token counts.
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();
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" });
The SDK can only access features exposed through the runtime's JSON-RPC protocol. If you need a CLI feature that's not available:
| SDK | Supported runtime protocol versions | Earlier runtimes |
|---|---|---|
| Node.js, Python, Go, .NET, Rust, Java | v4 | Not supported: startup fails with a protocol version mismatch error |
Grouped options require protocol v4. Old SDKs reject a v4 runtime; new SDKs reject v3 or earlier before creating or resuming sessions. Neither flat option payloads nor legacy aliases are supported. This startup compatibility boundary does not change persisted-session compatibility: existing sessions and stored event formats remain supported.
If you run your own runtime server, upgrade it together with the SDK so that both use the same protocol version.
Check versions at runtime:
const status = await client.getStatus();
console.log("Protocol version:", status.protocolVersion);
Can you improve this documentation? These fine people already did:
copilot-cli-release-app[bot], Patrick Nikoletich, copilot-sdk-mirror-writer[bot], Steve Sanderson, Don Jayamanne, github-actions[bot], Jeremiah Isaacson, Stephen Toub, examon, Sunbrye Ly & AymenEdit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |