Scope: Verified against Codex documentation on June 22, 2026.
The safe way to reduce Codex token spend is to optimize only while fixed quality gates remain unchanged. “Without reducing quality” should not mean trusting that a shorter transcript looks equally good. It means defining requirements, tests, static checks, and review criteria before the run, then rejecting any cheaper setup that performs worse against those gates.
This principle applies across the Codex CLI, IDE extension, app, and cloud, but the budget appears differently on each surface. ChatGPT users generally consume included usage, rate limits, or credits rather than receiving a direct token invoice. API-key users pay standard, model-specific API rates. Context usage affects how much information fits in a thread, while latency is simply elapsed time. These are related operational constraints, not interchangeable measurements. See the official Codex pricing, authentication, and API pricing documentation.
1. Define and measure the budget
A Codex thread contains more than the prompt and final answer. Codex gathers file contents, tool output, model responses, and the ongoing work record; all of it must fit in the model’s context window. Long logs and broad file reads can therefore consume context even when the final response is short. Codex may compact long threads automatically, but compaction summarizes and discards detail rather than making context free (Prompting Codex).
Measure four separate outcomes:
- Context: input tokens, cached input tokens, and remaining context capacity.
- Generated tokens: output tokens and reasoning-output tokens.
- Account cost: API charges, ChatGPT credits, or rate-limit consumption.
- Operational efficiency: elapsed time, turns, failed verification, and corrective attempts.
For a reproducible comparison, use this proposed method rather than relying on anecdotes:
- Choose five representative tasks. Give each task a saved prompt, a fixed starting commit, an exact verification command, and a written review checklist.
- Create a baseline profile and one candidate profile. Change one variable at a time. If testing context discipline, keep the model and reasoning effort fixed; test model changes separately.
- Run each task three times per profile from a clean copy of the same commit. Use a new noninteractive thread for every initial run.
- Capture the event stream:
codex exec --profile baseline --json - \
< prompts/task-01.txt > results/task-01-baseline-1.jsonl
- Immediately filter the completion event instead of printing the full machine-readable stream into another model context:
jq -c 'select(.type == "turn.completed") | .usage' \
results/task-01-baseline-1.jsonl
- Run the predefined verification command outside Codex. Record pass or fail. If it fails, take the exact session ID from the
thread.startedevent, resume that thread with the verification log and the fixed instruction, “Make the smallest correction required to pass the stated gate,” and save each corrective turn to another JSONL file. Stop after three corrective attempts and record failure if the gate still does not pass. - Store one row per task and repetition with: profile, input tokens, cached input tokens, output tokens, reasoning-output tokens, completed turns across all JSONL files, verification result, and corrective-attempt count. Compare medians only after confirming that requirement, test, and review outcomes are equivalent.
codex exec --json emits JSONL events, and its turn.completed usage object reports input_tokens, cached_input_tokens, output_tokens, and reasoning_output_tokens (Non-interactive mode). This article does not claim benchmark results; the procedure is a way to produce evidence for your own workload.
2. Establish quality gates first
Token reduction often fails because the task was underspecified. A five-word prompt can trigger exploration, assumptions, rework, and repeated checks. OpenAI recommends giving Codex a goal, relevant context, constraints, and a definition of done, and recommends including reproducible validation steps (Codex best practices).
Use a prompt shape like this:
Goal: Fix duplicate invoice creation in the retry path.
Context: Start with src/billing/retry.ts and tests/billing/retry.test.ts.
Constraints: Preserve the public API and database schema. Do not refactor
unrelated billing code.
Done when: The regression test and billing unit suite pass, and the final
diff contains no unrelated changes.
For higher-risk work, add type checks, linting, security checks, performance thresholds, or a human review rubric. Keep these gates identical across the baseline and candidate runs. A configuration that uses fewer tokens but needs more corrective turns, misses requirements, or produces a riskier diff is not an improvement.
3. Reduce irrelevant context and tool output
Point Codex toward likely files and explicitly exclude generated code, dependencies, build artifacts, coverage output, and unrelated services. Prefer targeted search and line-range reads over printing whole trees or large files. Run the smallest relevant test first, then expand only when the risk or failure requires it.
Filter command output before it enters the thread:
rg "InvoiceRetry" src tests
git status --short
git diff --stat
npm test -- retry.test.ts --runInBand
Machine-readable output is useful only when it is immediately filtered to the fields needed for the decision. Raw JSONL, verbose test reporters, and full CI logs can be larger than concise human-readable output. Preserve the failing assertion, stack trace, and summary; omit repeated successes and unrelated diagnostics. Codex also has a tool_output_token_limit setting, but a hard cap is a backstop because truncation can hide the actual error (Configuration reference).
Use AGENTS.md for durable routing and verification commands, but understand discovery correctly. Codex loads one global instruction file, then walks from the project root down to the directory where the run started, loading at most one instruction file per directory. It does not universally load a nested AGENTS.md merely because it later edits a file beneath that directory. Start Codex in the relevant subtree when those nested instructions must apply, and keep instruction files concise because they enter context at startup (AGENTS.md guide).
The self-published Caveman project is a Claude API output-style benchmark, not evidence about Codex, reasoning tokens, or total task cost. Its useful lesson is limited: removing filler can reduce visible output, but terse prose does not compensate for irrelevant reads, noisy tools, or retries.
4. Match model and reasoning effort to the task
Use the least expensive setup that still passes the fixed gates. OpenAI currently recommends gpt-5.5 for demanding Codex work and gpt-5.4-mini as a faster, lower-cost option for lighter coding tasks. Reasoning effort can be low for well-scoped mechanical changes and medium or high for complex debugging; higher effort uses more tokens and can consume limits faster (Codex models and IDE features).
Do not reduce model capability, reasoning effort, and context simultaneously in the first experiment. If the candidate fails, you will not know which change caused it. Escalate deliberately when ambiguity, concurrency, security, or repeated failed verification demonstrates the need.
Fast mode is a latency control, not a savings control. With ChatGPT sign-in it makes supported models faster while consuming credits at a higher rate; API-key users instead remain on standard API pricing. Use /fast off when the objective is credit efficiency rather than response speed (Codex speed).
Cloud tasks currently do not expose local model selection, so optimize them through task scope, repository instructions, environment setup, and verification rather than a local profile (Codex models).
5. Manage threads, compaction, and subagents
Keep one thread aligned to one objective. In the CLI, /status reports session configuration, token usage, and remaining context capacity. /compact summarizes the conversation to free context, while /new or /clear starts a fresh conversation when prior investigation is no longer relevant. /usage is account-level ChatGPT activity or rate-limit monitoring; it is not a per-run benchmark. These controls and their current meanings are documented in the CLI slash-command reference.
Compact at a phase boundary, such as after diagnosis or implementation, rather than repeatedly. Start a new thread when a task changes materially. Resume only when previous decisions and repository state are still useful.
Subagents can keep noisy exploration out of the main thread and reduce elapsed time for independent work, but they do not reduce total token consumption. Each subagent performs its own model and tool work, so comparable multi-agent runs consume more tokens. Reserve them for parallel research, test analysis, or independent review dimensions where isolation or speed justifies the extra cost (Subagent concepts).
6. Apply a concise reusable configuration
The CLI supports named profiles stored as separate files under CODEX_HOME, which defaults to ~/.codex. For example:
# ~/.codex/economy.config.toml
model = "gpt-5.4-mini"
model_reasoning_effort = "low"
model_verbosity = "low"
Run it with codex --profile economy or codex exec --profile economy "task". Profile files use top-level keys; current Codex no longer reads legacy [profiles.name] tables from config.toml (Advanced configuration). model_verbosity applies to Responses API providers (Advanced configuration).
The CLI, IDE extension, and app share configuration layers (Codex best practices). For this workflow, the CLI provides named profiles, its slash-command interface, and codex exec --json usage events (profiles, slash commands, and noninteractive mode). Keep project-specific paths and checks in the repository’s AGENTS.md, and use the profile only where its model choice passes your gates.
Every concise final report should still preserve four review outputs:
- changed behavior;
- checks run;
- results;
- unresolved risks.
That is the quality boundary: spend fewer tokens only when those outputs and the underlying verification outcomes remain intact.
Top comments (0)