Skip to content

Architecture

This overview follows the public Codex CLI 0.172.0 source tree. A thread carries conversation state. A turn starts with an input, can receive more input through steering, and may make several model requests before it completes. App Server turn entry · Core turn loop

Client input ──────→ Thread and turn
│
▼
History + instructions + tool schemas
│
▼
Model request
│
┌─────────┴──────────┐
▼ ▼
Tool request Assistant output
│ │
▼ ▼
Tool execution Completion checks
│
└────→ Record tool result
and request again
Component Responsibility
Client interface App Server turns a request into thread input and can send it to a turn already in progress. Turn submission
Turn loop Takes a history snapshot for the next model request and tracks whether the response or queued input requires follow-up. Turn loop
Model interface Represents model-visible input as a prompt with conversation items, tools, and instructions. The client formats those inputs into a provider request. Prompt type · Request builder
Tool runtime Converts a returned function call into a tool invocation, preserving its arguments and call ID. The execution layer applies the applicable approval and sandbox rules. Tool router · Tool orchestrator
History Records tool results for subsequent model calls. The runtime also has a path for reconstructing history from stored rollout items when a thread resumes. Record results · History reconstruction
When you need to know… Look at…
Which context and tools reached the model The provider request’s ordered input and, where present, its tools field. Prompt Construction
Which text and item updates core made available to a client The emitted item lifecycle and delta events. To verify what a particular UI displayed, inspect that client as well. Model Requests and Streaming
What command result the model could use The tool-result item in the next provider request. Compare its call_id with the original call. Tool-call assertion
Whether an active turn received a new user message Match the steering reply’s turn ID, the notification’s client message ID, and the user item in a later provider request. Steering an Active Turn
Which context survived reopening the thread Reconstructed model-visible input in the first request after resume. Compaction and Resume

For the CSV exercise, the displayed score report is one observation point. The command exit status and the provider’s copy of its output are separate evidence. Start with the point that can answer your question.

This diagram describes the path exercised in the first chapter. Start with One Turn, One Tool Call to see what the mock provider receives. Use the source map to look up a specific component.