What is OpenCode?
OpenCode is a coding agent. It keeps sessions, each a transcript in its database. For each answer it asks a model, runs the tools the model calls, and asks again until the model is done. OpenCode 2 is built to run inside a Cloudflare Durable Object: its database is the object’s SQLite, and it needs no machine of its own.
Take one small app: a Coder Durable Object with a session pr-142. OpenCode runs in the object. Its model requests are answered by the Fast model’s Layer, and its call to your deploy tool runs the tool’s handler, both in the same isolate. The bash tool needs a shell, which a Durable Object does not have, so it runs its command in the session’s sandbox on Boat.
- holds
- files · shell
The harness
Section titled “The harness”The harness is OpenCode with what you give it: the models sessions may run on, and the tools they may use. You yield it in a Durable Object’s outer Effect, and OpenCode starts in that object when a session is first used.
const harness = yield* OpenCode.Harness({ models: [Fast], tools: [AI.CodingTools, Deploy] });Sessions
Section titled “Sessions”A session is one OpenCode session. You name it, and the harness finds it by that name in the object’s storage.
const session = harness.session("pr-142");See Sessions & prompts.
Prompts
Section titled “Prompts”A prompt is one message to a session. It returns when OpenCode has answered, through every tool call that took.
const reply = yield* session.prompt("Fix the failing test.", { requestId: "msg-81" });Model requests
Section titled “Model requests”OpenCode is configured with one model provider, and the harness answers it: each request is handed to the AI.Model Layer of the model the session runs on. No request for a model leaves the isolate through OpenCode, and it holds no API key.
See Model requests.
Your tools are registered with OpenCode and run in the Durable Object, where their bindings are. The model sees each as alchemy_<name>.
See Tools.
Processes
Section titled “Processes”An AI.Process describes work as prose and names no harness. OpenCode.HarnessLive runs its sessions as OpenCode sessions.
The sandbox
Section titled “The sandbox”A Durable Object has no files and no shell. A tool that needs either uses AI.Sandbox, and the harness opens one sandbox per session for those tools. A session whose tools need neither never has one.
How @alchemy.run/opencode models these concepts
Section titled “How @alchemy.run/opencode models these concepts”OpenCode.Harness is an Effect you yield where its Layers are provided. Models, tools, MCP servers and sandboxes are the @alchemy.run/ai declarations, unchanged. OpenCode.HarnessLive is the same harness as a Layer, for processes. OpenCodeCloudflare.DurableObjectStorage runs OpenCode on the Durable Object’s SQLite and keeps its alarm armed while a prompt runs, so an evicted object wakes up and the prompt resumes. OpenCode.CodingTools provides the shared coding tools, each working in the session’s sandbox.