codex-codes
A tightly typed Rust interface for the OpenAI Codex CLI JSON protocol.
This crate provides type-safe Rust representations of the Codex CLI's JSONL output format, mirroring the structure of the official TypeScript SDK.
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
Example
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;
License
Apache-2.0