Context
What the context window is, what fills it during a task, and why more context is not always better.
Context is everything the model can see when it writes its next piece of text. For a coding agent, context decides almost everything: whether it knows your conventions, whether it has read the right file, and whether it still remembers the constraint you gave it an hour ago. This lesson explains how context works and how to manage it on purpose.
The context window
A model can only read a limited amount of text in one request. That limit is the context window, and it is measured in tokens. For most models, input and output share it: the reply has to fit in the same window as everything sent.
Different models have different window sizes, and they have grown over time. Whatever the size, the rule is the same. If something is not in the window, the model cannot use it. If the conversation outgrows the window, something has to be dropped or shortened.
What goes in it
For a chat, the window holds the conversation. For an agent, it holds much more. A typical request carries:
- System instructions: how the agent should behave, written by the tool you use.
- Tool definitions: a description of each tool the agent can call.
- Project instructions: files like
AGENTS.mdthat describe your conventions, when the tool supports them. - Saved notes or memory: facts kept from earlier sessions, if the tool has memory.
- The conversation: your messages and the model's replies.
- Tool results: file contents, command output, search results, and anything else the agent fetched along the way.
Tool results are often the biggest part. One large file or one noisy test run can take more room than the whole conversation.
Why more is not always better
It is tempting to give the model everything, just in case. In practice that tends to backfire.
- It costs more. Every token in the window is sent with every request, so a bloated context is paid for again at each step.
- It is slower. More input takes longer to process.
- Details get lost. Models can overlook an important line buried in a lot of unrelated text. The instruction that matters competes with everything else for attention.
- Old information misleads. A file read before an edit, or an approach you dropped, can still be in the window. The model may act on the stale version.
- Conflicts creep in. Two documents that disagree leave the model to guess which one you meant.
The goal is not the most context, but the right context: what the task needs, and little else.
Managing context on purpose
A few habits keep the window useful:
- Put lasting rules in an instructions file. Conventions you would repeat in every prompt belong in the repository's instruction file, where the agent reads them each time.
- Point instead of paste. Name the file or function and let the agent read it, instead of pasting large blocks that may already be out of date.
- Keep output focused. Ask for the one failing test, or a filtered log, rather than everything.
- Start a new session for a new task. Leftover context from unrelated work only gets in the way.
- Summarize when it gets long. Many tools can compact a conversation: they replace the history with a summary and keep going. The summary keeps the gist and drops detail, so restate anything critical afterward.
Here is the difference in practice:
The second prompt is shorter and leaves more room for what the agent finds.
Key points
- The context window is the limited amount of text, in tokens, a model can see in one request.
- For agents it holds instructions, tool definitions, notes, the conversation, and tool results, and tool results are often the largest part.
- More context costs more, runs slower, and can bury the details that matter.
- Keep lasting rules in an instructions file, point to files instead of pasting them, and start fresh for new work.