BLOG / CLAUDE CODE

What actually happens when you press Enter in Claude Code

Your laptop builds a request, GPUs run prefill and decode, and tools loop back. A step-by-step look at one Claude Code message.

You type a message, press Enter, and a moment later text starts streaming back. In between, your laptop builds a request, a data centre runs a model on GPUs, and the answer may go back and forth several times before you see it. Here is that trip, one step at a time.

The same steps apply to Cursor, Codex and most other coding agents. Anthropic does not publish how its servers work, so the server part below describes how large language models are typically served, not Anthropic's exact setup.

How one Claude Code message travels from your machine to the GPU and back
How one Claude Code message travels from your machine to the GPU and back

On your machine: building the request

Claude Code never sends just your message. Before anything leaves your laptop, it assembles:

  • The agent's instructions and the definitions of every tool it can use.
  • Your CLAUDE.md files, loaded from the current folder and every folder above it (Claude Code docs).
  • The name and description of each skill, about 100 tokens each. The full skill instructions load only when a task needs them (Agent Skills docs).
  • The conversation so far, plus your new message.

All of that goes out as one API request. So far, everything is ordinary CPU work.

On the server: prefill and decode

StageCPU or GPU?What happens
TokenizationUsually CPUText becomes tokens, the units the model reads.
Queue and schedulingCPUThe request waits for a slot on a GPU.
PrefillGPUThe model reads all input tokens at once and builds the KV cache.
KV cacheMostly GPU memoryStores attention keys and values so they are not computed again.
DecodeMostly GPU, CPU coordinatesThe model writes one token at a time, reusing the KV cache.
StreamingMostly CPUTokens are sent back to your terminal as they are made.

Prefill is why a long context delays the first token: the model has to process all of it before it can answer. Decode is why long answers take time: every new token needs another pass through the model.

Want to watch prefill and decode with real numbers? Our 3D Inference Simulation runs a small model one calculation at a time.

The tool loop: one message, many requests

When Claude wants to read a file or run a command, it does not do that on the server. It stops and replies with a tool request. Claude Code runs the tool on your machine, if your permissions allow it, adds the result to the conversation and sends a new request (tool use docs).

So one message like "fix the failing test" can become ten or twenty round trips: read a file, run the tests, edit, run them again. Each trip goes through prefill and decode again.

Your second message: why it stays fast

Your session history lives on your machine, not on the GPU. Every request carries the instructions, tools and conversation again, and the server keeps nothing between requests except short-lived caches. When the history gets too long, Claude Code replaces older turns with a summary.

Sending everything again sounds wasteful. Prompt caching is what keeps it cheap. The server keeps the processed start of a recent request, in a fixed order: tools, then the system prompt, then messages. If the next request starts the same way, only the new part needs prefill. On Anthropic's API, a cache entry lasts five minutes by default and refreshes each time it is used, and cached input costs a tenth of the normal input price or less (prompt caching docs).

This is also why changing something near the start of the request, such as the list of tools, is expensive mid-session. The cache matches from the beginning, so a change there means everything after it is processed again.

What to remember

  • Your laptop assembles the context. The GPU only sees what each request carries.
  • Prefill reads your input, decode writes the answer, and the KV cache connects the two.
  • One message can mean many model requests, because of the tool loop.
  • Prompt caching is why resending the whole conversation stays fast.

← Back to Blog