Understanding Context Decay
Context Decay is a common failure mode in AI-assisted software development. In prompt session #1, an AI agent follows all project guidelines perfectly. By prompt session #15, the agent starts introducing syntax errors, forgetting path aliases, or overwriting existing component files.
This happens because LLM context windows, while vast (200k to 1M+ tokens), suffer from attention dilution and middle-loss syndrome. As the chat log fills with generated code and stack traces, the relative weight assigned to initial prompt instructions decreases.
---
Symptoms of Context Decay
- Constraint Amnesia: The AI begins using forbidden libraries (e.g. installing Tailwind when Vanilla CSS was specified).
- Import Erasure: Removing critical module imports when modifying existing components.
- Style Inconsistency: Writing inconsistent button styles or bypassing established design system tokens.
How to Prevent Context Decay
- Move Rules out of Chat into Root Files: Place persistent instructions in
AGENTS.mdorCLAUDE.md. AI tools read these files fresh on every invocation. - Execute Short, Atomic Prompt Loops: Keep chat threads focused on single feature tasks (e.g., 3-5 prompts per session).
- Use Reset Commands: In CLI tools like Claude Code, run
/compactor/clearregularly to wipe transient chat state while retaining file-based context. - Build an Automated Test Harness: Use automated test suites (
npm test) to catch regressions the moment context decays.