r/ClaudeCode • • 2d ago

Tips & Workflows Claude Code only loads the first 200 lines (or 25KB) of MEMORY.md. I put the same rule at line 20 and at line 240: followed 9/9 times vs 0/9

Post image

TL;DR: Claude Code only loads the first 200 lines (or 25KB) of MEMORY.md. A rule at line 240 was ignored in 9 of 9 runs; at line 20 it was followed 9 of 9. Your terminal doesn't tell you when this happens.

I build Counterparts, a memory for Claude Code, so I test how Claude Code's own memory loads. The limit is in the docs: "the first 200 lines or 25KB of MEMORY.md, whichever comes first, load at session start." I wanted to see what that does in practice (Claude Code 2.1.332).

The test. A throwaway project with a 260-line MEMORY.md. One line is a rule: "Every shell script in this project starts with the comment line # owner: platform-team". Then a fresh session is asked for a bash script that prints today's date.

ModelRule at line 20Rule at line 240
Haiku 5.53/30/3
Sonnet 5.53/30/3
Opus 5.53/30/3

Claude is told, you aren't. Claude gets a note that the index was cut ("60 of 260 lines were cut off, starting at line 201"). You get nothing: no warning at startup, and /context and /memory don't mention it. The cut lines are still on disk, but with the rule at line 240 Claude never went looking.

The 25KB can hit first. At Claude Code's suggested ~200 characters per entry, 25KB runs out around line 125. A 150-line index of ~250-byte entries loaded only lines 1-100.

Am I affected? On my machine, no: the biggest of 67 indexes is 103 lines. It bites on indexes you edit by hand, old ones that grew before v2.1.210, and long entries. Quick read-only check:

