Codex · Updated 2026-10-09
Reduce Codex CLI Token Usage: Compress Tool Output in Codex
Codex runs shell commands, reads files and calls MCP tools, and every result it reads stays in the session for later turns. Here is where Codex CLI tokens go, the habits that cut them, and how SuperCompress keeps only the lines that answer the task Codex is working on.
AGENTS.md short and turn off MCP servers you don't need. Then run npm install -g supercompress-proxy && supercompress setup so Codex can compress bulky shell and MCP output against your current request. It works with a ChatGPT sign-in or an API key.
Where Codex tokens go
- Shell output. Test runs, builds, installs and
gitcommands return their full output. - File reads. Whole files come back even when one function matters.
- MCP servers. Each enabled server adds tool definitions, and MCP results can be large.
- Instructions.
AGENTS.mdfiles are loaded into the session.
Habits that cut Codex token usage for free
- One task per session. Start a new session for unrelated work instead of continuing a long one.
- Compact long sessions. Use
/compactwhen a session has gathered a lot of output you no longer need. - Keep
AGENTS.mdshort. Put long reference material in files Codex reads only when needed. - Limit MCP servers and tools. Only enable the servers a project uses.
- Ask for narrow commands. Running one failing test instead of the whole suite keeps the output small.
These habits shrink what goes in. They don't help when the agent genuinely needs to run a test suite or read a large file and only a few lines of the output matter. That is the part SuperCompress handles.
How SuperCompress works
SuperCompress is hosted, extractive and query-aware. Your agent sends a large block of context (a log, a diff, a file read, an MCP result) together with the question it is working on. Our Neural Keep model scores the lines against that question, keeps the original lines that answer it, and drops the rest. It never rewrites or summarizes, so file paths, error messages, IDs and code come back exactly as they were. The question itself is never compressed.
Every compress call reports original_tokens and kept_tokens, so you can see what was dropped on your own work instead of trusting a headline number. The usage_summary MCP tool shows totals per agent for your account.
What supercompress setup adds to Codex
| What | Where | What it does |
|---|---|---|
| MCP server | ~/.codex/config.toml ([mcp_servers.supercompress]) | Gives the agent the compress_context, connect_account and usage_summary tools. |
| Instructions | ~/.codex/AGENTS.md | Tells Codex to pass bulky output through compress_context with your request as the query, and never to compress the request itself. |
| Hooks | ~/.codex/hooks.json | UserPromptSubmit and PostToolUse hooks. After large tool calls, the hook compresses the new output against your request and passes the kept lines to Codex as extra context. |
Install
npm install -g supercompress-proxy && supercompress setup
Setup links your SuperCompress account in the browser, detects the coding agents on the machine and wires each one. Restart the agent so it loads the new MCP server. Then check what is wired up:
supercompress doctor
doctor prints a per-agent health check. supercompress uninstall removes only the entries SuperCompress added. Setup backs up each config file before it edits it.
When to skip it
- Short sessions with small tool results. There is little to drop.
- Files the agent is about to edit line by line. It needs those in full.
- Work where every byte must be passed through unchanged for compliance reasons.
FAQ
Does SuperCompress work when I sign in to Codex with ChatGPT?
Yes. SuperCompress works through MCP, instructions and hooks, not through Codex's model connection, so it works with a ChatGPT sign-in as well as with an API key.
Does SuperCompress change how I sign in to Codex?
No. You keep your normal Codex login and models. SuperCompress adds an MCP server and instructions to Codex; it does not route Codex's model traffic through a proxy.
Does SuperCompress summarize what Codex reads?
No. It is extractive. The lines it keeps are copied from the original output, so file paths, error messages and code stay exactly as they were.
How do I undo the Codex setup?
Run supercompress uninstall. It removes only the entries SuperCompress added, so your other MCP servers, hooks and instructions stay as they were.