codex-codes
A typed Rust interface for the OpenAI Codex CLI JSONL protocol.
Part of the rust-code-agent-sdks workspace.
Overview
This crate provides type-safe Rust representations of the Codex CLI's JSONL output format, mirroring the structure of the official TypeScript SDK. It is a pure types crate with no feature flags and is WASM-compatible out of the box.
Tested against: Codex CLI 0.104.0
Installation
Types
Events (ThreadEvent)
Discriminated union of all events emitted during thread execution:
thread.started— Thread initialized with an IDturn.started/turn.completed/turn.failed— Turn lifecycleitem.started/item.updated/item.completed— Item lifecycleerror— Thread-level error
Items (ThreadItem)
Discriminated union of all agent action items:
agent_message— Text output from the modelreasoning— Chain-of-thought reasoningcommand_execution— Shell command with output and exit codefile_change— File modifications (add/delete/update)mcp_tool_call— MCP tool invocationweb_search— Web search querytodo_list— Task tracking listerror— Error item
Options
ThreadOptions— Per-thread configurationApprovalMode— Tool execution approval policySandboxMode— File system access controlModelReasoningEffort— Reasoning effort levelWebSearchMode— Web search behavior
Usage
use ;
let event_json = r#"{"type":"thread.started","thread_id":"th_abc"}"#;
let event: ThreadEvent = from_str.unwrap;
let item_json = r#"{"type":"agent_message","id":"msg_1","text":"Hello!"}"#;
let item: ThreadItem = from_str.unwrap;
Parsing a JSONL stream
use ThreadEvent;
License
Apache-2.0. See LICENSE.