Join JS Mastery Pro to apply what you learned today through real-world builds, weekly challenges, and a community of developers working toward the same goal.

You've felt this. You start a session, and the agent is sharp. It reads your code, makes clean suggestions, gets your intent on the first try. An hour later it's a different tool. It forgets a decision you made twenty minutes ago. It suggests the exact fix you already rejected. It contradicts itself inside the same reply.
Most people read that as the model getting tired, or hitting some quality cap, or just being flaky. That's the wrong story. The model didn't change. Its context did.
And there's hard data on exactly this. A team at Chroma ran the same simple task through 18 of the best models available: GPT-4.1, Claude 4, Gemini 2.5, and more. Every single one got less reliable as the input got longer. Not when the window filled up. Long before that. The models had the information sitting right in front of them and used it worse as there was more of it. They called it context rot, and once you know the name you start seeing it everywhere.
Here's why it happens, and what to do about it.
An agent has a context window. Think of it as a desk, not a filing cabinet. Everything the agent is "thinking about" right now (your prompt, the files it read, its own earlier replies, that stack trace you pasted) sits on the desk at the same time. There's no back room it quietly files things into. If it's in play, it's on the desk.
You'd assume a bigger desk is always better. More room, more the agent can hold, better answers. It doesn't work that way. Windows have kept growing, a million tokens and beyond, and context rot didn't go anywhere. Room on the desk was never the problem. What's sitting on it is.
Two things are happening.
The first is positional, first documented at Stanford and usually called "lost in the middle." Models pay close attention to the start of what they're holding and the end of it, and weaker attention to the middle. Bury the fact it needs in the middle of a long, busy context and accuracy on a real task can fall by more than thirty percent. Newer models handle simple lookups across positions better than the first ones did, so this isn't a fixed law. But the moment the work needs actual reasoning, the sag in the middle comes back. Your agent didn't forget your decision. It just stopped looking at the part of the desk where you wrote it down.

The second one is worse for coding. When the desk is covered in stuff that looks relevant but isn't, the noise actively pulls the agent off course. This is the everyday failure. You spend forty minutes debugging auth. Then you switch to fixing a styling bug. All that auth context is still sitting on the desk. It looks like code, it looks recent, so the agent keeps half-reaching for it while you're trying to talk about CSS. You didn't get a dumber model. You handed a good model a messy desk.
Coding agents get hit hardest here, because they read a lot to do anything. Ask for one small change and the agent greps around and pulls in eight files. Seven of them are noise for this task. The one that actually matters is now buried in the middle, in the blind spot.
Once you can see the desk, the fix is obvious. Clear it.
Two moves, and they are not the same thing.
Clearing wipes the desk and starts fresh. You do it the moment you change tasks. Done with auth, moving to styling? Clear it. Yes, you lose the history, and that's the point. That history was about to become the noise dragging your next task down. Most agents have a command for this. In Claude Code it's /clear.
Compacting keeps a short summary and throws away the raw pile underneath. The agent writes down "here's where we are, here's what's decided" and drops the forty minutes of trial and error below it. You use this when you're still on one task but the thread has gotten long and heavy.
The instinct most people have is to keep one giant session running all day, because starting over feels like losing progress. It's backwards. A short, clean context beats a long, polluted one almost every time. Your real progress lives in your files and your commits, not in the chat scrollback.
One reframe changes how you work with these tools. Managing what the agent is holding at any moment is the core skill of working with agents, not a rescue move you reach for only when things break. The people who get great results aren't running some secret model. They keep the desk clean, on purpose, all day.
That habit is the groundwork the Agentic Engineering course is built on. Everything after it, every workflow, every skill, every real project build, falls apart if you can't see and control what the agent is actually thinking about. Learn this one thing well and you're already ahead of most people using AI to write code.
Clear more often than feels comfortable. Watch what it does to your results.