← Back to Blog

guide

Oct 22, 2026

Verify, don't trust: measuring token waste in Claude Code and Codex.

Most coding-agent token waste comes from resending tool output every turn. Measure it on your own Claude Code and Codex sessions before changing a thing.

Every tool result in a coding-agent session is sent again on the next turn. The model only knows what is in the current request, so the client resends the conversation so far: the files it read, the search results, and the command output.

That is why Claude Code token usage can jump on a long task even when each command looked small. The same pattern shows up in Codex token usage. Before you change settings or trust a "cut your bill" claim, measure the waste on your own sessions.

A token is a chunk of text the provider counts and prices. A short line can be a handful of tokens. A full file read can be thousands. This guide uses one illustrated example, then shows how to measure your real sessions.


The resend multiplier

Suppose a tool result first appears on turn 5, and the session continues through turn 200. That result is included again on each of the next 195 turns. One read costs about its size times 195, in input tokens, if nothing drops it from the history. Each new result adds its own repeats. A 200-turn session is only an example. Many sessions are shorter, and some are longer.

Worked example. A 1,000-token tool result from turn 5 through turn 200 is about 195,000 input tokens of repeated context (1,000 × 195). Use your own file size and session length when you estimate a real session. The shape of the repeat is what this example is for.

Caching makes repeats cheaper. It does not delete them

Anthropic and OpenAI both discount input that matches a cached prefix.

On Anthropic's API, a cache read is often about one tenth of the base input price. Some current models are lower than that. Writing the cache costs more than a normal input token: 1.25× for the default 5-minute cache, and 2× for a 1-hour cache. The default entry lasts about 5 minutes and is refreshed when it is used. Details and the per-model table are on Anthropic's prompt caching page. OpenAI's discount depends on the model. Check the current price page before you budget.

Three limits stay even when the discount is large:

  1. A cheaper token is not a free token.
  2. A change early in the prompt can miss the cache, so later turns pay the full price again.
  3. Cached text still occupies the context window. When the window fills, the agent drops or summarizes older material and the task gets worse. The window size depends on the model. Do not assume 128k.

Claude Code also has manual controls, including /compact and /clear, documented in Manage costs effectively. They help one developer. They are hard to apply the same way across a team.


Where the waste shows up

These are patterns ReclaimLLM's Signals detectors look for. They are not a claim that every team has all of them.

The same file, again and again. Inside one session, an agent often re-reads a file it already has. Across sessions, Signals P2 (Groundhog files) flags files that many sessions open to recover context that could live in one project note.

Huge search results and noisy commands. A broad grep or a verbose test run can add tens of thousands of tokens of paths and logs. Search shaping and command-output compaction exist to shrink those results. They do not "understand" the code. They trim or fold output that matches a known shape.

Starting over, or never starting over. P1 (restart churn) is the same project work beginning again instead of continuing from a handoff. P5 (session bloat) is one session that keeps growing past the point where that person usually finishes.

Carrying too much, or using a heavy model for a light task. P9 (context-weight burn) is a session whose cached context on each tool call is far above that person's normal baseline. P10 (model-task mismatch) is a costly model used for work that person usually finishes with a cheaper model. The detector compares models you already use. It does not require a specific model name.

The same failed call in a loop. The Claude Code loop breaker is on by default. After two identical repeats it adds a note. After four it asks you before the tool runs again. It does not silently kill the session. The installer documents this breaker as Claude Code behavior.

The catalog and the admin view are in the Signals docs and the model analysis walkthrough. AI coding anomalies need evidence, not another black box explains why these are rules with a trail, not a second model guessing.


Step 1: measure in shadow mode before you change behavior

A normal install does not wait in shadow mode. Read caching, the loop breaker, compression, and DLP are on by default, and they rewrite what the model sees. Shadow mode is the switch that keeps the measurement and skips the rewrite.

rclm-hooks-install --shadow-mode

Supported mechanisms still record an estimate. They do not change model-visible input or output. The agent sees the original tool result.

Those local estimates are not your invoice. Several of them use a rough characters-divided-by-four count. Provider usage, when the response includes it, is separate: cache-read and cache-creation tokens can be stored as reported by the API, and a session can be marked as real usage or as an estimate. Enterprise → Tokens is the project view for that split. Docs: tokens dashboard.

Return to rewriting with:

rclm-hooks-install --no-shadow-mode

You do not pass --read-cache or --compress to turn those on. They are already on. Pass --no-read-cache, --no-loop-breaker, or --no-compress to turn one off. --image-lifecycle is off until you opt in.


Step 2: replay your own sessions with a real tokenizer

Shadow mode watches new sessions. Replay re-runs the compression logic on sessions you already captured. It does not call the model and it does not re-run the old commands.

The hooks install includes the ReclaimLLM MCP server unless you passed --no-with-mcp. MCP (Model Context Protocol) is how the assistant calls a local tool. In Claude Code or Codex you can ask:

  • "Would compression help on my last 50 sessions?"
  • "What is the aggregate reduction across my Codex sessions this month?"

The tools behind those questions are replay_eligibility, replay_session, replay_corpus, and replay_compare. Eligibility comes first. A short session, or one with little tool output, comes back as insufficient data instead of a percentage.

