Codex token usage
Where Codex's tokens go,
and how to use fewer.
We took our longest recorded Codex sessions apart to see what the model is actually sent. Most of it isn't the conversation. It's command output and files read through the shell, sent again on every turn.
1. Every turn re-sends the whole session.
Each request Codex makes includes everything so far. Over a long session, the content sent to the model added up to a median of about 170 times the largest context the session held. Cached input is billed at a lower rate, but it is still billed.
2. Most of it is the shell.
Codex reads files with shell commands, so file contents and command output together made up more than half of the input in our longest sessions, weighted by how often each piece was re-sent:
| Content | Share of Codex input |
|---|---|
| Command output | 30% |
| File contents read | 28% |
| Your messages | 19% |
| Commands and scripts the agent wrote | 18% |
| The agent's own replies | 3% |
| Code it wrote into files | under 1% |
Measured from recorded Codex CLI transcripts. The system prompt and tool definitions aren't in transcripts and aren't counted. Your mix will differ with your work. For the same breakdown on Claude Code, see why Claude Code uses so many tokens.
3. A lot of it is the same file twice.
About half of all file-reading output was a file the session had already read. The earlier copy was still in the context and was sent again on every turn after.
How to check your usage
In the Codex CLI, /status shows the current session's token usage. Watch it over a long session: it grows with every command that prints a lot.
What helps
- A new chat for unrelated work:
/new. Everything in the context is re-sent until the session ends. - Compact before the context is at its largest:
/compact. - Short command output: line ranges instead of whole files,
rg -lbeforerg,| tailon long logs. You can ask for this inAGENTS.md. - Densilo, which does this automatically. It runs on your machine between Codex and the model. Old output the model has already seen is sent in short form, and the full text is kept so the model can fetch it back exactly. In our replays of long Codex sessions, it sent up to 57% fewer tokens (median 32%) and cut input cost by up to 49% (median 22%). Codex support is in beta. How we measured, and what a replay doesn't show.
Want the cost side? The token cost calculator works for Codex too: choose Codex and enter your own input price.
See your own number.
Install Densilo and run densilo benchmark in a repository you work in. It replays your recent Codex and Claude Code sessions offline: no model is called and nothing leaves your machine.