Skip to main content

Module client_sync

Module client_sync 

Source
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

  1. Create a client with SyncClient::start (spawns and initializes the app-server)
  2. Call SyncClient::thread_start to create a conversation session
  3. Call SyncClient::turn_start to send user input
  4. Iterate over SyncClient::events until turn/completed
  5. Handle approval requests via SyncClient::respond
  6. 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§

EventIterator
Iterator over ServerMessages from a SyncClient.
SyncClient
Synchronous multi-turn client for the Codex app-server.