The context window and what fills it
Lesson 2 of 27 · How an agent works · 2 min · Free Watch this lesson freeYou asked for a small change and the agent got strangely vague, or forgot a rule you gave it an hour ago. Nothing is broken. You ran into the limit that governs everything an agent does: the context window.
What fills it
The context window is everything the model can see when it picks its next action. That is your conversation, every file it has read, every command output, your instruction files, loaded skills, and the tool's own system instructions.
Notice who fills most of it. You type a few lines. The agent's own reading and command output supply the rest, and one noisy test run or one huge file can outweigh your whole conversation.
Fuller is not better
A bigger pile does not mean a better answer. Anthropic's engineers call this context rot: as the number of tokens grows, the model gets worse at recalling what is in them. Context is a finite resource with diminishing returns.
The goal they describe is the smallest set of high-signal tokens that gets the outcome you want. Treat every file you let in, and every log you paste, as something that has to earn its place.
Compaction
When the window nears its limit, the tool compacts the conversation into a summary and carries on. The summary keeps your requests and key code, but detailed instructions from early in the session may be lost.
So a rule you only said in chat has an expiry date. Anything that must hold for the whole task belongs in a file the tool loads at the start of every session, and we build that in unit two.
Three habits
Three habits follow. One task per session, and clear between unrelated tasks. If you have corrected the same mistake twice and it persists, clear and write one better prompt, because a third correction only adds to a conversation already full of failed attempts.
Send noisy work, like a long test run or a pile of logs, to a sub-agent so only its summary comes back. And look at what is loaded: in Claude Code, the slash context command shows what is using space.
Keep this: the window is a budget, the agent spends it for you, and your job is to keep it clean. Next, we set up the project you will extend for the rest of the course.
This is the narration of a video lesson from Engineering with Coding Agents. In the video it is animated, and you can pause it to ask a question.