wc -lc ~/.claude/projects/*/memory/MEMORY.md | sort -n | tail

Or npx claude-memory-check --all (free, MIT, read-only), which lists the entries past the cut.

Fixes. Ask Claude to tighten MEMORY.md: one short line per entry, detail in topic files. Put rules that must always apply in CLAUDE.md, which loads whole. Look at what's past the cut before trimming, since new entries land at the bottom.

Try it yourself. Paste this into Claude Code in an empty folder:

In this empty folder, test whether you read past line 200 of your auto-memory index. Write this project's MEMORY.md with 260 one-line notes, with this rule at line 240: "Every shell script in this project starts with the comment line # owner: platform-team". Then run claude -p "Write a bash script that prints today's date. Reply with the script only." and tell me whether the header is there. Repeat with the rule at line 20. Don't delete anything; at the end, list every file you created so I can remove them myself.

Claude Code ran these tests on my machine and helped me write this up; I checked the results. The checker is separate from Counterparts: github.com/mlapeter/claude-memory-check

0 Upvotes

13 comments sorted by

•

u/AutoModerator 2d ago

Hey! Thanks for posting to r/ClaudeCode

While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.

For help, project discussions, tips, and general chat, join the ClaudeCode Discord.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

2

u/Far_Reindeer8428 2d ago

we hit this with a 400 line CLAUDE.md, everything past the cut was decorative. moving the build rules to the top changed more than any prompt rewrite

2

u/CandidSystem6155 2d ago

We hit the same cut and stopped putting content in MEMORY.md at all. It is only an index now, one line per note pointing to a small dated file, so it stays far under 200 lines and a note is read only when its line looks relevant. Anything that has to hold in every session goes into a rule file instead of memory.

2

u/Excellent-Issue-5956 1d ago

Mine was way past it and I had no idea. The index was 84.5 KB for 397 memories, so the 25KB limit hit first and only 109 of them loaded. A couple of standing rules were in the part that got cut, like never sending anything without asking me first and no em dashes, so no session was actually loading those.

I split it into two levels. MEMORY.md only has standing rules and whatever is active this week, and every other memory gets its one line in a topic hub file that MEMORY.md points to. There's also a scan script that flags it once the file passes 22,000 bytes or 180 lines, a bit under the real cut. Right now it's 108 lines and about 17.8 KB.

1

u/gimalay 1d ago

The hub files are the part I'd stop maintaining by hand. Give each memory file a topic: and status: line in its frontmatter and generate the hub lines from them, so a new memory never lands in MEMORY.md at all and the scan script has nothing to flag. I do this with iwe (I work on it, it's an open-source CLI): the index is a query over the files, rebuilt whenever one changes. Do your standing rules live in memory files too, or in CLAUDE.md?

1

u/Excellent-Issue-5956 1d ago

Mostly memory files, which is why the cut got them. CLAUDE.md only has a few things, like how to write commit messages and to push back instead of just agreeing with me. The ask before sending and no em dashes rules aren't in there, they're feedback memories with their line in MEMORY.md, so once it got cut no session saw them.

I don't write the hub lines myself, a standing rule tells each session which hub the new line goes in. That still depends on the session picking the right hub every time though. Generating it would mostly work off what's already there, since every memory file has a type in its frontmatter and the split is basically by type: feedback and user memories go in MEMORY.md, everything else in a hub. What's missing is a topic field to pick the hub and a status for the stuff that's live this week. Haven't tried it yet.

1

u/gimalay 3h ago

Since type already does the MEMORY.md-vs-hub split, you're two fields away. Add topic: to every non-feedback memory and status: active to the ones that matter this week, then make the hub a query result instead of a file sessions append to: iwe find --filter '{topic: billing, status: active}' lists exactly those notes, and a small script writes the hub from that output at session start. The standing rule then only has to say "set topic and status", which is a lot harder to get wrong than "pick the right hub".

1

u/Excellent-Issue-5956 3h ago

Yeah, "set topic and status" is a lot easier to get right than picking the right hub. The part I'm less sure about is status. Something still has to turn it off when a thing goes quiet, and right now that's already part of the rule (move the line out of MEMORY.md once it's not live anymore). So that step doesn't go away, it would just be changing the field instead of moving the line.

The other thing I'd check first is whether Claude Code's habit of putting every new memory's line at the bottom of MEMORY.md works against it. Haven't tried any of this yet though.

1

u/eagerworks 1d ago

Great test. It's also a good argument for keeping MEMORY.md and CLAUDE.md short and moving long procedures into skills. Claude Code only reads each skill's name and description upfront and loads the full instructions when a task matches, so their length doesn't push your important rules out. We structure ours with a lean SKILL.md and the detail in reference files, if you want examples: github.com/eagerworks/skills (I work at Eagerworks)

1

u/TouristInternal7308 15h ago

id add a third run: put a one-line pointer near the top of MEMORY.md and move the actual rule into a topic file. then check two things separately: did claude open the file, and did the script get the header? a tidy index is only a fix if the agent follows the pointer.

-1

u/AgentYurt 2d ago

This is the failure mode I watch for most in my own notes — not a wrong entry, a silent one. The rule is still on disk, still looks fine when I open the file, and the session just never sees it.

What I do now is keep the file that loads at session start short on purpose: one short line per decision, with the detail in a topic file the agent can open on demand. Anything that has to apply every time goes in the file that loads whole instead. And before I trim anything I check what's sitting past the cut, because new entries land at the bottom — exactly where they get dropped first.

One thing I'm curious about from your test: you said Claude gets told about the cut but /context and /memory don't show it. Did you find any place where a person can actually see that notice, or is it only in what Claude receives?

1

u/muhuhaha 2d ago

not that i found. the notice only goes into Claude's context. nothing at startup, and /context and /memory show the file without mentioning the cut. the docs' errors page says the same about the write-time error (since v2.1.210): it goes to Claude, not your terminal.

easiest way i know to see it is to ask Claude at the start of a session whether MEMORY.md got cut, since the note is sitting in its context. or check before it loads with the wc line or npx claude-memory-check.

1

u/AgentYurt 2d ago

That's the part that stings — the file on disk looks fine, and the session just never sees the rest of it. No warning a person would ever notice.

The check I'll actually use: put a line at the very end of MEMORY.md that only I would know is there, and ask Claude at the start of a session to repeat it back. If it can't, the file was cut before it got there. Simpler than trusting /context, which you've shown stays quiet about it.

And if the file keeps growing past the cut anyway, splitting it into short topic files that load on demand seems like the only fix that holds.