Expand description
Standalone async Rust client for the Codex CLI’s app-server v2 JSON-RPC
protocol.
codex app-server is the interface Codex uses to power rich clients (the
VS Code extension, the Codex app). This crate spawns (or connects to) an
app-server process, speaks its newline-delimited JSON-RPC 2.0 wire format,
and exposes every v2 method as a typed async function.
This crate has zero dependencies on anything else in the workspace it
lives in - only published crates.io dependencies - so it can be lifted
into another project wholesale. See README.md for how its vendored
protocol schema was derived and how to regenerate it.
§Quick start
use codex_app_server_client::{CodexSession, DenyAllApprovalHandler, SessionOptions};
let mut session = CodexSession::spawn(SessionOptions::new("my_integration", "0.1.0")).await?;
let result = session
.run_text_turn_with_model_and_handler(
"gpt-5",
"Say hello in one sentence.",
&DenyAllApprovalHandler::default(),
)
.await?;
println!("{}", result.agent_message());Modules§
Structs§
- Allow
AllApproval Handler - Approval handler that approves Codex approval requests.
- Async
FnApproval Handler - Approval handler backed by an async closure.
- Codex
AppServer Client - Async client for the Codex app-server v2 JSON-RPC protocol.
- Codex
Daemon - Codex
Session - High-level app-server session that owns a client plus event stream.
- Compatibility
Report - Deny
AllApproval Handler - Approval handler that rejects every server request with a JSON-RPC error.
- Event
Collector - Event
Stream - Receives
Events from one app-server connection. - FnApproval
Handler - Approval handler backed by a closure.
- Pending
Server Request - A server->client request the app-server sent us (approvals, elicitation,
etc.), paired with a one-shot reply channel. Obtain these from
EventStream::recvas anEvent::Request. - Read
Only Approval Handler - Approval handler for read-only integrations.
- Session
Options - Options used when creating a high-level
CodexSession. - Surface
Summary - Text
Turn Result - Result of a one-shot text turn.
Enums§
- Error
- Errors returned by
crate::CodexAppServerClient. - Event
- An event pushed from the app-server connection. Deliberately not
#[non_exhaustive](contrastError, which explains its own opposite choice) - this models a closed, stable three-way split of “shape of thing the app-server can send,” not an open-ended taxonomy, so callers matching on it exhaustively (as this crate’s own code does everywhere) get a compile error if a variant is ever added, rather than silently ignoring the new case via a wildcard arm. - Server
Request Reply - A typed reply for a server-to-client app-server request.
Constants§
- CLIENT_
NOTIFICATION_ METHOD_ COUNT - CLIENT_
REQUEST_ METHOD_ COUNT - CODEX_
SCHEMA_ VERSION - DEFAULT_
CALL_ TIMEOUT - Default timeout for
CodexAppServerClient::call_request(and therefore every generated per-method wrapper). Override withCodexAppServerClient::with_call_timeout. This bounds one request/response round trip - it has nothing to do with how long a turn takes to finish generating, since that streams viacrate::Event::Notificationinstead of blocking the request that started it. - DEFAULT_
EVENTS_ CHANNEL_ CAPACITY - Default capacity of the internal channel from the reader task to
EventStream, used byCodexAppServerClient::spawn,CodexAppServerClient::connect_streams, andCodexAppServerClient::connect_unix. Bounded (rather than unbounded) so a stalled or absent consumer grows memory by a fixed amount, not without bound, if events keep arriving faster thanEventStream::recvis called - see that type’s doc comment for the drop policy once this fills up. - MAX_
LINE_ BYTES - Hard cap on a single NDJSON line’s size. Without this, a single huge or
unterminated line from a buggy or malicious app-server peer would grow
read_line’s buffer without bound. 64 MiB comfortably covers legitimate large payloads (e.g.fs/readFileresults, big diffs) while still being a real, finite bound. - SERVER_
NOTIFICATION_ METHODS - All 68 server notification methods this crate can decode: [“account/login/completed”, “account/rateLimits/updated”, “account/updated”, “app/list/updated”, “command/exec/outputDelta”, “configWarning”, “deprecationNotice”, “error”, “externalAgentConfig/import/completed”, “externalAgentConfig/import/progress”, “fs/changed”, “fuzzyFileSearch/sessionCompleted”, “fuzzyFileSearch/sessionUpdated”, “guardianWarning”, “hook/completed”, “hook/started”, “item/agentMessage/delta”, “item/autoApprovalReview/completed”, “item/autoApprovalReview/started”, “item/commandExecution/outputDelta”, “item/commandExecution/terminalInteraction”, “item/completed”, “item/fileChange/outputDelta”, “item/fileChange/patchUpdated”, “item/mcpToolCall/progress”, “item/plan/delta”, “item/reasoning/summaryPartAdded”, “item/reasoning/summaryTextDelta”, “item/reasoning/textDelta”, “item/started”, “mcpServer/oauthLogin/completed”, “mcpServer/startupStatus/updated”, “model/rerouted”, “model/safetyBuffering/updated”, “model/verification”, “process/exited”, “process/outputDelta”, “remoteControl/status/changed”, “serverRequest/resolved”, “skills/changed”, “thread/archived”, “thread/closed”, “thread/compacted”, “thread/deleted”, “thread/goal/cleared”, “thread/goal/updated”, “thread/name/updated”, “thread/realtime/closed”, “thread/realtime/error”, “thread/realtime/itemAdded”, “thread/realtime/outputAudio/delta”, “thread/realtime/sdp”, “thread/realtime/started”, “thread/realtime/transcript/delta”, “thread/realtime/transcript/done”, “thread/settings/updated”, “thread/started”, “thread/status/changed”, “thread/tokenUsage/updated”, “thread/unarchived”, “turn/completed”, “turn/diff/updated”, “turn/moderationMetadata”, “turn/plan/updated”, “turn/started”, “warning”, “windows/worldWritableWarning”, “windowsSandbox/setupCompleted”]
- SERVER_
NOTIFICATION_ METHOD_ COUNT - SERVER_
REQUEST_ METHOD_ COUNT
Traits§
- Approval
Handler - Policy hook for server-to-client app-server requests.
Type Aliases§
- Approval
Future - Boxed future returned by
ApprovalHandler. - Result