CodexArchitecture & History

From generating a snippet of code to running a complete task.
See how the model, tools, context, and sandbox work together.

Updated · Official docs and source

The model is swappable. The harness keeps the task running.

Pick a surface and a model, then watch which layer changes.

App ServerBidirectional JSON-RPC · default JSONL / stdio
Desktop client → App Server → multiple threads

Manage threads by project, review edits, and organize parallel work. Execution still uses the same harness.

Model

Responses API · reasoning and tool requests

Execution environment

Act only in the authorized scope

  • ShellCommands and tests
  • Git / FilesystemCode, files, and diffs
  • BrowserPages and app actions
  • MCPExternal tools and data
Local workspaceRemote DevboxCloud container
Current diagram: GPT-6 Astra

As of 2026.09.10 it is in eligible Codex accounts; CLI needs 0.153.0+. Changing the model changes reasoning quality and speed. Tools and permissions still belong to the runtime.

=

Codex is an agent product and a runtime system.The model reasons. The harness organizes context, runs tools, and handles feedback. The interface lets you start, follow, and review work.

Agent Loop: act, inspect the result, decide again

A failed build is not the end. Tool errors become the next input to the model.

Worked exampleMove an Astro project to Cloudflare Workers

  1. Task and inputGoal, constraints, and prior record
  2. Build contextInstructions, relevant files, and tool definitions
  3. Model decisionAnswer the user, or propose a tool call
  4. Permission checkApproval policy and accessible scope
  5. Run toolsCommands, files, browser, or MCP
  6. Result and feedbackOutput returns to the model for the next turn
  7. DeliverExplain the change and verification
Tool result → back to the model
Illustrated task logDoes not run real commands
1 / 9

Record the goal: finish the migration and verify the build.

Context is working memory. Threads are the task record.

The model receives the available context each turn. Clients show ongoing work through threads and events.

Context compaction

Capacity diagram

Reading files, inspecting diffs, and running tests all add content the model has to handle.

88%Illustrated context use
Instructions 8%Task 12%Files 24%Tool output 32%Session state 12%

Percentages explain the process. They are not a real token limit or compaction ratio.

How does the task continue after compaction?

  • Keep the task directionThe current goal, key decisions, and open questions need to travel into the next stretch of work.
  • Cut the historical loadLong logs and intermediate steps do not need to be sent in raw form every turn.
  • Re-read when precision mattersCompaction is not a lossless archive. Exact code and the latest state should still be confirmed from files or tools.

The Responses API can return an opaque compaction item that carries prior state in fewer tokens. That is not the same as this readable summary.

Thread → Turn → Item

ThreadA session you can continue
Turn 1 Migrate the project
  • User message
  • Tool execution and output
  • Code diff
  • Agent message
Turn 2 Add tests
  • New user message
  • Tool execution and verification
  • Agent message

A thread holds multiple turns; each turn holds a sequence of items. Persisted history lets a client reconnect, continue, or fork a session.

What does the model actually receive?

instructionsSystem and developer instructions, plus task constraints
toolsDefinitions and parameters for available tools
inputUser messages, project context, tool calls, and tool output

AGENTS.md supplies project rules such as test commands, code conventions, and directory notes. It shapes task context.

API-key mode calls the model through the Responses API. ChatGPT login uses the matching Codex backend. The exact request depends on the chosen provider and client config.

Approvals decide whether to ask. The sandbox limits what can run.

After the model proposes a tool call, execution policy and environment constraints still apply.

Permission contrast

Simplified diagram
Read project filessrc/app.tsAllowed
Edit workspace sourcesrc/app.tsAllowed
Write an ordinary file outside the workspace../notes.txtNeeds approval
Let a command use the networkDownload dependenciesNeeds approval

Assumes the files are reachable, no extra admin policy is in force, and restricted mode has not enabled command networking. “Needs approval” is not the same as already approved. Real permissions also depend on path, platform, and policy.

