11 TOKENS TYPED · 165,386 TOKENS READ · 6 API REQUESTS · 32¢ BILLED

Claude Code:
how one prompt becomes a code edit

ONE PROMPT· 14:20 → 14:23 ·
you typed·····································11 tokens
loaded before you typed·····································21,850 tokens
API requests·····································6
tokens the model read·····································165,386
lines changed on disk·····································2
billed·····································$0.32
you typed · 11 tokensthe model read · 165,386 tokens
the accent sliver is drawn 2px wide; at true scale it is a fifth of a pixel

Eight words go into a terminal on a Tuesday afternoon: “the auth test is failing — fix it.” Seven chapters follow those 11 tokens to two changed lines. On the way: the 21,850 tokens of instructions already loaded when they arrived, the grep-and-read loop that found the code, the prefix cache that makes re-sending everything six times affordable, and the bill at the end. The scenes play themselves — watch, or just scroll. are tappable. You are the prompt.

01

The harness

The program that reads your keystroke is not the model. Claude Code is a harness: it owns the tools, the files, the permission rules, and the assembly of every request, while the model it calls holds no memory of you between calls. At 14:20 nothing has been sent yet. The counter that runs through this tutorial — tokens the model reads, and what each one costs — is still at zero, and the next 21,850 tokens are assembled on your machine first.

STEP 01 / 05
YOU ARE NOT TALKING TO A MODEL
one keystroke, two very different programs
HARNESS · your machine
your files
the tools
permission rules
the transcript
the whole conversation
MODEL · one endpoint
POST /v1/messages
session store
nothing kept between calls
the model holds no memory of you, so the harness re-sends everything, every turn

The thing in your terminal is a — a program that assembles requests, executes tool calls, and renders output. The model itself runs behind a single HTTP endpoint, POST /v1/messages. That endpoint is : it stores nothing after it answers. So every request carries the whole conversation from the first token, not because anyone chose that design, but because there is nothing on the other side to remember it.

the API keeps no session — every turn re-sends the entire conversation from token zero
STEP 02 / 05
THE PROMPT YOU TYPED IS 11 TOKENS
the auth test is failing fix it
8 words · 33 characters · about 11 tokens
you typed · 11 tokensthe model read · 165,386 tokens
0.007% of the session — about 15,000 tokens read per token you wrote

Eight words, 33 characters, about 11 at roughly four characters each. You can count them before sending: POST /v1/messages/count_tokens returns the exact figure for a given model, free. By 14:23 the model will have read 165,386 input tokens. Your eleven are 0.007% of that — about 15,000 tokens read for every token you wrote. Everything after this step is the other 99.99%.

your 11 typed tokens are 0.007% of the session — roughly 15,000 read per token you wrote
STEP 03 / 05
WHAT A REQUEST IS MADE OF
one request body, rendered in this fixed order
1. toolsa JSON schema per callable tool
14,000 tokens
2. systemthe harness’s own instructions
4,480 tokens
3. messagesthe conversation, your prompt last
3,381 tokens
your prompt is the last item in the last field — and chapter 04 needs it there

Three fields carry everything. tools holds a JSON schema for every tool the model may call. system holds the , the harness’s own instructions. messages holds the conversation. They render in exactly that order — tools, then system, then messages — and that fixed order turns out to be worth roughly two-thirds of the bill. Your prompt is the last item in the last field.

the render order is fixed — tools, then system, then messages — and the whole caching strategy is built on it
STEP 04 / 05
THE MODEL EMITS TEXT; THE HARNESS DOES THINGS
every capability in the product is this round trip
modelemits a block
rulesallow or ask
shellruns rg
requestresult appended
tool_use
the model emits JSON and stops · the harness is what runs rg and writes files

The model cannot open a file. It emits a block — a tool name and a JSON argument object — and stops, with stop_reason: "tool_use". The harness reads the name, checks it against your permission rules, runs the actual ripgrep or file open, and sends the output back as a block inside the next request. Reading a file, running a test, opening a pull request: all of it is that one round trip, repeated.

