SYSTEM Cited by 2 sources
OpenCode¶
OpenCode is an open-source coding agent whose distinguishing property is its server-first architecture — the CLI, TUI, and desktop app are clients layered on top of a persistent server process. This makes OpenCode programmatically embeddable: sessions can be created, prompts sent, and output streamed via the official SDK without scripting a CLI wrapper.
Cloudflare picked OpenCode as the coding agent of choice for its internal AI code-review orchestration. Stated reasons:
- "We use it extensively internally, meaning we were already very familiar with how it worked."
- Open-source → Cloudflare engineers "have landed over 45 pull requests upstream" at time of writing (2026-04-20).
- SDK enables plugin-based embedding ("easily build plugins that work flawlessly").
- Server-first is the load-bearing architectural choice: "we needed to create sessions programmatically, send prompts via an SDK, and collect results from multiple concurrent sessions without hacking around a CLI interface."
Key embedding primitives (as used by Cloudflare)¶
- Spawn as child process:
Bun.spawn(["bun", opencodeScript, "--print-logs", "--log-level", logLevel, "--format", "json", "--agent", "<agent-name>", "run"], { stdin: Buffer.from(prompt), ... }). - Prompt via stdin, not argv — avoids Linux
ARG_MAX(E2BIG) on large merge-request descriptions full of logs. --format jsonemits JSONL events on stdout (one self-contained JSON object per line). Allows incremental processing without waiting for a trailing].- SDK
session.create/session.promptAsync— programmatically spawn child sessions inside a running server. Each sub-session is its own agent prompt with independent tool access. session.idleevents — primary signal for session completion; backed by 3-second polling fallback.step_finishevents — carryreason+ token usage;reason: "length"indicates hit-the-cap mid-sentence (triggers retry in Cloudflare's orchestrator).errorevents — carry structured error-type unions (APIError,ProviderAuthError,ContextOverflowError,MessageAbortedError, etc.) consumed by Cloudflare's circuit-breaker error classifier.- Runtime plugins — Cloudflare's orchestration defines a
spawn_reviewersplugin tool callable from the coordinator prompt.
Architecture implication¶
The server-first choice places OpenCode in a different architectural class from CLI-first coding agents like Claude Code, Codex CLI, Gemini CLI, Cursor, Crush: programmatic orchestration is a first-class use case, not a bolt-on. JSONL + SDK + stdin make OpenCode viable as a building block for higher-order orchestration systems rather than only as an end-user tool.
Seen in¶
- sources/2026-04-20-cloudflare-orchestrating-ai-code-review-at-scale — Cloudflare's 131k-runs-over-30-days production orchestration; 45+ upstream PRs landed.
- sources/2026-02-24-cloudflare-how-we-rebuilt-nextjs-with-ai-in-one-week — OpenCode as the coding-agent harness for an AI-assisted codebase rewrite. Sunil Pai ran 800+ OpenCode sessions over ~1 week to rebuild the Next.js API surface from scratch on Vite as vinext, for ~$1,100 in Claude API tokens. "I spent a couple of hours going back and forth with Claude in OpenCode to define the architecture: what to build, in what order, which abstractions to use. That plan became the north star." Canonical wiki instance of OpenCode as a framework-rewrite substrate (second orthogonal use case alongside the 2026-04-20 code-review orchestration).
Related¶
- systems/cloudflare-ai-code-review — the production embedding.
- systems/model-context-protocol — Cloudflare's review posts to GitLab via an MCP comment server plugin.
- patterns/jsonl-streaming-child-process — the canonical embedding pattern OpenCode enables.
- concepts/coding-agent-sprawl — the broader landscape OpenCode is one choice within.
- companies/cloudflare