TL;DR — Key Takeaways
- Watch for: repeated questions, rejected suggestions re-surfacing, generic code, pattern drift
- Degradation is normal — the key is recognizing it quickly
- Save your decisions before starting a new session
How to Recognize When Your AI Coding Agent Has Lost Its Context
An AI coding session degrades when the agent no longer has reliable access to the context established earlier in the session — causing it to produce suggestions that contradict your patterns, re-ask questions you already answered, or generate code that ignores your architecture. Degradation is normal and inevitable; it's a consequence of how context windows and attention mechanisms work. The skill is recognizing it fast.
This guide covers the 7 most reliable warning signs, why each happens, and what to do when you spot them.
Why Sessions Degrade
Before the warning signs: a quick explanation of why degradation happens, so you can recognize the pattern rather than just the symptoms.
Context window filling: As a session grows — more files read, more conversation history, more tool outputs — the context window fills. Older content either gets truncated (removed) or receives less attention as it competes with more recent content. Architectural decisions made in the first 30 minutes of a 4-hour session are at risk.
Attention dilution: Even when early content is technically still in the context window, the model's attention isn't uniformly distributed. Research on the "lost in the middle" phenomenon shows that LLMs tend to prioritize content at the very beginning and end of long contexts, with middle content receiving less focus.
Session drift: The agent is stateless. It doesn't have a persistent picture of "what we're building" — it constructs that picture fresh from the current context window at every response. As the window fills with recent content, the earlier picture fades.
See How LLM Context Windows Actually Work for the technical depth.
Sign 1: The Agent Re-Asks Questions You Already Answered
What it looks like:
"What's the auth setup for this project? Are you using JWT or session-based?"
You answered this 45 minutes ago. You described the entire Auth0 setup. The agent is asking again.
Why it happens: The message where you explained the auth setup has either been truncated (rolled off the context window) or is buried deeply enough that the model isn't weighting it. The agent genuinely doesn't "know" the answer anymore.
What to do: This is the clearest signal that a new session is warranted. Before starting fresh, verify that the answer is in your CLAUDE.md. If it's not, add it before closing. The next session will have the answer pre-loaded and won't need to ask.
Sign 2: Rejected Approaches Resurface
What it looks like:
"I'll implement this using tRPC to keep the API type-safe..."
You explicitly said no to tRPC an hour ago. You explained the reasons (team familiarity, existing route handler patterns). The agent is proposing it again.
Why it happens: Rejections established early in a session are especially vulnerable because they're often stated once and never repeated. "No tRPC" is a negative decision — there's no ongoing evidence of it in the code, unlike positive decisions that show up in every file. When early context fades, the rejection fades with it.
What to do: Short term: redirect the agent explicitly ("We're not using tRPC — as I mentioned earlier, we use route handlers"). Long term: put explicit rejections in your CLAUDE.md with the reasons. "NOT tRPC — team familiarity with route handlers" is one line that prevents this forever. See How to Write a Great CLAUDE.md for how to structure the rejections section.
Sign 3: Generic Code That Ignores Your Patterns
What it looks like: The agent generates code that's technically correct but doesn't follow your project's established patterns:
throw new Error("Unauthorized")instead ofreturn { error: "Unauthorized" }with the right HTTP status- Direct
import { PrismaClient }instead ofimport { prisma } from "@/lib/prisma" localStorage.setItem("token", ...)when you use Auth0 session-based auth
Why it happens: Your project patterns were established in earlier conversation or in files read earlier. As context degrades, the agent falls back to "generic correct" behavior — the patterns it knows from training — rather than your project-specific conventions.
Why this is expensive: Generic code can look right on first glance and pass review. It's often discovered later when it breaks something or a code review catches the inconsistency.
What to do: Add the critical patterns as code examples in CLAUDE.md. Short code snippets (3–5 lines) for your most important patterns prevent this regression even in degraded sessions, because CLAUDE.md is reloaded fresh at the start of every new interaction.
Sign 4: Inconsistent Variable or File Naming
What it looks like: The agent starts generating userId when you've been using user_id, or creates files in src/api/ when your new route handlers go in app/api/. Small inconsistencies that are easy to miss individually but add up.
Why it happens: Naming conventions are typically established by reading existing files early in the session. As those early reads fade from effective context, the agent may fall back to its defaults or simply lose consistency.
What to do: Naming conventions are a good addition to CLAUDE.md — they're stable and highly specific. "Files: kebab-case. Variables: camelCase. DB columns: snake_case." is 9 tokens that prevents this class of inconsistency entirely.
Sign 5: Hallucinating Project Structure
What it looks like: The agent refers to files or functions that don't exist, or places new code in wrong locations:
"Update the
AuthContext.tsxcomponent to..." (There is noAuthContext.tsxin your project)
Or:
"Since we're using the App Router, add this to
pages/api/..." (You moved away from the Pages Router months ago)
Why it happens: The agent's mental model of your project structure comes from the files it read at the start of the session. As that early context degrades, the agent either makes assumptions based on training data ("typical Next.js projects have X") or confuses project-specific structure with generic patterns.
What to do: When you notice this sign, explicitly re-orient: "We don't have an AuthContext.tsx. Our auth is handled via lib/auth.ts and middleware. Read lib/auth.ts before continuing." This is also a strong signal to capture your project's actual structure in CLAUDE.md.
Sign 6: Contradicting Your Earlier Instructions
What it looks like: You gave a specific instruction early in the session:
"Keep all type definitions in
types/— never inline them."
Three hours later:
[generates inline interface declarations in component files]
Why it happens: Explicit instructions given in conversation — as opposed to instructions in CLAUDE.md — are vulnerable to context degradation. The instruction was followed when it was recent. Now buried in old conversation history, it no longer exerts influence.
Why this matters beyond the immediate mistake: Contradicting earlier instructions is the hardest sign to catch during review. The code may be individually reasonable ("inline types are common in TypeScript"). You have to remember your earlier instruction to know it was violated.
What to do: Significant architectural instructions belong in CLAUDE.md, not just in conversation. Treat the conversation as a scratchpad, CLAUDE.md as memory.
Sign 7: Dramatically Slower, Hedgier Responses
What it looks like: The agent starts every response with extended caveats:
"I want to make sure I understand the current state of the codebase before suggesting changes. Could you clarify what pattern you're using for authentication? I see some files that suggest..."
Or produces much shorter responses with more requests for clarification than earlier in the session.
Why it happens: When the agent lacks confident context, it compensates by asking for more information or hedging its suggestions. The hedging is an honest signal — the agent is genuinely uncertain because its context has degraded.
What to do: Don't fight the hedging. The agent is telling you it doesn't have enough context to be useful. This is a clear behavioral signal that a new session is warranted. Before you do, save any decisions from this session to CLAUDE.md.
The Session Reset Protocol
When you spot 2+ of these signs together, the session has degraded enough that continuing is counterproductive. Here's the reset protocol:
Step 1: Capture the session's decisions. Before closing, ask the agent: "Summarize the key decisions we made in this session." Review its summary against what you know. Add anything missing to CLAUDE.md.
Step 2: Write a state brief. One paragraph: what was completed this session, what's in progress, what's blocked, what's next.
Step 3: Start a new session. Open Claude Code fresh. Start with:
Read CLAUDE.md.
Current state: [paste your state brief].
Today's task: [specific bounded task].
The new session starts with full attention on your CLAUDE.md (uncontested by hours of conversation history) and your state brief anchors it to where you left off.
Prevention: How to Extend a Session's Useful Life
Degradation is inevitable — but you can push it further out:
Use /compact proactively. Before the session becomes unwieldy, use /compact in Claude Code to compress the conversation history into a summary. You lose detail but free up context window space and create a fresh attention baseline.
Use /clear between distinct tasks. When you finish one feature and start another, /clear resets the conversation (keeping CLAUDE.md as context). The next task starts in a clean window.
Refer to CLAUDE.md explicitly for high-stakes decisions. "As specified in CLAUDE.md, we use Auth0." This re-anchors the agent without requiring it to surface the decision from degrading context.
Minimize unnecessary file reads. Every file the agent reads consumes tokens. Reference specific files by path rather than letting the agent explore. "Read src/lib/auth.ts" versus "look at how authentication works."
How Context Rot Relates to Session Degradation
Session degradation within a single session is a manifestation of context rot — the broader pattern of AI agents losing architectural decisions over time. Context rot has two timescales:
- Within-session: what this article covers — degradation over hours as context fills
- Cross-session: the complete loss of context when a session ends
The solution to cross-session context rot (persistent CLAUDE.md) also partially solves within-session degradation, because CLAUDE.md content is loaded fresh at the start of every interaction and tends to stay near the beginning of the context window where attention is highest.
For how to build a complete system that handles both timescales, see How to Persist Architectural Decisions Across AI Sessions.
Key Takeaways
- Session degradation is normal and inevitable — it's how context windows and attention work, not a bug
- 7 warning signs: repeated questions, rejected approaches resurfacing, generic code, naming inconsistencies, hallucinated project structure, contradicted instructions, slower/hedgier responses
- 2+ signs appearing together signals the session has degraded enough to warrant a reset
- The reset protocol: capture decisions to CLAUDE.md → write a state brief → start a new session with context
- Prevention: use
/compactproactively,/clearbetween tasks, and explicitly referenceCLAUDE.mdfor high-stakes decisions - Session degradation (within-session) and context rot (cross-session) share the same underlying cause but require different responses
Related: What Is Context Rot in AI Coding Agents · Context Compression Techniques for Long Agent Sessions · How to Persist Architectural Decisions Across AI Sessions