Inspecting Codex Request Payloads Reveals 9,400 Token Overhead per Prompt
A deep-dive investigation into Codex CLI 0.145.0 request payloads shows that a simple 16-character prompt generates a 43 KB HTTP JSON request. Bundled instructions, environment context, and tool definitions consume over 9,400 input tokens before any user code executes.
Why it matters
Understanding payload overhead is critical for developers managing token costs, context window limits, and latency when building or using CLI-based AI agents.
TL;DR
- 01Codex CLI adds ~9,400 tokens of system framing, tool definitions, and metadata to initial prompts.
- 02AGENTS.md files are merged hierarchically from repo root to the execution working directory.
- 03Large command outputs are truncated but still increase payload size significantly before triggering history compaction.
Payload Decomposition and Initial Baseline
Capturing raw JSON HTTP requests from Codex CLI 0.145.0 reveals significant prompt wrapping. A basic 16-character user input (Reply with pong.) produces a raw request body of 42,980 bytes. When encoded using o200k_base, the payload estimates at approximately 9,435 tokens. The wrapped prompt accounts for roughly 25 tokens (~0.3% of the request payload), while system framing, permissions, context metadata, and bundled tools make up the remaining 99.7%.
Instruction Chaining across AGENTS.md Files
Codex builds instruction chains by scanning upward from the working directory to the repository root:
- Starting in a child directory automatically aggregates
AGENTS.mdfrom the root down to that child folder. - Executing file listing commands like
ls childfrom the root does not trigger automatic loading ofchild/AGENTS.mdinto the instruction chain. - Synthetic markers demonstrate that instruction text is passed verbatim in subsequent requests, directly impacting the prompt baseline.
Output Truncation and History Compaction
Command execution output is appended directly into execution history. While a 10,000-line log is pruned to head-and-tail samples, payload size still spikes from ~9,584 tokens to 25,835 tokens. Compaction triggers when approaching configured limits (e.g., a 12,000 token threshold), executing a dedicated summary request (68,375 bytes / ~21,408 tokens) before rebuilding conversation history around retained messages.