Inside a coding agent
the request lifecycle
A worked example for the top of the Frontier Stack: what actually happens when you ask a coding agent to “fix a bug.” No server-side session, no vector database of your repo, no secret router — just a stateless API, a content-addressed cache, and a tool loop that runs on your own machine. Two animations make it concrete.
- the surprisethe API is stateless
- cachingcontent-addressed prefix, ~5-min TTL
- “retrieval”client-side tool loop, not server RAG
- routingnone — model is an explicit field
00 The mental model that’s wrong
Almost everyone pictures it like this: “there’s a session on Anthropic’s server; it remembers my conversation; each message continues it.” That is not how it works, and the real picture explains a surprising amount — why long sessions still work, why they get cheaper on repeated turns, why editing an early message can suddenly cost more.
The truth: the Messages API (POST /v1/messages) is stateless. There is no session object the server looks up. Every call — including the 50th message of a long Claude Code session — carries the entire conversation in the request body: every prior message, every tool call, every result. The client keeps the transcript and resends the whole thing each time. Watch it:
What actually crosses the wire when you talk to a coding agent.
So the mental model isn’t “the server finds my session and continues it.” It’s “the client keeps a growing transcript locally and re-submits all of it, every call.” The model has no memory between requests; the appearance of memory is entirely the client resending context.
01 Then what is prompt caching?
If the whole transcript is re-sent every turn, wouldn’t that be slow and expensive? It would — except for caching. But caching is not a session lookup either. It’s a content-addressed prefix cache:
- The client marks a point in the request — after the system prompt, tools, and earlier turns — with a cache_control breakpoint.
- Anthropic hashes the exact, byte-for-byte content up to that point. If a later request has an identical prefix, the cached attention state is reused instead of recomputed.
- It’s ephemeral — a ~5-minute TTL (refreshed on each hit; a 1-hour option exists). No ID, no database row — just “have I seen these exact leading tokens recently.”
- You can watch it in the response:
cache_read_input_tokens(cheap, ~10% of normal) vscache_creation_input_tokens(a little above normal, since it’s writing the cache).
Poke it. Take a normal turn, then edit an early message, then let it go idle:
Press “next turn” to send another message and watch the prefix hit the cache.
This is exactly why a Claude Code session feels fast and cheap on repeated turns: your system prompt, CLAUDE.md, and tool schemas are identical every call, so that big fixed prefix keeps hitting the cache — only the newest turn is fresh. And it’s why touching an early message hurts: change one byte up top and the whole prefix stops matching.
02 Two things people assume — that aren’t there
There is no RAG on Anthropic’s side. No vector database of your repo lives on the server. “Retrieval,” in a coding agent, is entirely the client-side tool loop you saw in the first animation — the model asks for a grep, your machine runs it, the output is pasted back as text:
You: "fix the bug in auth.py"
│
▼
Claude Code (local) ── prompt + tool defs ─────▶ Anthropic API
│ │
│◀──────────── "call Grep('auth')" ───────────┘
▼
Claude Code runs grep LOCALLY on your disk
│
▼
Claude Code ── grep output as tool_result ─────▶ Anthropic API
│ │
│◀──────────── next response / more ──────────┘Every Read, Grep, Glob, Bash in the transcript is your machine executing that command and stuffing the output into the next request as atool_result. The model never has independent access to your filesystem — it only ever “sees” what gets round-tripped back as text. That’s also why huge repos work: nothing is indexed up front; the agent issues targeted greps and reads as it goes, exactly as you would.
And there’s no automatic model router. The model is an explicit field —model: "claude-sonnet-5" — set by the client on every request. Nothing on the server inspects your question and silently swaps you to a cheaper model. The two things that look like routing —Fast Mode and the Advisor pairing — are both explicit settings you choose, not the API deciding for you.
This is one provider. The other three — OpenAI, Gemini, xAI — converged on the same shape but split on who holds state and who runs the tools. Widen the lens in the model-API landscape, which also maps every piece of it to open source.
03 The one caveat — a genuinely stateful surface
04 Why an observability company cares
Every arrow in that first animation that lands on the API side is GPU work — a forward pass over thousands of tokens of context. Caching is not just a billing trick: a cache_read means the GPUs skipped recomputing attention over that prefix. The gap between a warm cache and a cold one is, quite literally, the difference between silicon doing useful new work and silicon re-deriving what it already knew.
That is the thesis at the API layer. “Utilization” can read high whether the tokens are fresh or cache-reads — but the useful work is wildly different. The wholeFrontier Stack is made of arrows like these, and the job ofPlasmient is to tell you, for each one, how much of that GPU time was real. Start at the operation where the gap is widest: the attention deep-dive.
↗ Full references — go to the source
This is documented behaviour, not reverse-engineering. These are the primary sources — start with the Messages API reference to see the statelessness for yourself.
- docsAnthropic APIMessages API reference — POST /v1/messages, the stateless endpoint everything is built on
- docsAnthropicPrompt caching — cache_control breakpoints, cache_read vs cache_creation, the 5-minute and 1-hour TTLs
- docsAnthropicTool use — how tool_use / tool_result blocks round-trip through the context window
- docsAnthropicClaude Code — the coding agent this page uses as its worked example
- blogAnthropic“Building Effective Agents” — the agent loop, in Anthropic’s own words