Expand description
Synchronous 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.
This is the blocking counterpart to crate::client_async::AsyncClient.
Prefer the async client for applications that already use tokio.
§Lifecycle
- Create a client with
SyncClient::start(spawns and initializes the app-server) - Call
SyncClient::thread_startto create a conversation session - Call
SyncClient::turn_startto send user input - Iterate over
SyncClient::eventsuntilturn/completed - Handle approval requests via
SyncClient::respond - Repeat steps 3-5 for follow-up turns
§Example
ⓘ
use codex_codes::{SyncClient, ThreadStartParams, TurnStartParams, UserInput, ServerMessage};
let mut client = SyncClient::start()?;
let thread = client.thread_start(&ThreadStartParams::default())?;
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,
})?;
for result in client.events() {
match result? {
ServerMessage::Notification { method, .. } => {
if method == "turn/completed" { break; }
}
_ => {}
}
}Structs§
- Event
Iterator - Iterator over
ServerMessages from aSyncClient. - Sync
Client - Synchronous multi-turn client for the Codex app-server.