How to reduce Codex token usage
Save Codex tokens with focused context, shorter tool output, useful prompts, and fewer repeat reads. Includes Mikie setup and troubleshooting.
The quick answer
Reduce Codex token usage by giving it a clear result, the relevant code and tests, and a stopping point. Limit repeated reads and oversized output. Use Mikie for focused repository context, then judge the change by completed work and observed usage.
Find the repeated work first
A short question can lead to a large coding session: repository searches, file reads, logs, patches, and repairs. Look for the files and commands that keep returning. For a login bug, begin with its handler, session helper, and failing test.
Reading an entire directory before establishing the failure may add context without resolving a decision. Preserve callers and constraints that genuinely affect the patch.
| Pattern | Next action |
|---|---|
| Same untouched file again | Reuse anchored context |
| Large routine log | Send the result or actionable failure |
| Unrelated modules explored | Name the behavior and boundary |
| Speculative repairs | Reproduce the failure first |
Give Codex a finish line
Put the behavior, scope, and check in one request. Add a path when known, while allowing another read for a demonstrated dependency. This makes both success and the reason for a follow-up clear.
Fix the login redirect loop. Start with the login handler and its tests. Keep the public API unchanged. Add a regression for an expired session, run the relevant auth tests, and stop when they pass. Summarize changed behavior and unresolved failures.Make reads answer a question
Request a function or line range before a whole file. Search matching paths and lines before surrounding source. Keep full logs locally; give the agent exact failures it can act on. Refresh changed code instead of replaying broad discovery.
- Name the decision before requesting a read.
- Keep shared instructions concise and close to their code.
- Enable integrations needed for the task.
- Preserve exact failures and relevant traces.
Put Mikie on the context path
Use Node.js 22 or newer and a Mikie account. Installation docs include supported platforms and the Windows npm.cmd alternative. Open Codex in the repository after setup.
Use the MCP server named mikie and its current schemas. build_context_packet supplies a task packet; rank_relevant_files supports focused follow-ups when appropriate.
npm install -g @getmikie/cli@latest
mikie login
mikie setup codex
mikie doctor
# After completing a task:
mikie usageRepair gaps without restoring a context dump
Add a missing caller or configuration when the agent lacks a dependency. For a wrong repair, provide the reproducible input and failing assertion. Use mikie doctor's actual output if setup fails.
Compare similar accepted tasks under the same model and settings. A lower token count with an incomplete fix is not an improvement. Use the API cost guide for metered bills and the limits guide for included allowance.
- Requested behavior works.
- Relevant checks ran.
- Scope remained coherent.
- Usage, retries, and missing fields are visible.
Put it into practice
- Define the finished behavior and proof command.
- Gather relevant source through Mikie.
- Patch and run the declared checks.
- Review accepted quality, usage, and retries.
| Area | What it means | Who controls it |
|---|---|---|
| Repository context | Read relevant functions, callers, and tests before expanding. | Your workflow |
| Command output | Keep actionable failures; summarize routine output. | Your workflow |
| Follow-ups | Send the changed fact and next decision. | Your workflow |
| Correctness | Retain the information and checks the change needs. | The provider or measurement |
| Billing | Subscription allowance and API billing use different accounting. | The provider or measurement |
How Mikie helps
Mikie gives Codex line-anchored context through its local MCP integration. Run mikie setup codex and inspect mikie usage. Active runs with accepted quality and complete provider receipts support measured comparisons; shadow projections are estimates.
Sources
- OpenAI ↗
Included allowance, credits, API-key billing, usage checks, and usage factors.
- OpenAI ↗
Goals, relevant context, output requirements, and task boundaries.
Provider plans and prices can change. Source dates show when this guide was checked. How Mikie measures results.
Common questions
How do I save Codex tokens?
Reduce repeated reads, keep tool output relevant, and name the acceptance check. Retain the context needed for a correct change.
Does a shorter prompt always cost less?
No. Tools, output, caching, settings, and repairs also matter. Inspect the completed task.
Does this setup apply to ordinary ChatGPT chats?
These commands configure Codex. Task-scoping advice helps ordinary chats, but those chats do not automatically use the local Mikie integration.
Put better context to work.
Keep your coding agent. Give it a clearer view of the code it needs.
Set up Mikie →