Sign In

@opencode-ai/sdk

Package Overview
Dependencies
Maintainers
2
Versions
11006
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opencode-ai/sdk

In-process OpenCode host for Promise and Effect applications. The SDK executes Server's assembled HTTP router in memory, opening no listener and adding no network hop.

npmnpm
Version
0.0.0-dev-18128
Version published
Weekly downloads
12M
41.51%
Maintainers
2
Weekly downloads
 
Created
Source

@opencode-ai/sdk

In-process OpenCode host for Promise and Effect applications. The SDK executes Server's assembled HTTP router in memory, opening no listener and adding no network hop.

import { OpenCode } from "@opencode-ai/sdk"

await using opencode = await OpenCode.create()
const session = await opencode.sessions.create({
  location: { directory: "/workspace" },
})

Pass imported Promise plugins in plugins, or register one later with await opencode.plugin(plugin).

The Promise API uses the same values, errors, request options, and AsyncIterable streams as @opencode-ai/client.

Embedded hosts are silent by default. Set log to receive structured log entries:

await using opencode = await OpenCode.create({
  log: {
    level: "warn",
    emit: (entry) => console.error(entry.message, entry.attributes, entry.cause),
  },
})

close() and Symbol.asyncDispose release router resources, Location services, fibers, and scoped plugin registrations.

Workerd

Use the Workerd entrypoint inside a Cloudflare Durable Object. Hold one host for the lifetime of the object instance rather than creating one per request.

import { OpenCodeWorkerd } from "@opencode-ai/sdk/workerd"
import myPlugin from "./my-plugin"

export class OpenCodeDO {
  private readonly opencode: Promise<OpenCodeWorkerd.Interface>

  constructor(state: DurableObjectState) {
    this.opencode = state.blockConcurrencyWhile(() =>
      OpenCodeWorkerd.create({
        storage: state.storage,
        config: { default_agent: "build" },
        plugins: [myPlugin],
      }),
    )
  }

  async fetch() {
    const opencode = await this.opencode
    return Response.json(await opencode.health.get())
  }
}

blockConcurrencyWhile keeps every Durable Object event out until the host is ready and resets the object if initialization fails. The retained Promise gives request handlers direct access to the same host after startup. Configuration is a typed JavaScript object, and plugins are imported values bundled with the Worker.

Effect

The Effect-native API remains available from @opencode-ai/sdk/effect:

import { OpenCode } from "@opencode-ai/sdk/effect"

const opencode = yield * OpenCode.create()
const session = yield * opencode.sessions.get({ sessionID })

The Effect Workerd entrypoint is @opencode-ai/sdk/workerd/effect.

FAQs

Package last updated on 24 Aug 2026

Related posts