﻿# Codex app-server threads, turns and items explained

Understand thread, turn and item in the Codex app-server protocol, with a minimal initialization sequence and a map from protocol objects to application state.

Author: Retrivium editorial team
Updated: 2026-11-03
Canonical URL: https://retrivium.ai/journal/learn-codex-thread-turn-item/
Language: en

Codex app-server exposes a conversation as structured objects. An integration becomes easier to reason about when it preserves those object boundaries instead of flattening every notification into a single text log. The following payloads are illustrative protocol fragments, not a running application.

## Initialize the connection

The documented connection lifecycle begins with initialize and an initialized notification. Client metadata identifies the integration. This handshake belongs to the connection rather than to a particular repository question. Keep that distinction in a client state machine so reconnecting does not accidentally reuse an uninitialized transport.

```json
{"id":"init","method":"initialize","params":{"clientInfo":{"name":"example_client","version":"example"}}}
{"method":"initialized","params":{}}
```

## Create a conversation object

A thread is the conversation container. The example receives its identifier from the server and stores that value for later operations. The client should not manufacture a thread identifier from a local task label: the application task and the server conversation are related objects with different owners.

```json
{"id":"create","method":"thread/start","params":{}}
{"id":"create","result":{"thread":{"id":"thr_example"}}}
```

## Start the work within that conversation

A turn connects a new user input to the thread. Its work can produce many items, including messages and tool activity. Sending turn/start is an initiating operation, not the final result. The integration must continue consuming the relevant notifications until the turn reaches its documented terminal state.

```json
{"id":"work","method":"turn/start","params":{"threadId":"thr_example","input":[{"type":"text","text":"Summarize the repository"}]}}
```

## Map identifiers to the correct owner

A transport response echoes the request ID, while a notification identifies the affected runtime object in its payload. These are complementary correlation mechanisms. A user interface can keep a pending-request map alongside its thread and turn records. Confusing the maps makes late replies surprisingly difficult to interpret.

| Object | Belongs to | Useful application key |
| --- | --- | --- |
| Thread | Persistent conversation | Associate the conversation with the selected project record. |
| Turn | User request and resulting work | Track the current request without overwriting earlier work. |
| Item | A message, tool call or other work unit | Update the matching operation when a later event arrives. |
| Transport request | Client/server protocol exchange | Match a response to the request that created it. |

## Build the interface from object state

An item can update a command row while a turn remains active. A completed turn can then attach its final status to the corresponding user request. Keeping both levels makes a task view understandable without interpreting every text delta as a new operation. The protocol documentation is the source for concrete event fields and supported methods.

## Documentation and further study

- [Codex App Server](https://learn.chatgpt.com/docs/app-server).

- [Codex as a platform: build on the open agent harness](https://developers.openai.com/blog/codex-as-a-platform).

- [Non-interactive mode](https://learn.chatgpt.com/docs/non-interactive-mode).

Related engineering guides: [Reproducible inference stacks: preserving a GPU pilot’s result](/journal/software-stack-reproducibility/); [Choose a local AI stack: desktop chat, shared UI or coding agent](/journal/local-ai-app-stack-selection/).
