Understanding context
Working well with a coding agent comes down to one skill: managing what the agent can see. Almost everything else in this handbook builds on it. This page covers what context is, why it’s the constraint that matters most, and what we’ll cover in this guide.
What is context
Section titled “What is context”A large language model is stateless. It takes text in, predicts the next token, and remembers nothing between calls on its own. Context is how you give it state. It’s the full set of tokens the model can see at once: the system prompt, your messages, the agent’s own replies, and the output of every tool call it makes — files it reads, commands it runs, search results it gets back.
When an agent reads SchedulerProjectController.cs or runs your test suite, the result lands in context.
That’s how the agent “knows” anything about your code: it’s all there in the tokens in
front of it.
Modern models have a large context window — often 250k to 1M tokens — but it’s still finite. Everything the agent learns in a session has to fit inside it.
Why context matters
Section titled “Why context matters”Two things make context the resource worth managing.
The first is cost. Every token in context is reprocessed on each turn, so a larger context burns credit faster. A session that drags in files the agent never needed costs more to reach the same result.
The second matters more: models get less reliable as context fills up. A good rule of thumb is that a model does its best work in roughly its first 200k tokens — quality starts to slip well before the window is actually full.
LLMs work through attention: to decide what’s relevant, the model weighs every token against every other token. The more tokens in context, the more thinly that attention spreads, and the harder it is for the model to stay locked onto the parts that matter. A long, cluttered context buries the signal you care about under everything else you happened to load.
So context is finite, it degrades as it grows, and you pay for all of it. Managing it well is one of the highest-leverage habits you can build with a coding agent.
How to manage context
Section titled “How to manage context”The techniques fall into a few groups, and later pages go deep on each one:
- Give the agent good pointers up front. A project context file like
CLAUDE.mdtells the agent where things live and how the codebase is laid out, so it can navigate straight to what it needs instead of reading half the repo to orient itself. - Start fresh when the task changes. A new session is a clean slate. Carrying a finished task’s context into the next one pollutes the context window and pulls the model’s focus toward things that no longer matter.
- Build shared understanding early. Spend the start of a session getting the agent oriented on the problem before it edits anything. Once it understands the goal, it makes better calls about what to read and what to ignore — which keeps the context lean for the rest of the session.
- Split into many sessions for large tasks. If you need to make a big change or apply a fix across many files, break it into smaller sessions. Each session can focus on a single part of the work, keeping context small and relevant. Coding agents are notorious for getting lazy when they have a lot of work to do in one go.