Skip to main content

Why Claude Code Forgets Everything After 20 Messages (And How to Fix It)

· 6 min read

Claude Code auto-compacts at message 20 and loses all your file paths, decisions, and context. Here's why it happens and how MemClaw fixes it permanently.

Why Claude Code Forgets Everything After 20 Messages (And How to Fix It)

You're twenty messages into a session. Claude knows your project structure, the architectural decisions you made last week, the specific version constraints you're working around. Then it auto-compacts.

Next message, it's gone. File paths, variable names, the reason you chose that approach — all of it. You're back to re-explaining from scratch.

This isn't a bug. It's how Claude Code is designed to work. And once you understand why, the fix becomes obvious.


What Actually Happens When Claude Code "Forgets"

Claude Code has a context window — a fixed amount of text it can hold in memory at once. When a conversation gets long enough, it hits a threshold and triggers auto-compaction: it summarizes the conversation history to free up space.

The summary keeps the broad strokes. It loses the details.

Those details are exactly what you need:

  • The exact file path you were working in (src/services/auth/providers/oauth.ts, not "the auth file")
  • The number you spent an hour calculating (the rate limit is 847 requests per 15-minute window, not "around 800")
  • The reason you made a specific decision ("we're not using Redis here because the client's infra team won't support it")

Auto-compaction isn't the only failure mode. Start a new session and Claude wakes up with total amnesia — no memory of previous conversations at all. The context window resets to zero.


Why This Is an Architecture Problem, Not a Usage Problem

The instinct is to work around it: keep sessions short, paste in context at the start, maintain a MEMORY.md file.

These work, up to a point. The problem is they don't scale.

If you're working on one project with one client, manually managing context is annoying but manageable. If you're juggling three projects, five clients, or a long-running codebase with months of accumulated decisions — manual context management becomes a second job.

There's also a subtler failure mode: context mixing. Claude Code's default memory is global. If you're working on Client A's project in the morning and Client B's in the afternoon, there's no wall between them. Details bleed across. The AI starts making suggestions that make sense for one project but not the other.

This is the architecture problem. The solution isn't to be more disciplined about pasting context. The solution is to give each project its own isolated memory that persists automatically.


Install MemClaw in 30 Seconds

MemClaw is a memory layer for Claude Code and OpenClaw that gives each project its own isolated workspace. Context persists across sessions, auto-compaction doesn't wipe it, and projects never bleed into each other.

# Claude Code
/plugin marketplace add Felo-Inc/memclaw
/plugin install memclaw@memclaw

OpenClaw

bash <(curl -s https://raw.githubusercontent.com/Felo-Inc/memclaw/main/scripts/openclaw-install.sh)

ClawHub

clawhub install memclaw

Once installed, create a workspace for your project:

Create a workspace called "client-acme-api"

That's it. From that point on, everything Claude learns about that project — file paths, decisions, constraints, context — gets stored in that workspace and loaded automatically at the start of every session.


What Changes After You Set Up a Workspace

Before MemClaw:

Session 1: You explain the project structure, the tech stack, the constraints. Session 2: You explain it again. Session 3: Auto-compaction hits at message 18. You explain it again.

After MemClaw:

Session 1: You explain the project structure once. MemClaw stores it. Session 2: Claude loads the workspace. It already knows everything. Session 20: Auto-compaction happens. The workspace is unaffected — it's stored separately, not in the conversation history.

The key difference: workspace memory lives outside the context window. It doesn't get compacted. It doesn't reset when you start a new session. It persists until you explicitly change it.


The Three Failure Modes MemClaw Solves

1. Auto-compaction amnesia

When Claude compacts the conversation, it loses detail. MemClaw stores the important details in the workspace before they can be lost. The workspace is loaded fresh at the start of each session, so compaction only affects the current conversation — not the accumulated project knowledge.

2. Session restart amnesia

New session, blank slate. With MemClaw, starting a new session means loading the workspace. Claude picks up exactly where it left off.

3. Cross-project contamination

Working on multiple projects? Each gets its own workspace. Client A's context stays in Client A's workspace. Client B never sees it. Switch between projects by switching workspaces:

Switch to workspace "client-b-dashboard"

What About MEMORY.md?

If you're already using a MEMORY.md file, you know the problem: it works until it doesn't.

The most common failure is overwrite. You've carefully curated 20+ entries of project knowledge. One session, the agent decides to "update" the memory file and replaces everything with a three-line summary. Twenty entries gone.

MemClaw's workspace storage doesn't have this problem. The agent can add to the workspace, but it can't accidentally overwrite the entire thing. Individual entries are stored separately, not as a single file that can be replaced in one operation.


Checking What Claude Knows About Your Project

One of the more useful things you can do with MemClaw is audit what's actually stored. Before a complex task, ask:

What do you know about this project?

Claude will surface the workspace contents — the decisions, constraints, file paths, and context it has stored. You can see exactly what it's working with, identify gaps, and add anything that's missing before you start.

This is especially useful when picking up a project after a break, or when handing off to a collaborator.


Stop Re-Explaining Your Projects

The re-explanation loop is one of those things you get used to without realizing how much time it's costing. A few minutes at the start of each session, a few more after each compaction — it adds up.

More importantly, it's the kind of friction that makes you reach for Claude less. If you know you're going to spend the first ten minutes re-establishing context, you start to wonder if it's worth it.

MemClaw removes that friction. The context is there when you need it, isolated to the right project, and it doesn't disappear when the conversation gets long.

Stop re-explaining your projects. Install MemClaw:

# Claude Code
/plugin marketplace add Felo-Inc/memclaw
/plugin install memclaw@memclaw

OpenClaw

bash <(curl -s https://raw.githubusercontent.com/Felo-Inc/memclaw/main/scripts/openclaw-install.sh)

ClawHub

clawhub install memclaw

Full documentation: github.com/Felo-Inc/memclaw


Related: Managing 6 Clients with Claude Code: The Memory Problem Nobody Talks About · How to Give Claude Code Persistent Memory Across Sessions