How to reduce Codex token usage
Codex sends more than your prompt. Every request carries your AGENTS.md chain, the earlier conversation, the output of every command still in context, and the tools your MCP servers add. So the biggest savings come from a shorter AGENTS.md, a fresh session for each task, prompts that name the files, and fewer MCP servers. OpenAI gives the same advice on its Codex pricing page.
Updated 2026-11-16
Where a Codex turn’s tokens go#
A model keeps nothing between requests, so Codex sends the context again each time. Four things fill it:
- The instruction chain. When a session starts, Codex reads your user
AGENTS.md, then one file per folder from the repo root down to your working directory, and joins them. That text stays in context for the whole session. - The conversation. Every earlier message, and every answer.
- Tool output. File reads, command output, test logs and search results stay in context after the step that produced them.
- MCP servers. Each server you attach adds its tools to what the model has to carry.
OpenAI’s pricing page says usage depends on the model and on the size and complexity of the task, and that context, reasoning, tool use and caching all count. It also says prompt length alone is not a reliable estimate. A ten-word prompt in a heavy session can cost more than a long prompt in a fresh one.
Seven things that cut token usage#
1. Shorten AGENTS.md#
Everything in the chain is sent with each request, whether the task needs it or not. Keep the rules the agent needs on every turn. Move the rest out: build steps for one service, a migration checklist, the history of a past decision. For a larger project, OpenAI suggests nesting smaller files inside the folders they apply to, so a session in one folder does not carry the rules for another.
2. Start a new session for a new task#
A long session carries everything that happened in it. When you switch to unrelated work, start fresh. If you need to carry something over, ask Codex for a short handoff note first and paste it into the new session.
3. Name the files and the output#
A broad prompt makes the agent search and read widely. Give it the paths that matter and say what you want back: who it is for, the format and the length. Separate the required work from the optional improvements, so it does not do both by default.
4. Keep long output out of the session#
A full test log or build log read into context stays there. Ask for the failing lines or the last part of the output, not the whole file.
5. Limit MCP servers#
Disable the servers you are not using. This is on OpenAI’s own list of ways to make limits last.
6. Match the model and mode to the job#
Usage depends on the model, and the faster modes draw on your limits at a higher rate than the standard one. Routine edits do not need the largest model or the highest reasoning effort. A local message can also use less of your allowance than a cloud task.
7. Ask for shorter answers#
Output is the most expensive kind of token. Ask for the result, not a walk through how the agent got there.
Doing the first fix with a tool#
MinniMemoryMCP is an MCP server that works in Codex and Claude Code. It reads the AGENTS.md chain a session loads and shows you a map of it: each file, its size, whether it loads, and the cap in force. That alone tells you where the weight is.
$ npm i -g minnimemory
$ minnimemory install --host codex- Open Codex and run
/hooksonce to trust the two minnimemory hooks. Codex skips a hook it does not trust. - Ask Codex to run
init. It maps the chain and previews the split: what stays in AGENTS.md and what moves to files Codex opens only when a task needs them. - Ask it to apply the plan. One
applycovers every file the session loads, each with its own backup, and oneundoputs them all back.
A file Codex already loads whole, under the cap, is left as it is, and init says so. In our tests splitting a small file cost recall, so the split is for a chain that has outgrown the cap. AGENTS.md too large explains the cap.
Our measured session result is from Claude Code, where the same split applies to CLAUDE.md: Measured 15 November 2026: at API rates, a Claude Code session on our test memory cost $0.47 before MinniMemoryMCP 1.6.0 and $0.29 after on average, 37.7% less (each of the three sessions 33.9% to 40.0% less). A blind judge found 80 of 87 answers correct before and 81 after. The method is on the Evidence page.
How to check it worked#
Run /status in a Codex session to see your remaining limits, and compare the same kind of task before and after a change, not two different days of work. If you are on a plan and keep running out, Codex usage limits covers how the windows work. The Claude Code version of this guide is How to reduce Claude Code token usage.