Liking cljdoc? Tell your friends :D

SDK and CLI Compatibility

This document outlines which Copilot CLI features are available through the SDK and which are CLI-only.

Overview

The Copilot SDK communicates with the 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

FeatureSDK MethodNotes
Session Management
Create sessioncreateSession()Full config support
Resume sessionresumeSession()With infinite session workspaces
Destroy sessiondestroy()Clean up resources
Delete sessiondeleteSession()Remove from storage
List sessionslistSessions()All stored sessions
Get last sessiongetLastSessionId()For quick resume
Messaging
Send messagesend()With attachments
Send and waitsendAndWait()Blocks until complete
Get historygetMessages()All session events
Abortabort()Cancel in-flight request
Tools
Register custom toolsregisterTools()Full JSON Schema support
Tool permission controlonPreToolUse hookAllow/deny/ask
Tool result modificationonPostToolUse hookTransform results
Available/excluded toolsavailableTools, excludedTools configFilter tools
Models
List modelslistModels()With capabilities
Set modelmodel in session configPer-session
Reasoning effortreasoningEffort configFor supported models
Authentication
Get auth statusgetAuthStatus()Check login state
Use tokengithubToken optionProgrammatic auth
MCP Servers
Local/stdio serversmcpServers configSpawn processes
Remote HTTP/SSEmcpServers configConnect to services
Hooks
Pre-tool useonPreToolUsePermission, modify args
Post-tool useonPostToolUseModify results
User promptonUserPromptSubmittedModify prompts
Session start/endonSessionStart, onSessionEndLifecycle
Error handlingonErrorOccurredCustom handling
Events
All session eventson(), once()40+ event types
Streamingstreaming: trueDelta events
Advanced
Custom agentscustomAgents configLoad agent definitions
System messagesystemMessage configAppend or replace
Custom providerprovider configBYOK support
Infinite sessionsinfiniteSessions configAuto-compaction
Permission handleronPermissionRequestApprove/deny requests
User input handleronUserInputRequestHandle ask_user
SkillsskillDirectories configCustom skills

❌ Not Available in SDK (CLI-Only)

FeatureCLI Command/OptionReason
Session Export
Export to file--share, /shareNot in protocol
Export to gist--share-gist, /share gistNot in protocol
Interactive UI
Slash commands/help, /clear, etc.TUI-only
Agent picker dialog/agentInteractive UI
Diff mode dialog/diffInteractive UI
Feedback dialog/feedbackInteractive UI
Theme picker/themeTerminal UI
Terminal Features
Color output--no-colorTerminal-specific
Screen reader mode--screen-readerAccessibility
Rich diff rendering--plain-diffTerminal rendering
Startup banner--bannerVisual element
Path/Permission Shortcuts
Allow all paths--allow-all-pathsUse permission handler
Allow all URLs--allow-all-urlsUse permission handler
YOLO mode--yoloUse permission handler
Directory Management
Add directory/add-dir, --add-dirConfigure in session
List directories/list-dirsTUI command
Change directory/cwdTUI command
Plugin/MCP Management
Plugin commands/pluginInteractive management
MCP server management/mcpInteractive UI
Account Management
Login flow/login, copilot auth loginOAuth device flow
Logout/logout, copilot auth logoutDirect CLI
User info/userTUI command
Session Operations
Clear conversation/clearTUI-only
Compact context/compactUse infiniteSessions config
Plan view/planTUI-only
Usage & Stats
Token usage/usageSubscribe to usage events
Code Review
Review changes/reviewTUI command
Delegation
Delegate to PR/delegateTUI workflow
Terminal Setup
Shell integration/terminal-setupShell-specific
Experimental
Toggle experimental/experimentalRuntime flag

Workarounds

Session Export

The --share option is not available via SDK. Workarounds:

  1. Collect events manually - Subscribe to session events and build your own export:

    const events: SessionEvent[] = [];
    session.on((event) => events.push(event));
    // ... after conversation ...
    const messages = await session.getMessages();
    // Format as markdown yourself
    
  2. Use CLI directly for export - Run the CLI with --share for one-off exports.

Permission Control

Instead of --allow-all-paths or --yolo, use the permission handler:

const session = await client.createSession({
  onPermissionRequest: async (request) => {
    // Auto-approve everything (equivalent to --yolo)
    return { approved: true };
    
    // Or implement custom logic
    if (request.kind === "shell") {
      return { approved: request.command.startsWith("git") };
    }
    return { approved: true };
  },
});

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,
  });
});

Context Compaction

Instead of /compact, configure automatic compaction:

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
  },
});

Note: Thresholds are context utilization ratios (0.0-1.0), not absolute token counts.

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:

  1. Check for alternatives - Many features have SDK equivalents (see workarounds above)
  2. Use the CLI directly - For one-off operations, invoke the CLI
  3. Request the feature - Open an issue to request protocol support

Version Compatibility

SDK VersionCLI VersionProtocol Version
Check package.jsoncopilot --versiongetStatus().protocolVersion

The SDK and CLI must have compatible protocol versions. The SDK will log warnings if versions are mismatched.

See Also

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close