the model never touches your disk — it emits a JSON block and stops; the harness runs the command
STEP 05 / 05
FORTY TOOLS, DESCRIBED IN 14,000 TOKENS
ReadWriteEditGrepGlobBashAgentSkillWebFetchWebSearchTodoWriteToolSearchEnterPlanModeAskUserQuestionand 29 more
built-in tool definitions
14,000 tokens
one source file, read whole
2,400 tokens
every schema is text, and it sits at position zero of every request today

The tool list is not free. The tools reference lists more than forty built-in names — Read, Grep, Bash, Agent, Skill and the rest — and each one’s name, description and is plain text in the request. Measured with the /context command, the built-in definitions run 14,000 to 17,000 tokens. That block is larger than most files Claude will read today, and it sits at position zero of every request this session sends.

the tool definitions alone are 14,000–17,000 tokens — larger than most files Claude will read today
deep dive: the request, field by field

max_tokens is a ceiling on both halves. It caps thinking plus answer text together, not just the answer. A request that reasons for 12,000 tokens under a 16,000 cap has 4,000 left to speak with, and stops mid-sentence with stop_reason: "max_tokens" if it runs out.

Four stop reasons a harness must branch on. end_turn means done. tool_use means run something and come back. max_tokens means truncated. refusal means a safety classifier declined, with an HTTP 200 and an empty content array — code that reads content[0] without checking breaks on exactly that response.

Why the terminal appears to type. The response arrives as Server-Sent Events — message_start, a run of content_block_delta, then message_stop. The harness prints each delta as it lands. Nothing is being typed; a stream is being rendered.

Parallel calls, one reply. A single assistant turn can contain several tool_use blocks. Every matching result has to come back in one user message: splitting them across messages is valid JSON and trains the model out of asking for parallel work.

Do not estimate with tiktoken. It is OpenAI’s tokenizer and undercounts Claude by 15–20% on ordinary prose, more on code. The counting endpoint is free and model-specific; use it.

02

What loads before you type

Run /context in a fresh session, before you have typed anything, and 21,850 tokens are already spent. Eight blocks put them there, and exactly one of them is something you wrote. The counter moves for the first time here: from nothing to 21,850 tokens of context, still without a single request having been sent.

STEP 01 / 05
THE 21,850-TOKEN COLD START
a fresh session, before your first keystroke — 21,850 tokens
tool definitions14,000
system prompt4,200
project CLAUDE.md1,800
auto memory index680
skill descriptions450
~/.claude/CLAUDE.md320
environment info280
MCP tool names120
21,850 tokens loadedcontext window · 200,000 tokens

Eight blocks, measured. The are 14,000 tokens and the 4,200. Then the project CLAUDE.md at 1,800, the auto memory index at 680, skill descriptions at 450, your personal CLAUDE.md at 320, environment info at 280 — working directory, platform, shell, git branch and recent commits — and MCP tool names at 120. Total 21,850, or 11% of a 200,000-token , spent before you type.

a fresh session starts 21,850 tokens deep — 11% of the window, spent before your first keystroke
STEP 02 / 05
CLAUDE.MD IS A USER MESSAGE, NOT A SYSTEM PROMPT
loaded root-down, then appended as one user message
1/Library/…/CLAUDE.md····························managed policy0
2~/.claude/CLAUDE.md····························you, everywhere320
3./CLAUDE.md····························the team1,800
4./CLAUDE.local.md····························you, here0
CONTEXT — read, usually followed
CLAUDE.mdrulesauto memoryskill bodies
ENFORCEMENT — runs regardless
permission ruleshookssandbox

Where an instruction lands decides what it can do. The system prompt belongs to the harness; your is delivered as a user message after it. That makes it context rather than configuration — Claude reads it and generally follows it, and nothing enforces it. Files load root-down: managed policy, then your personal file, then each CLAUDE.md found walking up from the working directory, then CLAUDE.local.md. The documented target is under 200 lines per file, because a longer one costs more tokens and gets followed less.

