Back to Blog
Blog

Why Claude Code Loses Context in Long Sessions, And How CLAUDE.md Fixes It

Aug 4, 2026·7 min read·Rhithika Gurram
#Claude#Claude Code#AI#Markdown#Claude.md
Why Claude Code Loses Context in Long Sessions, And How CLAUDE.md Fixes It

Three hours into a session, Claude Code starts repeating questions you already answered. It reintroduces a naming convention you removed an hour ago. It “fixes” a file it broke in a way you never asked for. Nothing crashed. No error appeared. The model just quietly started deprioritising the parts of the conversation that mattered.

This isn’t a bug you can patch. It’s how context windows work, and it’s the single biggest reason AI coding sessions go from brilliant to frustrating without warning.

We work with startups hiring engineers who build with these tools every day, and the teams that get the most out of Claude Code aren’t the ones with the cleverest prompts. They’re the ones who stopped treating context as infinite and started engineering it. The tool at the center of that shift is a plain Markdown file called CLAUDE.md.

What’s Actually Happening When Claude Code “Forgets”

Claude Code ships with a 200,000-token context window by default, with a 1-million-token option available on newer models. That sounds enormous, but a fresh session already consumes thousands of tokens before you type a word: the system prompt, loaded skills, and any MCP server schemas all eat into the budget first. Add a CLAUDE.md file, a few tool integrations, and some file reads, and a meaningful chunk of the window is already spoken for.

The deeper problem isn’t running out of room. It’s what happens well before the window fills. Multiple engineering teams working with Claude Code have independently converged on the same finding: output quality starts degrading once context usage passes roughly 20 to 40 percent, long before any hard limit is hit. Attention mechanisms weight recent tokens more heavily as a conversation grows, so instructions from early in the session quietly lose influence even though they’re technically still “in memory.”

This matters practically. A three-hour session that starts with a clear task and never gets checkpointed will produce visibly worse code by hour two, not because the model got dumber, but because abandoned approaches, recovered-from errors, and exploratory detours are all still sitting in the window, diluting the signal that actually matters.

Context Rot Is Real, and It’s Been Measured

This isn’t a Claude-specific quirk. Independent benchmarking from Chroma tested 18 frontier models, including Claude Opus, and found every single one loses accuracy as input grows, in some cases dropping from 95 percent to 60 percent past a certain threshold. Researchers call this “context rot,” and it shows up as a “lost in the middle” effect: models process the start and end of a long context well, but skim the middle, which is exactly where your architecture decisions from 40 minutes ago tend to live.

For a founder or engineering lead, the takeaway is blunt: a longer context window is not the same thing as a more usable one. Newer models can technically read a million tokens, but real-world testing shows wildly different comprehension rates at that scale, which is why a clean, well-managed 200K session frequently outperforms a stuffed 1M one.

What CLAUDE.md Actually Fixes

CLAUDE.md is a Markdown file that Claude Code automatically loads at the start of every session. Think of it as a standing onboarding brief for a contractor who has zero memory of yesterday. It doesn’t make the model smarter. It stops the model from re-guessing things you already decided: which test command to run, which folder is off-limits, which pattern to use instead of the one it defaults to.

Without it, every session starts from zero, and you end up retyping the same correction for a week straight. With it, that correction becomes a permanent rule that the model reads before it does anything else.

How to Write a CLAUDE.md That Actually Holds Up

  1. Keep it under 200 lines. Frontier models reliably track roughly 150 to 200 instructions before adherence starts slipping, and Claude Code’s own system prompt already uses a chunk of that budget.

  2. Lead with commands, not prose. Exact build, test, and lint invocations are the highest-value lines in the file.

  3. Point, don’t paste. Reference the file path instead of pasting its contents into the file. Every line you paste is a tax on every future session.

  4. Never duplicate the linter. If a formatter already enforces a style rule automatically, don’t spend model attention re-explaining it.

  5. Prune ruthlessly. A CLAUDE.md that’s grown into documentation is one that the model has started ignoring in the middle.

  6. Use /clear between unrelated tasks, and checkpoint every 45 to 60 minutes on long sessions rather than letting one conversation run for hours unmanaged.

FAQ: Context, CLAUDE.md, and Hiring the People Who Know This Stuff

Q. Does a bigger context window solve the forgetting problem?

No. A larger window gives the model more room to hold information, but real-world reading comprehension at that scale still varies enormously between models. Managing what goes into the window matters more than how big it is.

Q. Is CLAUDE.md the same as documentation?

No. Documentation is for humans skimming at their own pace. CLAUDE.md is loaded in full every session, whether it’s relevant to the current task or not, so it needs to be short, universally true, and command-first.

Q. How do we know if a candidate actually understands this, versus just knowing the syntax?

Ask them to walk you through a CLAUDE.md they’ve written for a real project, and ask what they cut and why. Engineers who’ve hit context rot in production talk about pruning decisions specifically. Engineers who haven’t tend not to talk about the file in the abstract.

Q. Where do we find engineers who already work this way?

This is increasingly a baseline skill rather than a specialty, but it’s still uneven across the market. It’s one of the things we screen for directly when vetting developers for MyNextDeveloper clients. It’s a strong proxy for how someone actually works with AI tooling day to day, not just how they talk about it.

Key Takeaways

  • Claude Code doesn’t fail with an error when context degrades. It fails quietly, with subtly worse output.

  • Quality starts dropping at 20 to 40 percent context usage, well before the window is full.

  • Context rot is measured by cross-model behavior, not a Claude-specific flaw.

  • CLAUDE.md fixes the forgetting problem by turning repeated corrections into permanent, loaded-every-session rules.

  • The best CLAUDE.MD files are short, command-led, and reference files instead of being pasted.

Putting It All Together

Long AI coding sessions don’t fail because the model got worse mid-conversation. They fail because nobody managed what the model was holding onto. A tight CLAUDE.md, a habit of clearing context between tasks, and engineers who already think this way turn a frustrating afternoon into a genuinely fast one.

That last part is the part most teams underrate. Tooling is easy to copy. Knowing how to use it well isn’t. If you’re building a team where AI-assisted engineering is the default rather than the exception, that’s exactly the kind of judgment we vet for at MyNextDeveloper when we match founders with the top tier of software and AI talent.

TL;DR

Claude Code doesn’t crash when it forgets; it just quietly degrades, producing worse output well before the context window actually fills up. Research shows that every frontier model, including Claude, loses accuracy as input grows, a phenomenon known as “context rot.” A bigger context window doesn’t fix this; comprehension at scale varies wildly regardless of size. CLAUDE.md solves the real problem by turning repeated corrections into a permanent, short, command-first file the model reads every session. The best fix combines a lean CLAUDE.md with disciplined habits such as clearing context between tasks and checkpointing during long sessions.

Looking to build a high-performing remote tech team?

Check out MyNextDeveloper, a platform where you can find the top 3% of software engineers who are deeply passionate about innovation. Our on-demand, dedicated, and thorough software talent solutions provide a comprehensive solution for all your software requirements.

Visit our website to explore how we can assist you in assembling your perfect team.