techlist.io
OpenAI2026-02-035 min read

Curated summary

Unlocking the Codex harness: how we built the App Server

Read original(opens in new tab)

Codex App Server: One Harness Behind Every Surface

OpenAI's Codex runs across the web app, CLI, IDE extensions, and macOS app, all powered by the same agent harness. The Codex App Server, a bidirectional JSON-RPC API, is the layer that exposes that harness to clients. The post explains why the App Server was created, how its architecture and conversation primitives work, how different surfaces integrate with it, and how it compares to other ways of embedding Codex.

Origin of the App Server

  • The App Server began as a practical way to reuse the harness in the VS Code extension without re-implementing the agent loop in the IDE.
  • An early experiment exposed Codex as an MCP server, but mapping VS Code's rich interactions (workspace exploration, streaming reasoning, diffs) onto MCP semantics proved difficult.
  • The team instead introduced a JSON-RPC protocol that mirrored the TUI loop. This became the unofficial first version of the App Server, which was not originally designed as a stable API.
  • Growing demand from internal teams and partners (JetBrains, Xcode, and the Codex desktop app orchestrating parallel agents) pushed the team to design a stable, backward-compatible surface.

Inside the Codex Harness

  • Thread lifecycle and persistence: creating, resuming, forking, and archiving threads, and persisting event history so clients can reconnect.
  • Config and auth: loading configuration and handling flows such as "Sign in with ChatGPT."
  • Tool execution and extensions: running shell and file tools in a sandbox and wiring in MCP servers and skills under a consistent policy model.
  • All of this lives in "Codex core," which is both a library containing the agent code and a runtime that runs the loop for one thread.

Architecture of the App Server

  • The App Server is a long-lived process that hosts Codex core threads and also defines the JSON-RPC protocol between client and server.
  • It has four main components: the stdio reader, the Codex message processor, the thread manager, and core threads.
  • The thread manager starts one core session per thread. The message processor submits client requests to those sessions and receives their updates.
  • The stdio reader and message processor translate JSON-RPC requests into core operations and convert low-level internal events into a small set of stable, UI-ready notifications.
  • The protocol is fully bidirectional. The server can issue its own requests, such as approval prompts, and pause the turn until the client responds.

Conversation Primitives

  • Item: the atomic unit of input or output, typed as a user message, agent message, tool execution, approval request, or diff. Each item follows item/started, optional item/*/delta events, then item/completed.
  • Turn: one unit of agent work started by a user input and ending when the agent finishes responding to it. A turn contains a sequence of items.
  • Thread: a durable container for an ongoing session, containing multiple turns, with persisted history.
  • Handshake: the client must send initialize first, with clientInfo, and the server responds with its userAgent string. This lets both sides agree on protocol version, feature flags, and defaults.
  • Typical flow: the client creates a thread and a turn. The server sends thread/started and turn/started, then streams items for user input, tool calls, and agent output. Approvals pause the turn until the client replies "allow" or "deny." The turn ends with turn/completed.
  • A test client is available via codex debug app-server send-message-v2 "<prompt>" to inspect full JSON for a turn.

Integrating with Clients

All three patterns use JSON-RPC over stdio (JSONL). Bindings exist in Go, Python, TypeScript, Swift, and Kotlin. TypeScript definitions can be generated with codex app-server generate-ts, and JSON Schema with codex app-server generate-json-schema.

  • Local apps and IDEs: the client bundles or fetches a platform-specific binary, runs it as a long-lived child process, and pins it to a tested version. Partners like Xcode keep the client stable and point it at newer server binaries, so they get core improvements without waiting for client releases. The protocol is backward compatible, so older clients work with newer servers.
  • Codex Web: a worker provisions a container with the checked-out workspace and runs the App Server inside it. The browser talks to the backend over HTTP and SSE. State lives on the server, so work continues if the tab closes, and a new session can reconnect and catch up.
  • TUI/CLI: the TUI was historically a special-case client that talked directly to Rust core types. The team plans to refactor it to use the App Server like any other client. This would enable connecting to a remote Codex server while keeping the UI local.

Choosing the Right Protocol

  • Codex as an MCP server (codex mcp-server): good for existing MCP workflows that invoke Codex as a tool, but Codex-specific features like diff updates may not map cleanly.
  • Cross-provider agent harness protocols: portable across model providers and useful for coordinating multiple agents, but they tend to converge on a common subset of capabilities.
  • Codex App Server: the recommended choice for full functionality, including sign-in, model discovery, and configuration. The cost is building a JSON-RPC client, though Codex can help generate it from the schema and docs.
  • Codex Exec: a scriptable CLI mode for one-off tasks and CI pipelines with structured output and clear exit codes.
  • Codex SDK: a TypeScript library for controlling local agents from your own application. It supports fewer languages than the App Server and may gain SDKs that wrap the App Server protocol.

Taking This Forward

The App Server is the first-class integration method going forward. Its source is in the open-source Codex CLI repository, and the team is actively seeking feedback and feature requests. Teams wanting to embed Codex in their own tools should start with the App Server, using the generated schema bindings to build a client.

Continue with another curated summary.