CLAUDE.md shapes behaviour and does not enforce it — a PreToolUse hook is the thing that enforces
STEP 03 / 05
THE NOTES IT KEEPS FOR ITSELF
~/.claude/projects/<project>/memory/
MEMORY.md — the index
# Memory Index
- build.md — pnpm, not npm
- auth.md — refresh at 15 min
…195 more lines
200 lines / 25 KB — read limit
- deploy.md — staging needs VPN
- flaky.md — retry timing specs
TOPIC FILES
build.mdauth.mddeploy.mdflaky.mdread on demand
everything past the cut is dropped on every session start, without a warning

is the second half of what survives between sessions. Claude writes markdown into a per-project directory — a build command it worked out, a flaky test, a convention you corrected it on twice. MEMORY.md is the index, and only its first 200 lines or 25 KB, whichever comes first, load at session start; topic files are read on demand with the ordinary file tools. Everything past that cut is dropped on the next load, which is why the harness returns an error telling Claude to shorten the index once it grows past the limit.

only the first 200 lines or 25 KB of MEMORY.md load — whatever follows is dropped on every session start
STEP 04 / 05
DESCRIPTIONS NOW, BODIES LATER
the same five servers, drawn against a 200,000-token window
5 MCP servers · names only, deferred120 tokens
5 MCP servers · schemas loaded upfront55,000 tokens
a schema you never call still rides in every request until it is deferred

, priced. Skills put only their one-line description in context — 450 tokens for the whole set — and a body loads when that skill is invoked. tool schemas are deferred the same way by default: only names are listed, 120 tokens, and the full schema arrives through tool search when a task needs it. Without deferral this is the largest line item people find on their first /context. A GitHub or Playwright server with twenty-plus tools can add 10,000 tokens, and five connected servers about 55,000.

five MCP servers with schemas loaded upfront is about 55,000 tokens — a quarter of the window, on tools you may never call
STEP 05 / 05
YOUR ELEVEN TOKENS GO LAST
ordered by how often each layer changes, not by what matters
1 · system prompt18,200 tokens
tool schemas, instructionschanges when: you upgrade Claude Code
2 · project context3,650 tokens
CLAUDE.md, memory, ruleschanges when: /clear or /compact
3 · conversation11 tokens
your prompt, results, replieschanges when: every single turn
request 1 leaves with 21,861 input tokens · yours are the last 11

Position matters more than size. The blocks are ordered by how often each changes: tool definitions and system prompt, which change when you upgrade Claude Code; then project context, which changes at /clear or /compact; then the conversation, which changes every turn. Your prompt is appended at the very end, which is exactly where chapter 04 needs it. Request 1 leaves your machine carrying 21,861 input tokens.

the request is ordered by how often each layer changes, not by importance — that ordering is worth about two-thirds of the bill
deep dive: instructions, and where to put them

Rules that load only when relevant. A file under .claude/rules/ with paths: frontmatter enters context the moment Claude reads a matching file, and not before. That is the cheapest way to hold instructions for a subdirectory you touch once a month.

Imports organize, they do not save. An @path/to/file reference inside CLAUDE.md expands at launch, up to four hops deep. Splitting a 600-line file into six imports produces six tidy files and the identical token count.

Monorepos pick up other teams’ files. Walking up the tree collects every CLAUDE.md on the way, including ones written for packages you never open. claudeMdExcludes takes glob patterns and skips them; a managed-policy CLAUDE.md is the one file no individual setting can exclude.

The one route into the system prompt. --append-system-prompt puts text in the layer CLAUDE.md cannot reach. It has to be passed on every invocation, which makes it a tool for scripts rather than for sitting down to work.

Auditing what actually loaded. /context lists the memory files in play; the InstructionsLoaded hook logs each one as it loads, which is the way to catch a path-scoped rule that never fired. /doctor proposes trims for a CLAUDE.md that has grown past its usefulness.

04

The prefix cache

Re-sending the whole conversation on every turn would be ruinous at full price, and it is not full price. The API matches the start of each request against what it processed a moment ago and bills the matched span at a tenth. This chapter changes none of the token counts from chapter 03 — the same 165,386 — and changes what each of them cost: 133,275 read from cache, 32,111 written to it.

STEP 01 / 05
THE MATCH IS A PREFIX, AND IT IS EXACT
the same request 6, matched from byte zero
nothing in the prefix changed
read from cache · 30,851 tokensnew · 1,260
one byte changed at token 40
read · 40reprocessed at full price · 32,071 tokens
no per-file cache, no per-segment cache — one string comparison, from the front

