It starts fine. You describe what you want, the agent nails the first few steps — and then, a dozen messages in, it forgets a decision you made earlier, rewrites a file you told it to leave alone, or you paste one more thing and get an error like this:
prompt is too long: 207379 tokens > 200000 maximumEverything stops. Some of this is the tool itself — model quality and routing shift day to day, and no config file fixes that. But one big piece is squarely in your control: what fills the context window in the first place.
What losing context actually is
An agent doesn't hold a memory of your project — it has a context window, a fixed budget of tokens it can keep in view at once. Everything competes for that space: your instructions, the files it reads, the conversation so far. When the window fills, the oldest material gets pushed out or summarized away — which is the exact moment it “forgets” the thing you told it twenty messages ago.
The agent reads from your working directory. Well-behaved ones already skip whatever's in .gitignore — but that still leaves plenty of junk that isn'tignored: the committed lockfile, test fixtures, vendored code, generated docs, minified bundles. Every one of those it reads is room it doesn't have for your actual code.
The “prompt is too long” error
That number is your repo, measured in tokens. When the files the agent pulls in add up to more than the model can hold, you hit the wall — and it's usually not one giant file but a pile of small junk. People delete package-lock.json and still see the error, because the lockfile was only part of the load.
The fix isn't a bigger model. It's telling the agent what to skip before it reads it — a short ignore list keeps the junk out of the count. How to reduce your agent's context walks through exactly what to cut.
Where your credits and limits go
“You've hit your limit.” “You're out of fast requests.” “That bug fix burned 30 credits.” Part of every one of those is the agent re-reading files that never mattered. Reading junk costs tokens, and tokens are what your plan meters — a leaner context is spend you simply don't pay on the file-reading side.
A single committed lockfile can run around 70,000 tokens. If the agent re-reads it every time it looks at your repo, you pay for that again and again, for nothing.
The doom loop, and the .md pileup
Two more that come up a lot. The loop where the agent keeps rewriting the same thing has several causes, and most aren't about context — but one common ingredient is stale junk crowding the window, and that part you can cut. And the repo that slowly fills with agent-generated .mdfiles: once there are forty of them, the next session drowns trying to read them all, so a rules file can tell it to skim those instead. You're pruning what gets read, not what gets written.
What actually helps
You can't give the model a bigger memory. What you can do is spend its window better:
- Tell it what to skip. A short ignore list in AGENTS.md or CLAUDE.md names the files that carry no signal, so the agent stops pulling them into context.
- Make some of it stick.That list is advisory — the model usually honors it but can still open a listed file. Four of the config files are enforced: the agent's own harness applies them as a best-effort block, so the skip doesn't depend on the model paying attention. How enforcement works.
ContextPruner does the tedious part: paste your file tree and it works out which files are junk, then writes all nine config files with the ignore list already filled in. It's free and runs entirely in your browser, so your file list never leaves it.
None of this makes the model smarter or promises it'll never lose the thread. It just stops the window filling with things that were never worth reading — which, more often than not, is what “losing context” actually was.