I had a feeling something was off with my genealogy project.
The project is my family history site, built and researched with Claude Code. It has gone through 72 phases in about three weeks. And every time I sat down to plan a new phase, I’d see the same line scroll by: let me see what was done in the other phases.
That’s a reasonable thing for a person to say. It’s a less reasonable thing for a program to say every single time. So I ran /context in the middle of a research session to see what was actually in there.
596,000 tokens used out of a million. Of that, 553,000 were Messages, the conversation itself. CLAUDE.md, the file I worried about, was only 9,600.
I didn’t know yet what was in those 553,000 tokens. But I was pretty sure I’d put some of it there myself.
Finding the culprit
The first line of my CLAUDE.md said this:
Read docs/BRIEF.md (Matt’s brief: what the project should do) and docs/SPEC.md (what is built, how it works, and the decisions made) before doing anything.
I wrote that on day one, when SPEC.md was a few pages. It seemed like good hygiene. Then I looked at the docs folder.
-rw-r--r-- 1 matt matt 22260 Nov 20 12:22 BRIEF.md
-rw-r--r-- 1 matt matt 23910 Nov 23 15:25 DEPLOY.md
-rw-r--r-- 1 matt matt 1232755 Nov 25 23:00 SPEC.md
SPEC.md was 1.2 megabytes. At roughly four characters a token, that’s about 300,000 tokens. One file. And I’d told Claude to read it before doing anything.
The spec had grown the way these things grow. Every phase added its plan, its checkpoint and its “what got built” notes. Every decision I made went in a table. Nothing ever came out. By the end it held 72 phases of history and 214 decision rows, most of them about work long finished.
There’s a second problem with a file that size, and it’s sneakier. Claude’s file reader only returns so much in one read. So it may not read all of it. It may read the beginning, which was my oldest phases. That’s the most out-of-date part of the whole document.
What I learned about context
I’d been fuzzy on how this actually works, so I asked Claude to walk me through it. Here’s the short version.
- CLAUDE.md loads in full at the start of every session. Once per session, not once per prompt. But it stays in the conversation, so it counts on every turn.
- A plain mention of a file loads nothing. “See spec.md” just tells Claude the file exists. It opens it only if it decides to.
- An
@import loads the whole file at startup. Write@docs/spec.mdand it’s in, every session, relevant or not. - “Read X before doing anything” behaves like an import, only worse. Claude reads it with its file tool every session, so it lands in Messages. In a long session it may read it again.
- Everything Claude reads stays. Every file, every search result, every tool output piles up in Messages until you clear or compact.
I was already running /clear between planning a phase and executing it. Planning burns a lot of context on ideas that get thrown away, and the plan file carries what matters into the build. What I hadn’t done was look at what loads after the clear. A clean start doesn’t buy much if the first thing it does is read a 300,000-token file.
The million-token window is what let this go on so long. With a smaller window I’d have hit the wall weeks ago. Room to spare isn’t the same as a good idea to fill it.
Why I didn’t just chop it
The obvious fix was to cut the old phases and move on. I didn’t want to do that, and I’m glad I didn’t.
This project runs on rules. Never write back to FamilySearch. No more than four research agents at once. Never mix one research question’s work with another’s. A living person can be named on the site but never given a page. I’ve built those up session by session, usually right after something went wrong. Losing one quietly would be worse than the token bill.
When we looked closer, the spec turned out to be four different things mixed together:
- A status table of all 72 phases. Four still open.
- A decisions table that mixed standing rules with one-off answers. Some rules had also been replaced several times. The daily cap on FamilySearch page images went from 20 to 40 to 80 to 300, then moved into a settings file. A careless split could keep an old version as if it were current.
- A reference for how every tool works, with real rules buried in the middle of it.
- The phase history, about 640 KB of it. This was the part that could safely go.
And two traps I hadn’t thought of. My own code read the spec. The script that writes my session logs pulled decision rows straight out of it, and so did the one that reviews tool proposals. Split the file carelessly and those break without saying anything. Then there were the references: CLAUDE.md, the READMEs and the slash commands all pointed at sections like “§5b” and “§14 Phase 17”. They all had to keep working.
Five sessions and a plan file
I went back and forth with Claude on the prompt a few times before I ran anything. Each round added something: the code that reads the spec, then my CLAUDE.md, then the brief. The version I ran said, near the top, in capitals: do not read docs/SPEC.md in full. Inspect it with wc, grep and small line ranges only. Reading the whole thing to fix the problem of reading the whole thing seemed like a bad start.
The work was too big for one context, so I split it into five stages, each in its own session with a /clear between. The memory across those clears was one file, docs/restructure-plan.md. Every stage starts by reading it, does only its own work, writes down what it did and what it verified, commits, and stops.
- Survey and rules inventory. Map the spec’s sections and sizes, and find every piece of code that depends on it. Then the part I cared about most: sort all 214 decision rows. 62 came out as standing rules, 127 as one-off answers and 12 as superseded, plus a handful in between. It found 17 rules that existed only in the spec and never made it into CLAUDE.md, including which model drafts phase plans. It also listed 14 places where my original brief now contradicts the project, like Find a Grave requests spaced 3 to 5 seconds apart when they’ve been 15 to 25 seconds since a 429 back on November 8. Then it stopped, and I reviewed every list.
- Move the content with a script, not through the context window. 85 new files: one per reference section, one per finished phase, and the decisions table moved whole. Then the check: put the pieces back together and compare them byte for byte against the original. It also counted every line to make sure each one appeared exactly once. Before trusting the check, it deliberately dropped a line, duplicated a line and altered a header, and confirmed the check failed each time.
- Write the new always-read files. A rules file, a slim spec, a lean brief.
- Fix the code. The session log and proposal scripts now read the new homes, with a fallback for sessions that span the move. 2,567 Python tests and 442 Pest tests passed, on SQLite and MySQL.
- Test it cold. A fresh session got only the new always-read files and 18 questions. How many agents at once? Can you cite WikiTree for a birth date? A 1938 deed names a witness who isn’t in the tree. Could they be living? It got all 18 right and cited the file and line for each. One question was a trap: it asked for a number that’s deliberately not in the always-read files. It didn’t guess. It went and looked it up.
The review in stage 1 was where I earned my keep. A couple of my decisions came out of it:
- Rules got IDs and their own file. Every standing rule now lives once, in
docs/RULES.md, as R-001 through R-053. CLAUDE.md pulls it in with an@import, so the rules are loaded every session whether Claude thinks it needs them or not. My words at the time: “I like the idea of rule IDs. can we make this @-imported to CLAUDE.md?” - The brief got lean. The original was 22 KB of requirements, most of them built long ago, and a few out of date. Now it’s an 8 KB statement of what the project is for, and the original is archived untouched.
- A few rules changed while I was looking at them. One I reversed outright. Another I struck because it wasn’t really a rule, just a note about how one tool happened to be built. And one I made official: “an adult in 1945 or earlier is dead. treat them as such.”
The numbers
What a session reads before it starts work went from about 318,000 tokens to about 14,500.
| File | Before | After |
|---|---|---|
| docs/SPEC.md | 1,232,755 bytes | 18,951 bytes |
| CLAUDE.md | 28,366 bytes | 10,207 bytes |
| docs/BRIEF.md | 22,260 bytes | 8,604 bytes |
| docs/RULES.md | didn’t exist | 29,601 bytes, imported |
One number went up on purpose. The “Memory files” line in /context grew from 10.8k to 14.9k tokens, because the rules are now imported instead of read when Claude feels like it. I’ll pay 4,000 tokens to know every rule is in front of it every time.
The real test was boring, which is what I wanted. I cleared, asked “summarize FS-198 for me,” and checked /context after it answered. Messages: 13.4k. Before this, that question would have started with a big chunk of a 300,000-token spec.
Long research sessions still climb into the hundreds of thousands. That’s fine. That’s real work: agent reports, searches, records. It’s not the same stale history being reloaded.
What I’d tell you
If you’ve been running a Claude Code project for a few weeks, it’s worth five minutes:
- Run
/contextin the middle of a real session. Look at Messages, not just CLAUDE.md. - Check what your CLAUDE.md tells Claude to read. “Before doing anything” is expensive if the file keeps growing.
ls -alyour docs folder. If something is over a few hundred KB, ask why.- Keep current state and history in separate files. Claude needs to know where the project stands, not every step it took to get there. The code is a better record of what got built anyway.
- Put your rules in one place and import them. Then test that a fresh session can actually answer questions about them.
- Clear between planning and doing, and make sure the plan file holds what you decided.
The part that went wrong was mine. I wrote a sensible instruction on day one and never looked at it again while the file it pointed at grew past a megabyte. The fix took a couple of hours and five sessions. Most of that was me reviewing lists, which is the part I wouldn’t skip.
The spec is now a page you can read. Not bad for a file that used to be bigger than some of my sessions.
Say something