The key to the is the bytes of the request, from position zero up to a . If request 6 begins with exactly the bytes request 5 began with, that span is a hit. One byte different anywhere in the prefix and everything after it is reprocessed at full price. There is no per-file cache and no per-segment cache: it is one string comparison, running from the front.

a single changed byte at position 40 invalidates token 40,000 — nothing after a change survives
STEP 02 / 05
WHAT A HIT AND A MISS COST
four prices for the identical token, at Opus 5 rates
read from cache0.1×
$0.50 / M
fresh input
$5.00 / M
written to cache, 5-min1.25×
$6.25 / M
written to cache, 1-hour
$10.00 / M
the 5-minute cache earns out on request 2 · the 1-hour cache on request 3

Four prices for the identical token, against Opus 5’s $5 per million input. A fresh token bills at $5.00 per million. A token written to the cache bills at 1.25× for the five-minute and 2× for the one-hour — $6.25 or $10.00 per million. A token read from the cache bills at 0.1×, or $0.50 per million. Break-even at the five-minute TTL is the second request; at the one-hour TTL it is the third, because you paid double to write it.

a cached token costs a tenth of a fresh one, and a written one costs a quarter more
STEP 03 / 05
THREE LAYERS, ORDERED BY HOW OFTEN THEY CHANGE
a change invalidates its own layer and everything below it
a new turn arrives
1 · system prompt + tools18,200
2 · project context3,650
3 · conversation10,261
layers 1 and 2 read from cache
you switch model
1 · system prompt + tools18,200
2 · project context3,650
3 · conversation10,261
every layer reprocessed
the layer that changes every turn is deliberately the last one in the request

Claude Code orders every request stable-first, which is why chapter 02’s ordering looked arbitrary. Layer one — system prompt and tool definitions, 18,200 tokens — changes when you upgrade Claude Code. Layer two — CLAUDE.md, auto memory, unscoped rules, 3,650 tokens — changes at /clear or /compact. Layer three, the conversation, changes every turn. A change in layer three leaves the first two cached. A change in layer one invalidates all three.

the layer that changes every turn is deliberately last — put the volatile thing first and you pay full price behind it
STEP 04 / 05
THE THINGS THAT THROW IT ALL AWAY
every item on the left feels free until the next turn
THROWS THE CACHE AWAY
/model — caches are per model/effort — part of the cache keyfast mode on — adds a headeran MCP server connects or dropsdenying a tool by nameupgrading Claude Code/compact — by design
KEEPS IT
editing files in the repoediting CLAUDE.md mid-sessionchanging output stylechanging permission modeinvoking a skill or command/recap and /rewindspawning a subagent
the right column all append to the end · the left column all change the prefix

A named list, because every item on it feels free. Switching model with /model, since caches are per-model and the identical conversation on Haiku is a full miss. Changing , also part of the cache key. Turning on fast mode, which adds a header. An MCP server connecting or dropping while its tools sit in the prefix. Denying a bare tool name. Upgrading Claude Code mid-session. And compaction, by design.

switching from Opus to Haiku mid-session can cost more than staying on Opus — the cheaper model rebuilds the whole cache
STEP 05 / 05
HOW LONG IT SURVIVES A COFFEE
the cached prefix, and the clock every hit resets
time left on the cached prefix5-minute TTL
two minutes since the last turn
next request · $0.50 / M
the expensive turn is always the first one after a break

A cached prefix expires after a gap with no requests, and every hit resets the timer. The default is five minutes. On a Claude subscription, Claude Code asks for the one-hour TTL instead, and drops back to five minutes once you are drawing on usage credits, because the longer write costs more. That is why the first message after lunch is slow: the prefix is gone, and the whole history is reprocessed as fresh input at $5 per million.

every cache hit resets the clock — the expensive turn is always the first one after a break
deep dive: the cache, up close

