What Is the Continue SDK and How to Use It: A Developer’s Guide
The Continue SDK is a TypeScript programmatic interface that provides direct access to the IDE, LLM, and context management capabilities of the Continue AI-assistant platform.
The Continue SDK serves as the architectural backbone of the continuedev/continue repository, enabling developers to build custom slash commands, tools, and external scripts that interact with the core AI assistant engine. This editor-agnostic interface abstracts away the complexity of IDE integrations and language model providers, offering a unified API for file system operations, chat streaming, and context manipulation.
Core Architecture and Components
The Continue SDK acts as a runtime façade that stitches together three essential pillars of the Continue platform. According to the source code in core/index.d.ts (lines 3890-3905), the ContinueSDK interface exposes these key members:
ide: IDE– Provides IDE-agnostic access to file systems, diffing, terminal operations, and LSP navigation across VS Code, JetBrains, and other supported editors via the Model Context Protocol.llm: ILLM– Holds the language model instance (OpenAI, Anthropic, Bedrock, or custom providers) with low-level completion and chat helpers.- Context and Session State – Includes
history,input,contextItems,selectedCode,config, and afetchwrapper for managing conversation state, user selections, and HTTP requests respecting proxy configurations.
Interface Implementation
The concrete implementation is instantiated through the factory method Continue.from. The wrapper function initializeContinueSDK in extensions/cli/src/continueSDK.ts (lines 13-30) handles API key validation and parameter forwarding to Continue.from, returning a fully-configured ContinueClient instance that implements the ContinueSDK interface.
How to Initialize the Continue SDK
To obtain a ready-to-use SDK instance in a Node.js environment or CLI script, import the initialization helper from the @continuedev/sdk package.
import { initializeContinueSDK } from "@continuedev/cli/src/continueSDK";
const apiKey = process.env.CONTINUE_API_KEY;
const assistantSlug = "my-assistant";
const orgId = "org-123";
async function main() {
// Returns a fully-wired Continue SDK instance
const sdk = await initializeContinueSDK(apiKey, assistantSlug, orgId);
// Stream a chat completion through the configured LLM
const generator = sdk.llm.streamChat(
[{ role: "user", content: "Explain the observer pattern in 2 sentences." }],
new AbortController().signal,
{},
sdk.fetch,
);
for await (const chunk of generator) {
process.stdout.write(typeof chunk === "string" ? chunk : JSON.stringify(chunk));
}
}
main().catch(console.error);
This initialization pattern creates three core objects:
- An
IDEimplementation (e.g.,VscodeIDEorJetbrainsIDE) communicating via the Model Context Protocol client. - An
ILLMimplementation configured fromconfig.jsonor custom client-supplied models. - A
ContinueConfigobject merging configuration files, environment variables, and runtime overrides.
Building Custom Slash Commands with the Continue SDK
The Continue SDK enables the creation of custom slash commands that receive the SDK instance through their run method signature: run(sdk) => AsyncGenerator<string>.
Adding Context Items Programmatically
The following example demonstrates accessing the IDE API and injecting context items into the model's context window:
import { ContinueSDK, ContextItemWithId } from "@continuedev/sdk";
export const myCommand = {
name: "summarizeSelection",
description: "Summarize the currently highlighted code.",
async *run(sdk: ContinueSDK) {
// Access file system through the IDE abstraction
const file = await sdk.ide.getCurrentFile();
if (!file) {
yield "No file open.";
return;
}
// Create and inject a context item
const ctx: ContextItemWithId = {
id: { providerTitle: "selection", itemId: "1" },
content: file.contents,
name: "selectedFile",
description: "User-selected code snippet",
};
sdk.addContextItem(ctx);
// Stream the LLM response
const prompt = "Summarize the above code in plain English.";
const generator = sdk.llm.streamChat(
[{ role: "user", content: prompt }],
new AbortController().signal,
{},
sdk.fetch,
);
for await (const chunk of generator) {
yield chunk;
}
},
};
Register this command in your config.json under slashCommands to expose it in the Continue interface.
Creating Custom Tools Using the Continue SDK
Beyond slash commands, the Continue SDK supports custom tools that integrate with the Model Context Protocol runtime. Tools receive ToolExtras containing the SDK's IDE interface.
import { Tool, ToolExtras } from "@continuedev/sdk";
export const readFileTool: Tool = {
type: "function",
function: {
name: "read_file",
description: "Read a file from the workspace and return its contents.",
parameters: {
type: "object",
properties: { path: { type: "string" } },
required: ["path"]
},
},
displayTitle: "Read File",
readonly: false,
group: "filesystem",
async preprocessArgs(args, { ide }) {
const workspaceRoot = await ide.getWorkspaceDirs();
return { ...args, path: `${workspaceRoot[0]}/${args.path}` };
},
async evaluate(args: { path: string }, extras: ToolExtras) {
const contents = await extras.ide.readFile(args.path);
return [{
content: contents,
name: args.path,
description: "File content",
uri: { type: "file", value: args.path }
}];
},
};
Add this tool to config.json under tools or via toolOverrides. When ModelCapability.tools is enabled, the SDK exposes these functions to the LLM for autonomous execution.
Summary
- The Continue SDK is defined in
core/index.d.ts(lines 3890-3905) and provides typed access to IDE operations, LLM interactions, and context management. - Initialize the SDK using
initializeContinueSDKfromextensions/cli/src/continueSDK.ts, which internally callsContinue.fromto wire up IDE and LLM implementations. - The SDK supports three primary extension patterns: slash commands (via
run(sdk)generators), custom tools (via the Tool interface), and external scripts (direct SDK consumption). - All SDK methods respect the user's
config.json, environment variables, and proxy settings through the built-infetchwrapper andContinueConfigmerging.
Frequently Asked Questions
How do I install the Continue SDK in my project?
Install the @continuedev/sdk package via npm or yarn. For CLI usage, import initializeContinueSDK from @continuedev/cli/src/continueSDK. The SDK requires Node.js and functions in VS Code extensions, standalone scripts, web workers, or any JavaScript runtime that supports the Model Context Protocol.
What is the difference between Continue.from and initializeContinueSDK?
Continue.from is the core factory method that instantiates the SDK by creating IDE and LLM implementations. initializeContinueSDK is a convenience wrapper in extensions/cli/src/continueSDK.ts (lines 13-30) that validates API keys and forwards parameters to Continue.from, returning a ContinueClient ready for immediate use.
Can I use the Continue SDK without VS Code?
Yes. The Continue SDK is editor-agnostic. While it can create VscodeIDE or JetbrainsIDE implementations, it also functions in headless CLI scripts, custom applications, or web workers. The IDE interface abstracts the underlying editor, allowing the same code to run across different environments via the Model Context Protocol.
How do I add custom context to the LLM using the SDK?
Call sdk.addContextItem() with a ContextItemWithId object containing the content, name, and description. This method is available on all SDK instances and is commonly used within slash commands to inject file contents, selected code ranges, or external data into the model's context window before streaming a response.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →