Expand description
Asynchronous multi-turn client for the Codex app-server.
Spawns codex app-server --listen stdio:// and communicates over
newline-delimited JSON-RPC. The connection stays open for multiple
turns until explicitly shut down.
§Lifecycle
- Create a client with
AsyncClient::start(spawns and initializes the app-server) - Call
AsyncClient::thread_startto create a conversation session - Call
AsyncClient::turn_startto send user input - Consume
AsyncClient::next_messageto stream notifications - Handle approval requests via
AsyncClient::respond - Repeat steps 3-5 for follow-up turns
- The client kills the app-server on
Drop
§Example
ⓘ
use codex_codes::{AsyncClient, ThreadStartParams, TurnStartParams, UserInput, ServerMessage};
let mut client = AsyncClient::start().await?;
let thread = client.thread_start(&ThreadStartParams::default()).await?;
client.turn_start(&TurnStartParams {
thread_id: thread.thread_id().to_string(),
input: vec![UserInput::Text { text: "Hello!".into() }],
model: None,
reasoning_effort: None,
sandbox_policy: None,
}).await?;
while let Some(msg) = client.next_message().await? {
match msg {
ServerMessage::Notification { method, params } => {
if method == "turn/completed" { break; }
}
ServerMessage::Request { id, method, .. } => {
client.respond(id, &serde_json::json!({"decision": "accept"})).await?;
}
}
}Structs§
- Async
Client - Asynchronous multi-turn client for the Codex app-server.
- Event
Stream - Async stream of
ServerMessages from anAsyncClient.