When an AI bill goes up, the usual reaction is to touch the prompt: shorter instructions, a cheaper model, fewer examples. I wanted to know whether that made sense for my own usage, so I measured it. I could not reproduce the most striking result 24 hours later. That turned out to be the most useful part of the experiment.

The setup

I used Sorte Verso, a personal project running in production: a monorepo with an Astro + React front end, plus a Laravel API in a separate repository. 271 tracked files.

Every run got the same read-only task:

Where is login (or authentication) validated in this project? List the files involved and explain the flow in up to 10 lines. Do not change anything.

I ran Claude Code headless (claude -p ... --output-format json), restricted to read tools (Read, Grep, Glob). The JSON output reports, per run, cache-read tokens, cache-write tokens, output tokens, number of turns and cost. Three scenarios, three runs each:

  • A: the project as is, with the MCP servers I use day to day enabled;
  • B: same as A, plus a short CLAUDE.md at the root saying where things live (login, session, API contract);
  • C: same as A, but with --strict-mcp-config, which ignores the MCP configuration.

Environment: Claude Code 2.1.210, Opus 4.8 with a 1M-token window, November 14, 2026. The raw numbers are in medicoes.csv.

Results

Scenario Context on the 1st call Cost of run 1 Avg. cost of runs 2–3 Avg. time
A — no map, MCP on ~266K tokens $3.14 $0.525 26.0 s
B — map, MCP on ~265K $0.77 $0.436 27.2 s
C — no map, no MCP ~16K $0.23 $0.418 24.9 s

All nine answers reached the same conclusion: the API validates the login on the server, and the site only stores and sends the token. Quality did not change between scenarios.

Four things stood out.

1. Before reading a single file, the agent was already carrying ~265K tokens

In scenarios A and B, the first call to the model, before any file was read, already had about 265K tokens of context. In scenario C, which only turned MCP off, it was about 16K. Same task, same repository, same answer, with 16 times less context.

2. The cache hides the cost, until the first call of the hour

Run 1 of scenario A cost $3.14. The next two cost $0.52 each. The difference is prompt caching: on the first run those ~265K tokens were written to the cache, and afterwards they were only read.

Anthropic's pricing documentation explains the math. A 1-hour cache write costs 2 times the base input price, and a cache read costs 0.1 times. The JSON shows Claude Code used the 1-hour cache. I rebuilt the cost of every run with those multipliers, and it matched the JSON within $0.003.

The practical consequence: if you measure your agent with a warm cache, you see $0.50. If you start in the morning, or come back from lunch after the cache expired, you pay $3. An average that doesn't separate the two describes neither.

3. Fewer tokens is not proportionally cheaper

Scenario C used 7 to 16 times less context than A, yet with a warm cache it cost almost the same: $0.42 versus $0.52. The reason is that cost is driven by what is new in each run, not by the total.

In run A2, reading 516K tokens from the cache cost $0.26, and writing 23K new tokens cost $0.23. In C2, the cache read cost $0.01, but the agent read more files and wrote 37K new tokens, which cost $0.37.

Counting tokens without separating new input, cache reads and cache writes leads to the wrong conclusion.

4. The CLAUDE.md map helped a little, with noise

With the map (B), runs 2 and 3 wrote 14K new tokens on average, versus 23K without it (A), and cost about 17% less ($0.436 vs. $0.525). But run B1 took 10 turns, against 6 or 7 for the others. With three runs per scenario, that's a hint, not a conclusion.

The next day: I couldn't reproduce it

Finding #1 was the obvious headline: "turn off MCP and cut 94% of your context". Before writing that, I tried to understand where those ~250K tokens came from. I ran a minimal prompt ("Reply only: OK"), changing one variable at a time:

Test Claude Code Model MCP Context
R1 2.1.325 Opus 5.5 on 40,096
R2 2.1.325 Opus 5.5 off 27,561
R3 2.1.325 Opus 4.8 on 40,068
R4 2.1.325 Opus 4.8 off 27,533
R5 2.1.210 Opus 4.8 [1m] on 25,801
R6 2.1.325 Opus 5.5 on + --allowedTools 27,511

None came close to 265K. Today, MCP adds about 12.5K tokens per call, which matches what /context shows in an interactive session: the 301 tools are listed as loaded on demand. That is Claude Code's documented behavior: tool search defers MCP definitions, and only tool names and server instructions load at session start.

R1 to R6 used a minimal prompt, not the original task. That doesn't change the comparison, because what I compare is the first call, before any file is read.

I tested the model, the Claude Code version and --allowedTools, and none of them explains the gap. The configured MCP servers were the same on both days. What I can't test again is whether, in that run, the tool definitions were being deferred or loaded in full. My hypothesis is the latter, but it is a hypothesis, and I can't prove it.

What I take from this

An AI cost number holds for a configuration, not for a tool. The same command, on the same repository, produced 265K tokens of context one day and 27–40K the next. Had I optimized based on the first measurement, I'd be fixing a problem that no longer existed, or that I never understood.

Record the environment with the number. My script logged the Claude Code version, the commit and the file count. It did not log the /context output before each scenario. That would have answered the question that remains open.

Track three numbers, not one. New input, cache reads and cache writes have very different prices. The useful question is not "how many tokens", but "how much of the context is new on each run, and how often does the cache expire".

Measure the first call, not just the average. The cold-cache worst case cost six times the warm average. In real use, with breaks longer than the cache lifetime, it happens every day.

Checklist before optimizing your agent's cost

  1. Run the same task at least 3 times per scenario and keep the raw JSON of each run.
  2. Record the tool version, model, flags, commit and the list of active MCP servers.
  3. Run /context before each scenario and save the output.
  4. Separate the first, cold-cache run from the rest.
  5. Compare new input, cache reads, cache writes and output, not just the total.
  6. Check that the answer is still correct. A saving that changes the result isn't a saving.
  7. Before changing anything, try to reproduce your main finding.

The measurement script, the data and the tables are in the article's folder.