Why Is My Codex CLI Token Usage Suddenly So High? | Diagnosis & Fixes
Problem
My Codex CLI token usage spiked from ~2% per hour to 9% in two hours. and I’m not alone.
I checked my Reddit and and found I wasn’t crazy. Multiple users reported the same thing:
> My codex tokens suddenly have been exhausted over the past week - has something changed?> > 8% daily quota for 20 lines of code changed> > 25% weekly limit burned in 30 minutesEnvironment
- Codex CLI 0.106.0
- ChatGPT Pro plan ($20/month)
- macOS,14.x, Sonoma 14.7.2
What Happened
I was working on a feature implementation when I noticed my weekly usage jumping from 62% to 59% to 62% repeatedly. That bouncing pattern was suspicious.
I decided to analyze my token consumption. Here’s what I found
User: killtheperfectDate: 2026-02-27Sessions: 62Token-count events: 4,499The output shocked me:
- Median context per turn: ~96k tokens
- p95 context per turn: ~200k tokens
- Baseline startup overhead: 21-22k tokens (up from 12-15k)
- Shell tool outputs: 90.3% of all tool-output characters
The Root Cause
I discovered three culprits:
1. Shell Tool Output Explosion
┌──────────────────────────────────────────────────────────────┐│ User Request │└──────────────────────────────────────────────────────────────┘ │ ▼ ┌────────────────────────┐ │ System Prompt (21k) │ └────────────────────────┘ │ ▼ ┌─────────────────────────────────────────────────────────────┐ │ Shell Commands (rg, git diff, cat logs) │ │ 90.3% of context window │ └─────────────────────────────────────────────────────────────┘ │ ▼ ┌─────────────────┐ │ Token Exhaustion │ └─────────────────┘Every rg search, git diff, and test output got dumped into my context window.
2. Elevated Baseline Overhead
- Previous: 12-15k tokens per session startup
- Current: 21-22k tokens per session startup
- Increase: ~50-60% more overhead before any real work
This started around version 0.106.0 based on community reports.
3. Context Accumulation
- Session starts with 21k overhead
- First shell command adds 10-50k tokens
- Context compaction hasn’t occurred yet
- By turn 5-10, I’m at 100k+ tokens consistently
How to Diagnose
I tried Codex’s built-in diagnostic tools.
Check Rate Limits:
{ "method": "account/rateLimits/read", "id": 1 }Response:
{ "usedPercent": 87, "windowDurationMins": 10080, "resetsAt": "2026-03-03T00:00:00Z"}Monitor Real-Time Usage:
{ "method": "thread/tokenUsage/updated", "params": { "threadId": "thr_123", "usage": { "totalTokens": 96000, "promptTokens": 94000, "completionTokens": 2000 }}The promptTokens field showed my context window was bloated with shell output.
Solutions
I tried several approaches to reduce consumption.
Attempt 1: Limit Shell Output (Partial Success)
# Beforerg "authentication" .# Afterrg "authentication" --max-count=10 -lThis helped, but I was still hitting high usage because of accumulated context.
Attempt 2: Manual Compaction (Better)
{ "method": "thread/compact/start", "id": 25, "params": { "threadId": "thr_b" } }This reduced context by ~40%, but I had to trigger it manually.
Attempt 3: Switch to Mini Model (Best Results)
For routine tasks like refactoring and documentation updates, I switched to GPT-5.1-Codex-Mini:
Result: ~4x reduction in token consumption for simple tasks.
What Actually Worked
After experimenting, I found these strategies reduced my consumption by 60-80%
1. Targeted Shell Commands
# Bad: Full diffgit diff main...feature
# Good: Summary firstgit diff --stat main...feature | head -20git diff main...feature -- src/auth/ | head -1002. Manual Compaction Trigger compaction after large outputs:
{ "method": "thread/compact/start", "id": 25, "params": { "threadId": "thr_current" } }3. Use Mini for Routine Tasks Switch to GPT-5.1-Codex-Mini for:
- Simple refactoring
- Documentation updates
- Small bug fixes
4. Disable Unused MCP Servers Each MCP server adds context. Disable when not needed.
5. Precise Prompts
- Bad: “Help me fix the authentication issue”
- Good: “Fix the JWT validation error in
/src/auth/jwt.tsline 45. The error is ‘invalid signature’.”
Quick Reference Checklist
Before Session:
- Disable unused MCP servers
- Review AGENTS.md for redundancy
- Choose appropriate model (Mini for routine tasks)
During Session:
- Use targeted shell commands with output limits
- Monitor token usage via notifications
- Trigger compaction after large outputs
After Session:
- Check rate limit status
- Review which commands consumed most tokens
- Consider forking threads for new tasks
Summary
In this post, I diagnosed why my Codex CLI token usage suddenly spiked. The key points are:
- Shell tool outputs consume 90%+ of context
- Baseline overhead increased 50-60% (12-15k to 21-22k tokens)
- Proactive management reduces usage by 60-80%
Start with account/rateLimits/read to assess your current state, then apply targeted shell commands and manual compaction to keep your context window lean.
Final Words + More Resources
My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me
Here are also the most important links from this article along with some further resources that will help you in this scope:
- 👨💻 OpenAI Codex Official Documentation
- 👨💻 Codex CLI GitHub Repository
- 👨💻 OpenAI Platform Pricing Page
Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!
Comments