Docs / How Agents Talk to Models / A Claude Code session
A Claude Code session
CLAUDE.md + every tool schema — and that base rides along as input on every request. One instruction (“add a test”) becomes a loop of many requests; subagents run their own transcripts and bills; and when the window fills the harness compacts older turns into a summary. It's the most expensive shape precisely because every earlier module compounds inside it.When you run claude in a terminal, it feels like a conversation. Underneath it's the exact machinery of the core path, just more of it. Nothing here is Firstpass — this is how any capable coding agent spends. Walking one session end to end makes every earlier module concrete.
What's loaded before you type anything
The moment a session starts, the harness builds a base context it will send on every request for the rest of the session:
- The system prompt — the harness's own instructions: how to use tools, safety rules, output conventions. Several thousand tokens, fixed for the session.
- Project memory — your
CLAUDE.md/AGENTS.md, loaded verbatim so the agent knows your conventions. - Tool schemas — the name + JSON schema of every tool the agent can call (Read, Edit, Bash, Grep, plus any MCP tools). This is the
toolsarray from Tool calls plus any MCP tools, together, on the wire.
Add it up and the base context is often several thousand input tokens before your first word — and by multi-turn's rule, it is re-sent and re-read on every request in the session. That's exactly the stable prefix caching exists to cache, which is why a coding agent is the textbook case for prompt caching.
One instruction becomes many requests
You type one line — “add a null-check test for handle().” That is not one model call. It kicks off the the tool loop loop: the agent reads files, writes a test, runs it, reads the failure, fixes it — each step a separate request, each carrying the base context plus a transcript that grew since the last step. A single instruction routinely spends five, ten, twenty model calls before it reports back:
CLAUDE.md + tools). Steps ③–④ run locally with no model call. The fatter arrow at ⑤ reflects the larger input after the transcript grows. This stacks multi-turn compounding on top of a fat fixed prefix — which is why caching matters most in a coding session.Subagents spend on their own tab
When the agent delegates — “search the codebase for every caller of parse()” — it can spawn a subagent. That subagent gets its own base context and its own transcript, runs its own tool loop, and returns only a compact result to the main session. This is deliberate: it keeps the main thread's context lean (the subagent's twenty file-reads never pollute your window). But make no mistake — those tokens are billed. A session that spawns three subagents is running four independent Module-4 loops, four bills, that happen to roll up into one task.
When the window fills: compact — or clear
Every model has a context ceiling, and a long session eventually nears it. You have two ways to bring the input back down, and they are opposites.
Compact (automatic near the ceiling, or /compact) summarizes older turns into a digest and continues the same task — you keep the thread. Two costs follow:
- Compaction is itself a model call — summarizing isn't free.
- It rewrites the prefix, so the prompt cache from before the event is invalidated — the next request pays fresh reads.
Clear (/clear) does the opposite: it wipes the conversation entirely and starts fresh. The base context (system prompt, CLAUDE.md, tool schemas) reloads, but every turn of history is gone. No summary is made — it's the cheapest possible reset, and the right move when you switch to an unrelated task rather than continue the current one.
/compact | /clear | |
|---|---|---|
| Keeps the thread? | Yes — summarized | No — wiped |
| Costs a model call? | Yes (the summary) | No |
| Input right after | base + summary + new turns | base + your next turn only |
| Reach for it when | same task, running long | moving to a new task |
/clear before an unrelated task is the cheapest context you'll ever send.So what does a session cost?
Put the pieces together for a realistic half-hour of pair-programming — a handful of instructions, each fanning into a tool loop, over a fat base context:
The seven modules above are the main road — the path our one task actually walked. These five are the turns a real agent takes off it: streaming responses, machine-readable output, images, MCP servers, and the failures that happen when you make hundreds of calls. Each is a dedicated module; take them in any order.