Limits are enforced in the execution environment

Tool requestApproval policySystem isolation
macOS
Apple Seatbelt / sandbox-exec limits file and network access.
Linux
Isolation uses mechanisms such as bubblewrap. Compatible older policy can still take a Landlock path.
Cloud
The cloud prepares the repo, runs the task, and stores state in an isolated container.

--yolo bypasses approvals and sandbox limits. That changes the execution boundary; it does not make the model smarter. External tools and the browser have their own permission controls.

Extensions: connect tools, and pass along working methods

MCP

Connect external tools and data sources over a standard protocol — code hosts, databases, or business systems.

Skills

Package instructions, resources, and scripts into reusable working methods, loaded when a task needs them.

Plugins

Combine related apps, Skills, and tool integrations into a complete setup for a role or workflow.

From a TypeScript prototype to a Rust runtime

Native execution, terminal interaction, state, and system isolation make up the CLI’s engineering base.

April 2025

TypeScript + Ink

React Ink made it fast to build and iterate on a terminal UI. It required Node.js 22+ at the time.

From May 2025

Rust + Ratatui

The move targeted a standalone binary, native security bindings, lower memory overhead, and an extensible protocol.

Runtime core

Rust · Tokio

Agent state, async work, and process coordination.

core / exec

Terminal UI

Ratatui · Crossterm · Clap

Draw the terminal UI and handle keyboard input and CLI flags.

tui / cli

Model transport

Reqwest · Rustls · WebSocket

Send requests, keep the connection secure, and receive streamed responses.

http-client / backend-client

Client protocol

Serde · JSON-RPC · JSONL

Turn client requests and runtime events into structured messages.

app-server / app-server-protocol

Config and state

TOML · SQLite · SQLx

Read config and persist some local state. Thread history has a separate store.

config / history / rollout

Tools and terminals

rmcp · portable-pty · Tree-sitter

Connect external tools, control terminal child processes, and parse command structure.

rmcp-client / utils/pty

Observability

tracing · OpenTelemetry

Record runtime events to diagnose calls and execution.

otel

System isolation

Seatbelt · bubblewrap · seccomp

Constrain tool execution by platform and policy. Linux still has a compatible Landlock path.

core / linux-sandbox

Items come from the Rust workspace and Core docs. The migration goals above were the team’s engineering notes at the time, not a performance benchmark. Dependencies and module layout change across versions.

Codex timeline

From the code model behind Copilot to an agent system that can call tools and finish tasks.