Replay counts text tool-result tokens with a real tokenizer (o200k_base), not the characters-divided-by-four estimate used in live hook telemetry. The report is a share of those tool-result tokens. It is not a share of the whole prompt, and it is not a share of the bill.

One published replay of our sessions found that the compression hooks removed roughly a quarter of the tool-result tokens. Other workloads we have replayed landed lower, and some landed higher. Use the sentence as a reason to measure, not as your forecast. replay_compare shows what each mechanism adds on the same sessions before you enable it.


Step 3: if you need an offline check, use RCLM Bench

RCLM Bench is an open-source command-line and terminal UI for two jobs: run a coding task in an isolated Docker worktree, and replay compression on Claude Code and Codex sessions without sending them through a live agent. Task checks are there so you can see whether a change still passes the tests you defined.

This article does not include a sample score from Bench. A number from our repo would not be your task. Run it on a task you care about, and label the output as that run.


Step 4: turn off what does not pay, and opt into the rest

After shadow mode and replay, keep a mechanism only if your sessions moved and the agent still finished the work.

| Mechanism | Default | What it changes | |---|---|---| | Read cache | On for Claude Code | A later read of unchanged lines is replaced with a short note: which lines, and the turn that first read them. Changed lines are still sent | | Compression, including search and command-output shaping | On for Claude Code, Codex, and Cursor | Shrinks large tool results that match a known shape. Unknown commands pass through | | Loop breaker | On for Claude Code | Warns on repeated identical calls, then asks before another repeat | | Image downscaling | Off until --image-lifecycle | On Claude Code, large images can be scaled down before they enter the transcript. On Codex, image results are measured only. Codex does not apply that rewritten image output | | Brevity prompt | Off until --brevity | Claude Code only. Adds a short "be brief" instruction at session start. Any savings figure for this one is a cohort estimate, not a per-session measurement | | Context pack and handoff | Context pack is off until --context-pack. The handoff suggestion is on unless you pass --no-handoff-advisor | Helps a long session start from a summary instead of a cold reread. file_brief is the related MCP tool for one file |

Codex also applies a shell-read range cache when that mechanism is enabled. Do not assume every Claude Code switch has the same effect on Codex. Image downscaling is the clearest difference: measurement only on Codex.

Moving a captured session between Claude Code and Codex is a separate feature. It does not change these token numbers. Mention it only if you already use both tools on one task.


The same hooks can redact secrets

The hook that sees tool output can also run DLP. DLP is on by default, and shadow mode does not turn it off. Redaction replaces recognized secrets with placeholders such as [REDACTED:API_KEY]. It is string matching, and it can miss a secret. An env-file read that DLP cannot safely redact is blocked. An unexpected error on a different tool does not block that tool. A deleted hook blocks nothing.

If the reason you are here is a leaked .env rather than a token bill, read .claudeignore doesn't stop Claude Code reading your .env and the Claude Code security page. Compression and redaction share an install. They answer different questions.


What to do next

  1. Install hooks if you have not: curl -fsSL https://reclaimllm.com/install.sh | bash on macOS or Linux, or pipx install rclm and then rclm-hooks-install.
  2. Measure without rewriting: rclm-hooks-install --shadow-mode.
  3. Ask for a replay of your own recent sessions. Treat "insufficient data" as a real answer.
  4. Leave shadow mode only for mechanisms that moved your tool-result tokens without breaking the task.

Cost savings is the product page. Context compression is the mechanism reference. Token compression use cases is the narrative version of the same idea. None of those pages should be read as a promised discount on your provider invoice.


Frequently asked questions

Why does Claude Code use so many tokens?

Because tool results stay in the conversation and are sent again on later turns. A result from early in a long session is counted once per later turn. Prompt caching can discount some of those repeats. It does not remove them from the context window.

How can I reduce Claude Code token usage without changing how I work?

Install the hooks and let read caching and compression shrink repeated or bulky tool output. Those two are on by default, so a normal install already rewrites output. If you want numbers before any rewrite, start with rclm-hooks-install --shadow-mode and a replay. This does not require developers to remember /compact.

Does caching make re-sent tool output free?

No. On Anthropic's API, a cache read is often about a tenth of the base input price, and less on some current models. Cache writes cost more than a normal input token. The default cache lasts about five minutes. Cached text still counts toward the context limit.

How do I measure token savings before turning anything on?

Use shadow mode so the hooks record estimates and do not rewrite the prompt. Then run replay on captured sessions. Replay uses a real tokenizer and reports text tool-result tokens. Live hook estimates often use a characters-divided-by-four approximation. Do not treat those two numbers as the same thing.

Do these techniques work with Codex too?

Partly. Compression runs on Codex as well as Claude Code and Cursor. Image downscaling is measurement-only on Codex. The loop breaker in the installer is the Claude Code control. Replay can be pointed at Codex sessions. Compare your own Codex corpus before you expect the Claude Code result.

Will this lower my AI bill?

It can remove tool-result tokens. The effect on the invoice depends on your plan, model, cache hit rate, and whether the agent takes more turns after the context changes. Token reduction is not a guaranteed percent off the bill. A mechanism can also make a task worse if the agent no longer has the text it needed. That is why replay and a real task check come before you enforce a new mechanism.