Context Poisoning: The Shakespeare Problem
Dumping your whole codebase into an AI coding agent hurts performance; treat it like an intern and narrow what you share.
Dumping your whole codebase into an AI coding agent hurts performance; treat it like an intern and narrow what you share.
When I dump a whole repo into an AI chat, the model loses the thread. Same idea as "Lost in the Middle": give it the files, stack traces, and logs that matter for this fix, not everything open in your editor.
Last month I watched an agent "fix" a Stripe webhook bug by refactoring a 2019 inventory cron job. Both files were in the context. Neither had anything to do with checkout.
I had dragged in the entire src/ tree because I thought more context meant better answers. I got context poisoning instead. Signal buried under noise.
You know the Shakespeare line about the rose. Hand someone the complete works to find it and they'll flip pages for an hour. Hand them Act II, Scene 2 and they're done in seconds. Dumping your whole codebase into an agent's window is the million-page edition.
I treat coding agents like a sharp junior on day one. Fast reader. Zero institutional memory.
For a payment bug I'd rather open with:
Users get 500 on checkout. Check
CheckoutController.tsaround line 45 (Stripe callbacks). Logs attached.
than:
Here's the 5GB monorepo. Payments are broken.
The second version sends them through About pages, modal CSS, and CI yaml before they touch the file that matters.
What I actually include:
Vague prompts get vague patches. That list is how I get something mergeable on the first pass in Cursor or Claude Code.
The intern story is intuition. Liu et al. is the part I cite when someone argues bigger context windows solved this.
Massive prompts get attention at the start (your system message) and the end (your latest reply). The middle blurs or gets invented.
Cram a monolith into one thread and you pay for tokens while the model misses the fifty lines you cared about and hallucinates ties between unrelated modules. I've had payment logic "fixed" via legacy inventory code for exactly that reason.
Claude Code best practices and Anthropic's context management docs match what I learned from bad sessions. This is my checklist.
Curate files. Button bug → button component and the page it lives on. Not the database schema and every API route sitting open in my editor.
Name the done state. "Update onClick in Button.tsx to log to Sentry before rethrowing." Without that, a one-liner and a tested handler both count as success.
Paste evidence first. Stack traces and logs beat filenames. Line numbers give the model something to aim at.
Add files when stuck. If it asks for a helper, attach it then. I debug the same way. Symptom first, widen only when I have to.
Clear poisoned threads. Ten rounds on the same dead end? Reset context, summarize what you learned, try again. Claude Code can wipe after planning so execution isn't stuck on brainstorm noise.
These models predict from the full chat history. Failed attempts in that history nudge the next attempt toward the same failure. Fresh thread, obvious fix. I've lost enough afternoons to believe it.