19 milestones

  1. Model

    GPT-6 Astra arrives in Codex

    As of September 10, official help docs confirm Astra for eligible Codex accounts. The CLI needs 0.153.0 or later. Availability still depends on plan and workspace permissions.

    Models keep iterating. Codex still supplies the tools and task runtime.

    OpenAI Help Center · Original source
  2. Model

    GPT-5.6: Sol, Terra, Luna

    Sol targets complex work, Terra balances capability, speed, and cost, and Luna is for faster, cheaper tasks. Coding, research, and computer use land in one model family.

    Pick a model for the job instead of splitting “regular GPT” from a code model.

    OpenAI · Original source
  3. Product

    Plugins, Sites, and knowledge work

    Role-specific plugins, shareable Sites previews, and result annotations shipped. Analysis, design, and research became explicit product surfaces.

    Deliverables expanded from code to reports, charts, and interactive pages.

    OpenAI · Original source
  4. Product

    Codex can operate the computer and apps

    The desktop app added background computer use, a built-in browser, image generation, memory preview, and more plugins, plus broader automation and SSH development-environment support.

    A task can span the repo, the browser, and desktop apps.

    OpenAI · Original source
  5. Model

    GPT-5.4: coding and general capability converge

    The mainline GPT model absorbed GPT-5.3-Codex coding ability and strengthened computer use and knowledge work.

    Codex as an agent product moved further apart from any one model name.

    OpenAI · Original source
  6. Model

    Codex-Spark: a real-time coding path

    A research preview on Cerebras hardware. At launch it was text-only, with a 128K context and official reports of more than 1,000 tokens/s.

    Alongside long tasks, Codex added a low-latency, rapid-edit working style.

    OpenAI · Original source
  7. Model

    GPT-5.3-Codex: coding joined with reasoning

    It combined GPT-5.2-Codex coding with GPT-5.2 reasoning and domain knowledge, supporting long tasks that include research, tool use, and complex execution.

    Analysis and implementation in one task can stay on the same model.

    OpenAI · Original source
  8. Engineering

    OpenAI published the App Server architecture

    The official write-up unpacked the shared harness, bidirectional JSON-RPC protocol, and Thread / Turn / Item data model, showing how local clients and the cloud attach to the same core.

    Different interfaces can reuse the same execution logic and task events.

    OpenAI · Original source
  9. Product

    Codex App: managing parallel tasks

    A macOS app shipped first, organizing multiple agents by project and independent threads, with worktrees, change review, Skills, and automation entry points.

    Work expanded from a single terminal collaboration to managing many tasks.

    OpenAI · Original source
  10. Model

    GPT-5.2-Codex: long tasks and context compaction

    It strengthened context compaction, reliable tool calls, large-scale refactors and migrations, and improved Windows performance.

    The focus moved from generating a function to finishing complex work in a real codebase.

    OpenAI · Original source
  11. Product

    Codex becomes generally available

    Codex entered GA with an SDK, Slack integration, and admin controls, connecting terminal, editor, and cloud work.

    The agent could be embedded in team workflows and other software.

    OpenAI · Original source
  12. Model

    GPT-5-Codex: a coding model for agents

    Optimized for real software-engineering work: interactive edits, independent long tasks, and code review, used across CLI, IDE, and cloud experiences.

    Training goals moved closer to reading, changing, and testing real projects.

    OpenAI · Original source
  13. Engineering

    Codex CLI announces a move to Rust

    The early TypeScript and React Ink implementation started migrating to Rust, aiming for standalone installs, native security bindings, lower memory overhead, and an extensible protocol.

    CLI engineering shifted toward a native agent runtime.

    OpenAI · GitHub · Original source
  14. Product

    Cloud Codex and codex-1

    Tasks ran in an isolated cloud environment preloaded with the repo, able to read and write files, run tests, and open PRs. codex-1 was an o3 variant optimized for software engineering.

    Developers could hand off a full coding job asynchronously.

    OpenAI · Original source
  15. Product

    Codex CLI: the brand returns as an agent

    An open-source terminal agent shipped with o3 and o4-mini, connecting model reasoning to local code and command execution.

    Give it a goal, and the agent can inspect the project, change code, and verify the result.

    OpenAI · Original source
  16. Model

    First-generation Codex API models retire

    code-davinci-001/002 and code-cushman-001/002 left the API. This refers to the old code models, not the Codex agent product that returned after 2025.

    The first code-completion API ended. Later Codex reused the name.

    OpenAI Docs · Original source
  17. Product

    Codex API opens private beta

    OpenAI opened natural-language-to-code to developers through a private API beta.

    A code-generation model became a service other apps could call.

    OpenAI · Original source
  18. Model

    The Codex paper and HumanEval

    The paper studied a GPT model fine-tuned on public GitHub code and released HumanEval. Codex in the paper scored 28.8% pass@1 on that benchmark.

    Generated programs were measured with executable tests.

    OpenAI · arXiv · Original source
  19. Product

    GitHub Copilot technical preview

    GitHub launched a Copilot technical preview powered by OpenAI Codex, bringing code suggestions into the editor.

    Many developers first used Codex inside an IDE.

    GitHub · Original source

The 2021 unit of workA snippet of code

The modern Codex unit of workA task

Sources

Timeline entries cite sources from the time of publication. Architecture and model availability were checked through September 10, 2026.