Cutting Claude Code and Codex token usage: /context, /compact, prompt caching, and model routing
How to cut Claude Code and Codex token spend and stretch usage limits: /context, /compact, /clear, prompt caching, subagents, and local usage tracking.


The short answer
Coding-agent bills and 5-hour limits burn fastest from one thing: re-sending a bloated context window on every turn. Use /clear between unrelated tasks, /compact with explicit keep-instructions during long tasks, subagents to isolate big file reads and test logs, and cheaper models for routine edits.
| Habit | Command / setting | Why it saves tokens |
|---|---|---|
| Start fresh on a new task | /rename then /clear (Claude Code); /new (Codex) | Stops old file reads from being re-sent on every message |
| Compact with focus | /compact Focus on test output and code changes | Replaces long history with a targeted summary while reloading rules |
| Inspect context & cache | /context and /usage (Claude Code); /status (Codex) | Shows what is taking space and whether prompt cache is hitting |
| Isolate noisy reads | Use subagents (or cheaper subagent model like haiku) | Only the short summary returns to your main context window |
| Match model to the task | /model and /effort | Save Opus / GPT-6.2 Astra for hard reasoning; use Sonnet / Sol for routine edits |
What fills your context before you even type
In Claude Code, several pieces load before your first prompt: the system prompt, root CLAUDE.md (or AGENTS.md), auto memory, skill descriptions, and MCP tool names. Every file read, hook output, and test run adds on top — and every subsequent turn processes that growing prefix again.
- Check
/contextin Claude Code to see the live breakdown of what is occupying space. - Check
/usage›Prompt cache (main)(v2.1.251+): it reports what share of input tokens hit cache, how many cache misses happened, and from v2.1.260 the likely cause of the last miss (such as tool definitions changing). - Trim unused MCP servers with
/mcp: Anthropic notes that plain CLI tools likegh,aws, orgcloudadd zero per-tool listing overhead compared with MCP servers.
/compact vs. /clear: what actually survives
When you run /compact, Claude Code summarizes the conversation history and automatically re-injects your system prompt, root CLAUDE.md, unscoped rules, auto memory, rebuilt skill descriptions (v2.1.304+), any plan written in plan mode, and a fresh git status snapshot. Path-scoped rules and nested subdirectory CLAUDE.md files reload on demand.
# Compact instructions
When compacting, preserve failing test commands, exact error messages, and the list of files already modified.Tracking cache hit rate and routing cheaper models in Mirasim
Provider billing pages only show your total account spend, not which repo or session burned the budget. Mirasim keeps a local ledger on your machine and lets every pane pick its own model and reasoning level.
- Local Usage page: view call count, total tokens, output tokens, cache hit rate, and estimated cost broken down by agent, model, account, workspace, and individual session — down to single calls.
- Mix models across panes: keep one pane on Claude Opus 5.5 or GPT-6.2 Astra for design work, while adjacent panes run Sonnet 5.5, DeepSeek, Kimi, or a local Ollama model with zero Mirasim credit.
- Pay per token on Mirasim credit when you want discounted API access without extra subscriptions: Claude Sonnet 5.5 50% off, Opus 5.5 50% off, GPT-6.2 Sol Limited time: 90% off off official API prices.
Chapter 17 · Usage and cost › Finding where the money went → Finding where agent spend goes in Mirasim's Usage page.
Questions
- Does
/compacterase myCLAUDE.mdrules? - No. Claude Code re-injects your root
CLAUDE.md, unscoped rules, auto memory, and plan mode plan from disk after compaction; nestedCLAUDE.mdfiles reload on demand. - Why did my prompt cache hit rate suddenly drop?
- Changing active MCP tools, switching models mid-session, letting the cache TTL expire while idle, or running compaction rebuilds the prefix. In Claude Code v2.1.260+,
/usagenames the likely cause on thePrompt cache (main)line. - How do I cap spend for a single Claude Code CLI run?
- Pass
--max-budget-usd <amount>when running Claude Code on API billing so the run stops once estimated cost reaches that cap.
Article · Claude Code pricing: what each plan costs, what the API costs, and paying only for what you use → Claude Code pricing: plans vs. API rates.
Article · Claude Code usage limits: what the messages mean, and how to keep working → Claude Code's 5-hour and weekly usage limits, and how to keep working.
Article · Subagents in Claude Code and Codex: what they are and how to make your own → Using subagents in Claude Code and Codex to isolate big reads and tasks.
Article · Agentic coding is cheap per call, but expensive per hour → Why agentic coding is cheap per call but adds up per hour.
Article · Claude Code /rewind and /undo: checkpoints, what isn't tracked, and branching sessions → Undoing edits with Claude Code `/rewind` and `/undo`, plus visual rewind and branching in Mirasim.
Article · Setting up Claude Code and Codex in a monorepo or large codebase → Configuring Claude Code and Codex for a monorepo: nested instructions, Read deny rules, and sparse worktrees.
Sources
Checked on November 29, 2026 against Anthropic's Claude Code docs (code.claude.com/docs: Manage costs effectively, Explore the context window) and OpenAI's Codex command docs (learn.chatgpt.com/docs). Check those pages for the latest commands and cache stats.
Keep reading

Fixing OpenAI and Codex 403 “unsupported_country_region_territory”
Why OpenAI and Codex return 403 unsupported_country_region_territory, how to fix false positives on VPNs or cloud IPs, and compliant alternatives.

Running Claude Code and Codex on Amazon Bedrock, Vertex AI, and Microsoft Foundry
Connect Claude Code and Codex to Amazon Bedrock, Vertex AI, and Microsoft Foundry: env vars, config.toml, auth, model pinning, and limits.

Using Claude Code with Chrome and Codex Browser: live debugging, Playwright, and previews
How to connect Claude Code to Chrome (extension, console logs, login limits) and use Codex Browser or Playwright, plus live dev-server previews in Mirasim.