Four breakpoints, and a floor. A request may carry at most four cache_control markers. Below a minimum prefix length nothing caches at all, silently: 512 tokens on Opus 5, 1,024 on Opus 4.8 and Sonnet 5, 2,048 on Opus 4.7, 4,096 on Opus 4.6 and Haiku 4.5. The floor is not monotonic across generations, so a 3,000-token prompt caches on the newer model and does not on the older one.

The 20-block lookback. A breakpoint searches backward at most 20 content blocks for a prior entry. A single turn that appends more than that — common in an agentic loop with many tool results — can miss the cache with no visible cause and no error.

Parallel requests all pay. An entry becomes readable only once the first response starts streaming. Fire ten identical requests at once and all ten miss; fire one, wait for its first token, then fire nine, and nine of them hit.

The cache is per machine and per directory. The working directory, platform, shell and OS version are inside the system prompt, so two sessions in different directories build different prefixes and cannot read each other. That includes two worktrees of one repository.

Watching it live. Every response reports cache_creation_input_tokens and cache_read_input_tokens. A high read-to-creation ratio means it is working; creation staying high turn after turn means something in your prefix keeps moving. ENABLE_PROMPT_CACHING_1H=1 and FORCE_PROMPT_CACHING_5M=1 override the TTL choice.

05

Making the edit

At 14:22 the model emits an Edit block: a path, an old string, a new string. Four things happen between that block and the bytes on disk, and the model performs none of them. The counter barely moves in this chapter — one edit result and one hook line, 210 tokens between them — which is the point. The expensive part of changing code was finding it.

