Skip to content

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 json emits 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.idle events — primary signal for session completion; backed by 3-second polling fallback.
  • step_finish events — carry reason + token usage; reason: "length" indicates hit-the-cap mid-sentence (triggers retry in Cloudflare's orchestrator).
  • error events — 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_reviewers plugin 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

Last updated · 200 distilled / 1,178 read