Codex Agent Loop
Use this skill when you need the durable mental model for how Codex actually runs: how the initial request is assembled, how inference and tool calls loop within a turn, how conversation state grows across turns, and where model_instructions_file, AGENTS.md, and local guidance enter.
Read Order
- Read
references/unrolling-the-codex-agent-loop.mdfor the end-to-end model of threads, turns, items, and tool iteration. - Read
references/building-the-initial-prompt.mdfor the first request, prompt item ordering, tool definitions, and SSE event flow. - Read
references/conversation-growth-and-performance.mdfor prompt growth, exact-prefix caching, statelessness,previous_response_id, ZDR, and compaction. - Read
references/openai-codex-prompt-loading.mdonly when exactmodel_instructions_file,AGENTS.md, or project config semantics matter. - Read
references/prompt-layering.mdonly when deciding what belongs in the base prompt versus local guidance or mutable context.
Core Model
- A
threadis the durable conversation container. - A
turnbegins with a new user request and may contain many inference and tool-call iterations before it ends. - The Responses API request surface is structured as
instructions,tools, andinput; the server derives the actual prompt shape from those parts. - Tool calls are part of the normal loop, and their outputs are appended back into later
inputitems. - Stable early prompt content matters because it affects both behavior and prompt caching efficiency.
Use This Skill Well
- Start with the conceptual reference before reading the lower-level details.
- If the question is narrow, load only the specific reference that answers it.
- Keep the distinction between base
instructions, laterinput, and appended tool outputs explicit. - Preserve the blog's mental model: a turn is not a single model call, and the loop does not end until the assistant emits a final message for that turn.
- Use the embedded SVGs in the references when you want the original diagrams in context.
- Reach for exact docs via MCP when configuration or current product behavior matters.
Reference Policy
- Treat
references/unrolling-the-codex-agent-loop.mdas the main reusable explanation another agent should remember. - Treat
references/building-the-initial-prompt.mdandreferences/conversation-growth-and-performance.mdas the detailed mechanics that preserve most of the blog's substance. - Fetch official docs via
openaiDeveloperDocsbefore answering questions about exact current prompt loading,AGENTS.mddiscovery, fallback filenames, byte limits, config keys, or other evolving behavior. - Treat
references/openai-codex-prompt-loading.mdas a local helper summary of official guidance, not a replacement for checking current docs when precision matters.
Fetch First For
model_instructions_fileand config-key semanticsAGENTS.mddiscovery order, fallback filenames, and byte limits- project-scoped
.codex/config.tomlbehavior - current Codex config reference details
- any question phrased as latest, current, official, exact, or up to date
References
references/building-the-initial-prompt.mdreferences/conversation-growth-and-performance.mdreferences/unrolling-the-codex-agent-loop.mdreferences/openai-codex-prompt-loading.mdreferences/prompt-layering.md