STEP 01 / 04
AN EDIT IS A STRING REPLACEMENT, AND IT MUST BE UNIQUE
an Edit block is three strings and one hard requirement
file_pathsrc/api/auth.ts
old_stringif (Date.now() > expiresAt) {
new_stringif (Date.now() >= expiresAt - SKEW) {
0 matchesrejected — nothing to replace
1 matchapplied
2 matchesrejected — it will not pick one
and the file must already have been read in this conversation

Edit takes three arguments: file_path, old_string, new_string. The harness requires the old string to match the file exactly, indentation included, and to match exactly once. Zero matches and two matches both fail rather than guess. It also requires that Claude has read the file in this conversation, so a write can only land on bytes the model has actually seen.

an edit that matches twice is rejected rather than applied — and Claude cannot edit a file it has not read
STEP 02 / 04
THE GATE THE MODEL CANNOT OPEN
every tool call meets the rule table before the shell sees it
Read src/api/auth.tsallowruns
Edit src/api/auth.tsallowruns
Bash rm -rf distaskstops, waits for you
manualasks first
accept editswrites go through
planno source edits
autobackground checks
Shift+Tab cycles the four modes · none of them are visible to the model

Permission rules are enforced by the harness, not by the prompt — the line between context and configuration that chapter 02 drew. There are four , cycled with Shift+Tab: manual asks before edits and commands; accept-edits waves file writes through; plan explores and blocks source edits; auto runs with background safety checks. Denying a bare tool name removes that tool’s schema from the request entirely, which is why chapter 04 listed it as a cache invalidation.

denying a tool by name deletes its schema from the request, so a permission change is also a cache invalidation
STEP 03 / 04
HOOKS, CHECKPOINTS, AND THE 120 TOKENS AFTERWARDS
what happens between the Edit block and the bytes on disk
snapshotcheckpoint saved
write2 lines replaced
PostToolUseprettier runs
appended120 tokens
the conversation so far · 30,851 tokens+ 120
the hook is a shell command on an event, so it runs whatever the model decides

Before the edit, the harness snapshots the file. That snapshot is the a double Escape restores; it is separate from git and it survives resuming the session. After the edit, a PostToolUse runs Prettier, and its output — 120 tokens — is appended to the conversation. A hook is a shell command bound to a lifecycle event, so unlike a line in CLAUDE.md it runs whatever the model decides.

a hook is the one instruction the model cannot ignore — a shell command on an event, not a sentence in a prompt
STEP 04 / 04
WHAT YOU SEE IS NOT WHAT THE MODEL SENT
the request, and the rendering of it you actually see
IN THE REQUEST
system prompt
project CLAUDE.md
rule: api-conventions.md
text: “Found it — the check is off by the clock skew.”
tool_use: Edit src/api/auth.ts
tool_result: 2 lines replaced
hook output: prettier
ON YOUR SCREEN
Found it — the check is off by the clock skew. Update(src/api/auth.ts) ⎿ Updated with 2 additions and 2 removals
four of the seven blocks in this request are never rendered anywhere

The model’s output is a sequence of content blocks: text and tool calls, nothing else. The harness turns that into your terminal — rendering the markdown, printing tool calls as one-line notices, showing the edit as a diff, collapsing npm test output into a summary. Whole categories never appear at all: the system prompt, hook output, a path-scoped rule loading. The transcript on your screen is a rendering of the request, not the request.

the request and the terminal are different documents — rules, hooks and the system prompt are in one and invisible in the other
deep dive: writing safely

Write is the blunt one. Edit replaces a string it can prove is there; Write replaces the whole file. Overwriting a file Claude has not read is refused for the same reason a blind edit is: there is no way to check what is being destroyed.

Some commands never prompt. The harness keeps a built-in set of read-only Bash commands that run without asking even in manual mode. That is why git status is instant and git push is not.

Hooks can rewrite the call. A PreToolUse hook returning updatedInput changes the command before it runs — filtering test output to failures, say. Exit code 2 sends stderr back to Claude as context; plain stdout on exit 0 goes to the debug log and nowhere near the model.

Rewind is cheaper than compaction. /rewind truncates the conversation back to an earlier turn, and that shorter history is a prefix the cache was built from. Every turn since read through it, so the entry is still warm. Compaction, by contrast, builds a prefix that has never been seen.

What a restore skips. Checkpoints cover file contents, not the world. Symlinked and hard-linked paths are skipped, and anything that reached a database, an API, or a deploy is beyond recall — which is the actual reason those commands ask first.

06

When the window fills

Three minutes of work spent 32,111 tokens of a 200,000-token window — 16% of it, and the counter’s high-water mark for this session. A morning spends all of it, and the session does not end there. The harness starts deleting, in a documented order, and what it deletes decides which of your instructions are still in force afterwards.

STEP 01 / 04
THE OLDEST TOOL OUTPUT GOES FIRST
a full window, and the order the harness empties it in
startup blocks························18%kept
old file reads························34%cleared first
old command output························21%cleared first
the conversation························19%summarized second
recent work························8%kept
the reads are 55% of the window, so they are where the harness looks first

The harness manages the window in two stages. First it clears older tool outputs — the file contents and command results nobody is referring to any more — because that is where the volume is. Only if that is not enough does summarize the conversation. Your requests and the key code snippets are preserved; detailed instructions from early in the conversation may not be.

the first thing dropped is old tool output, not old conversation — the file reads are where the tokens are
STEP 02 / 04
WHAT SURVIVES A COMPACT
after compaction, sorted by what happens to it
system prompt, output style····························untouched
project CLAUDE.md, unscoped rules····························re-read from disk
auto memory····························re-read from disk
rules with paths: frontmatter····························lost until a match is read
nested CLAUDE.md····························lost until that directory is read
invoked skill bodies····························re-injected, capped and truncated
skills come back at 5,000 tokens each, 25,000 total, truncated from the end
so the top of a SKILL.md is the part that survives

The table, because half of it is surprising. System prompt and output style are untouched, sitting outside the message history. Project-root CLAUDE.md, unscoped rules and auto memory are re-read from disk and re-injected. A rule with paths: frontmatter, and a nested CLAUDE.md, are lost until a matching file is read again. Invoked skill bodies come back capped at 5,000 tokens each and 25,000 total, oldest dropped first, truncated from the end.

skill bodies are re-injected but truncated from the end at 5,000 tokens each — the top of SKILL.md is what survives
STEP 03 / 04
COMPACTION IS ITSELF A LARGE REQUEST
compaction is itself a request, and it pays twice
the summarizing request, cache warm
read at $0.50 / Mthe instruction
the summarizing request, cache cold
all of it at $5.00 / M
the first request after compaction
a short new history, no prefix match
run it at a break between tasks, when the prefix is warm and the history is done with

Priced honestly. To write the summary the harness sends another request carrying the same system prompt, the same tools and the same history, plus one instruction appended at the end. While the cache is warm that request reads your prefix at a tenth and spends its money generating the summary. Cold — resuming yesterday’s session — there is no prefix left, and the whole history is reprocessed as fresh input. Then the summary invalidates the conversation layer by design, because the new, shorter history shares no prefix with the old one.

compaction pays twice — the summarizing request re-reads the conversation, and the summary invalidates the cache it just read
STEP 04 / 04
A BIGGER WINDOW IS NOT A CHEAPER ONE
this session, 32,111 tokens, drawn in both windows
default200,000 tokens
32,111 tokens · 16.1% full
[1m] variant1,000,000 tokens
32,111 tokens · 3.2% full
both are re-sent in full on every turn — a bigger window moves the limit, not the arithmetic

Opus 5, Fable 5, Sonnet 5, and Opus 4.6 onward hold a million tokens. That moves the point where compaction fires; it does not change the arithmetic, because a million-token context is re-sent on every turn like any other. Long context is one of the two behaviours /usage names once it accounts for a tenth of recent usage — the other is cache misses. The levers stay the ones from chapter 03: /clear between unrelated tasks costs nothing, and delegating the big reads keeps them out of the window entirely.

/usage names long context and cache misses once either accounts for a tenth of recent usage
deep dive: keeping a session small

Compact with a target. /compact focus on the auth bug keeps what you name instead of what the automatic pass guesses. A Compact Instructions section in CLAUDE.md sets the same steer for every pass, without you typing it each time.

The thrashing case. If one file or tool output is large enough to refill the window right after each summary, compaction would loop forever. The harness stops after a few attempts and reports it, which is a better failure than an expensive infinite one.

Clearing is free; compacting is not. /clear throws the conversation away with no request at all. /compact buys continuity and costs a full-history request to produce. Between unrelated tasks, the cheap one is also the correct one.

Resuming an old session is the expensive turn. The history now sits behind a possibly-changed system prompt with a long-dead cache, so the first request back can be the largest you send all week. On Pro and Max plans Claude Code offers to resume from a summary instead.

Teams multiply the window, not just the work. Each teammate in an agent team runs its own context window as a separate instance. In plan mode that comes to roughly seven times the tokens of a standard session, which is a reason to keep the roster small and the tasks self-contained.

07

The bill

The session ends at 14:23. Six requests, 165,386 input tokens, 2,020 output tokens, twelve tool calls, two changed lines. Here is the arithmetic at Opus 5’s published rates of $5 per million tokens in and $25 per million out, and the counter closes at $0.32 — against $0.88 for the identical session with no cache.

STEP 01 / 04
THE THREE-COLUMN LEDGER
ONE PROMPT · SIX REQUESTS · OPUS 5 RATES
written to cache32,111 tokens$6.25 / M$0.20
read from cache133,275 tokens$0.50 / M$0.07
output2,020 tokens$25.00 / M$0.05
billed$0.32
the same session, no cache$0.88
cache reads were 81% of the input tokens and 21% of the bill

Split by what each token cost. 32,111 tokens were written to the cache at $6.25 per million: $0.20. 133,275 were read from it at $0.50 per million: $0.07. 2,020 output tokens at $25 per million: $0.05. Total $0.32. Uncached, those same 165,386 input tokens would have billed at $5 per million — $0.83, and $0.88 with the output. Caching turned an 88-cent task into a 32-cent one.

cache reads were 81% of every input token in the session and 21% of the bill
STEP 02 / 04
WHY SHORT SESSIONS SAVE LESS
cost with caching, against the same request without it
req 1−2.7¢
req 2+7.0¢
req 3+16.7¢
req 4+28.8¢
req 5+42.2¢
req 6+56.0¢
accent bar · with cachinggrey bar · the same request uncached
request 1 is the only one where the accent bar is longer — the write premium, paid up front

The ninety-percent-off headline is a long-session number. Caching only pays once the write premium is amortized. Request 1 wrote 21,861 tokens at 1.25× and read nothing, so it cost more with caching than without — 13.7¢ against 10.9¢. By request 6 the reads dominate and each turn saves about 13¢. Across an afternoon on one warm prefix the ratio approaches the full tenfold discount; across a three-minute task it lands at 2.8×.

request 1 cost 25% more with caching than without — the write premium only earns out from request 2
STEP 03 / 04
OUTPUT COSTS FIVE TIMES INPUT, AND THINKING IS OUTPUT
the price sheet is asymmetric, and thinking sits on the expensive side
input
$5.00 / M
output
thinking — billed, never shown$25.00 / M
/effort is the knob · and changing it mid-session rebuilds the cache as well

The price sheet is asymmetric: $5 in, $25 out per million on Opus 5. is billed as output, and it is on by default because it measurably helps on planning and multi-step work. The budget can run to tens of thousands of tokens on a single request. That is the knob with the steepest cost curve, which is why /effort exists — and, per chapter 04, why changing it mid-session rebuilds the cache as well. (The reasoning-models tutorial is about what those tokens are doing.)

thinking tokens are billed as output at 5× the input rate — and you never see them
STEP 04 / 04
WHAT A DAY OF THIS COSTS
published figures across enterprise deployments
this two-line fix
$0.32
one developer, one active day
$13
the 90th-percentile day
$30
one developer, one month
$150–250
this task was about a fortieth of an average developer-day

Scaled from one task to one engineer. Anthropic’s published figures across enterprise deployments: about $13 per developer per active day, $150–250 per developer per month, and under $30 per active day for 90% of users. Our 32-cent task is roughly a fortieth of a day. Where the long tail comes from is documented too — a session left open all day re-sending its full history, a first message after a break that missed the cache, an agent team running seven times the tokens of a single session.

about $13 per developer per active day, and under $30 for 90% of users — this fix was a fortieth of a day
deep dive: reading the meter

/usage attributes, not just totals. It breaks recent usage down by skill, subagent, plugin and individual MCP server, and flags any behaviour accounting for a tenth or more — long context and cache misses being the two it names outright.

The two fields worth a statusline. Every response reports cache_creation_input_tokens and cache_read_input_tokens. A statusline script reading current_usage puts the read-to-creation ratio on screen, which is the fastest way to notice a prefix that stopped matching.

Half price, if it can wait. The Batches API processes the same requests asynchronously at 50% of standard rates, with most batches done inside an hour. Nothing interactive fits, but a nightly sweep over a thousand files does.

Per-user numbers across a team. OpenTelemetry export streams token and cost metrics per user and session into your own stack, and works on every setup — including the cloud providers, where Anthropic’s own dashboards see nothing.

The figure in your terminal is an estimate. /usage computes its dollar amount locally from token counts at list rates. It knows nothing about your promotional pricing or contracted discounts, so it will not match the invoice.

Σ

One prompt, priced

A receipt: one line per thing you were charged for, with the total at the bottom. Every row was earned in a chapter above, and the right margin says which. Eight words went in at 14:20; two lines came out at 14:23; 165,386 tokens passed through the model in between.

ONE PROMPT, PRICED · TUESDAY 14:20 → 14:23 · OPUS 5, 200K WINDOW
you typed·······································11 tokens01
loaded before you typed·······································21,850 tokens02
tool definitions, 40+ tools·······································14,000 tokens02
system prompt·······································4,200 tokens02
project CLAUDE.md·······································1,800 tokens02
auto memory index·······································680 tokens02
environment · MCP names · skills·······································850 tokens02
API requests·······································603
tool calls·······································1203
input tokens the model read·······································165,38603
written to cache @ $6.25/M·······································32,111 tokens · $0.2004
read from cache @ $0.50/M·······································133,275 tokens · $0.0704
output tokens @ $25.00/M·······································2,020 tokens · $0.0507
context at its peak·······································32,111 of 200,000 tokens06
lines changed on disk·······································205
billed·······································$0.32
the same session with no cache·······································$0.88
each request, and the share of it read from cache
req 10%
req 295.2%
req 383.6%
req 491.2%
req 597.6%
req 696.1%
$ /usage
Total cost: $0.32
Total duration (API): 1m 04s
Total duration (wall): 3m 12s
Total code changes: 2 lines added, 2 lines removed