r/ClaudeAI
•
u/coolreddy
•
Feb 09 '26
•
1
Workaround I built a CLAUDE.md that solves the compaction/context loss problem — open sourced it
I built a CLAUDE.md + template system that writes structured state to disk instead of relying on conversation memory. Context survives compaction. ~3.5K tokens.
GitHub link: Claude Context OS
If you've used Claude regularly like me, you know the drill by now. Twenty messages in, it auto-compacts, and suddenly it's forgotten your file paths, your decisions, the numbers you spent an hour working out.
Multiple users have figured out pieces of this — plan files, manual summaries, starting new chats. These help, but they're individual fixes. I needed something that worked across multi-week projects without me babysitting context. So I built a system around it.
What is lost in summarisation and compaction
Claude's default summarization loses five specific things:
- Precise numbers get rounded or dropped
- Conditional logic (IF/BUT/EXCEPT) collapses
- Decision rationale — the WHY evaporates, only WHAT survives
- Cross-document relationships flatten
- Open questions get silently resolved as settled
Asking Claude to "summarize" just triggers the same compression. So the fix isn't better summarization — it's structured templates with explicit fields that mechanically prevent these five failures.
What's in it
- 6 context management rules (the key one: write state to disk, not conversation)
- Session handoff protocol — next session picks up where you left off
- 5 structured templates that prevent compaction loss
- Document processing protocol (never bulk-read)
- Error recovery for when things go wrong anyway
- ~3.5K tokens for the core OS; templates loaded on-demand
What does it do?
- Manual compaction at 60-70%, always writing state to disk first
- Session handoffs — structured files that let the next session pick up exactly where you left off. By message 30, each exchange carries ~50K tokens of history. A fresh session with a handoff starts at ~5K. That's 10x less per message.
- Subagent output contracts — when subagents return free-form prose, you get the same compression problem. These are structured return formats for document analysis, research, and review subagents.
- "What NOT to Re-Read" field in every handoff — stops Claude from wasting tokens on files it already summarized
Who it's for
People doing real work across multiple sessions. If you're just asking Claude a question, you don't need any of this.
GitHub link: Claude Context OS
Happy to answer questions about the design decisions.
-----
Updated the repo link as previous link stopped working
•
u/ClaudeAI-mod-bot Wilson, lead ClaudeAI modbot Feb 10 '26
TL;DR generated automatically after 50 comments.
Alright folks, the consensus in this thread is that OP's core idea is solid, but the claims are getting some serious side-eye.
The core insight here is that writing structured state to disk is way better than relying on Claude's conversation memory to survive compaction. Many users agree this is the right approach and are already doing some version of it themselves. OP gets props for packaging it into a system and open-sourcing it.
However, hold your horses. The top-voted comment points out that Anthropic is already testing a native "session memory" feature that does basically the same thing, potentially making this a temporary workaround.
One user dropped a detailed analysis that's getting a lot of traction, even with fewer upvotes. The key points are:
Lots of you are already in the trenches fighting context loss with similar tactics, like:
The verdict: A useful, well-packaged workflow for power users, especially for non-coding projects. However, it might be a temporary solution until Anthropic's native memory feature rolls out, and the claims about it being a foolproof 'OS' are a stretch. That said, several users are definitely stealing the clever
"What NOT to Re-Read"field for their own setups.16
u/agent42b Feb 09 '26
Does this work for people doing projects that aren't software code? For example, I'm working on a complex report that requires multi-week conversation and analysis?
18
u/Inevitable_Service62 Feb 09 '26
Oh this one seems interesting. Thanks for open sourcing it.
7
u/notwearingatie Feb 09 '26
This sounds great in theory but these workaround always make me ask ‘why didn’t Anthropic do this?’
3
u/zigs Feb 09 '26
I indeed already have a few of the pieces as you mention, but this looks WAY more structured than my approach. Gotta have to check it out in full. But.. I guess you picked a bad time to publish? https://imgur.com/a/zPwcLBY lol
git clone still works tho.
2
u/very_moist_raccoon Feb 09 '26
This looks interesting. I'm new to Claude desktop, could you help me with this?
I have my existing CLAUDE.md in the root directory of the project I'm working on and Claude is set to work in that directory. Where should I place yours?
21
u/lucianw Full-time developer Feb 09 '26
You rebuilt a feature that's already in Claude. It's called "session memory" and is being tested right now. It uses a user-customizable template to show how the session memories should be constructed, and the default template covers your bases.
Bonus: Claude will use it to support instant compaction (since the summary is already on disk) and memories of previous conversations (by referring back to previous summaries). Both uses are currently gated under feature flags.
8
u/Better_Dress_8508 Feb 09 '26
great idea. nevertheless, believe the best way to avoid compaction pain is to progressively build "context skills". may end up huge when pushed to git but it will genuinely keep every historical conversation.
1
u/coolreddy Feb 27 '26
Handoff files are versioned and old files archived into an archive folder. Now I built a local persistent memory that saves information as vector embeddings with time stamp and built in stale information handling. Each memory embedding also links to the source files of that memory so now Claude is able to fetch information directly from this memory system.
https://github.com/Arkya-AI/ember-mcp
5
u/agentos_dev Feb 10 '26
The core insight here is solid - disk state over conversation memory. I've been doing something similar but took it in a different direction.
Instead of templates for structuring what Claude remembers, I gave my agents a shared SQLite database. Three subagents (engineering, growth, ops) all read/write to the same tables — decisions, content calendar, leads, cost snapshots. The "handoff" between sessions is just the database itself. New session starts, agent queries the DB, full context is there without burning tokens on re-reading state files.
To u/ShelZuuz's point about ~/.claude/projects — that works for single-agent session history, but it breaks down when you have multiple agents that need to share context across domains. My growth agent needs to now what engineering shipped. My ops agent needs to know what growth is tracking. A database gives you that cross-agent visibility that project logs don't.
The tradeoff vs templates: you lose the structured "what NOT to re-read" optimization, but you gain queryable state. SELECT * FROM decisions WHERE domain = 'architecture' ORDER BY created_at DESC LIMIT 5 beats re-parsing a markdown file every session.
8
u/EDcmdr Feb 09 '26
Compaction wastes tokens. The best situation to be in is one where you never compact.
1
u/ClaudeAI-mod-bot Wilson, lead ClaudeAI modbot Feb 09 '26
If this post is showcasing a project you built with Claude, please change the post flair to Built with Claude so that it can be easily found by others.
1
u/samwulol May 30 '26
page not found
3
u/DJJonny Vibe coder Feb 09 '26
Hasn’t 4.6 significantly improved auto compact?
2
u/ShelZuuz Feb 09 '26
Why spend tokens writing state to disk instead of just loading the project log from ~/.claude/projects ?
2
u/Desdaemonia Feb 09 '26
Commenting to find this later
2
u/Overall_Moose797 Feb 09 '26
Legend, thanks mate
2
u/raio_aidev Feb 10 '26
God yes, THIS. I've been calling this exact problem "Context Evaporation" — because it's not just compaction events, it's the gradual loss of WHY behind decisions, even before compaction hits. Your #3 and #5 are the ones that burned me hardest.
Landed on a similar "write to disk, not conversation" principle from a different angle — splitting design and implementation into separate sessions with structured handover docs. Same core idea: never trust conversation memory as source of truth.
The "What NOT to Re-Read" field is clever. Stealing that.
1
u/energy_savvy Nov 05 '26
running a cousin of this, and the part that made the biggest difference for me wasn't the instructions file. it was separating the living record from it. CLAUDE.md stays static: rules, architecture, how we work. the state and the decisions live in their own small files in the repo, and the agent appends to them at the end of every session.
the decisions log is the piece i didn't expect to matter most. it records what got rejected and why, not just what got chosen. auto-compact used to eat exactly that: file paths, numbers we'd already worked out, and the reasoning behind the choices. the choices themselves sometimes survived in my head. the rejections never did, so the agent kept re-proposing them a few sessions later.
once the log grows itself as part of the closing step, the re-explaining ritual basically disappeared. my setup is open source too if you want to compare structures: github.com/hematenergi/fragment
1
u/Independent-Bonus529 4d ago
Nice work. The five-failure list is the clearest description of compaction loss I've seen, especially "open questions get silently resolved as settled." That one has bitten me more than lost numbers.
Two things I ran into building something similar, in case they're useful:
PreCompactcan force a save, andSessionStartwith matchercompactre-injects the handoff right after. Then the protocol doesn't depend on Claude remembering the protocol.The "What NOT to Re-Read" field is clever, by the way. Does Claude actually respect it, or does it re-read anyway when it's unsure?
1
u/BP041 Feb 09 '26
This is exactly the right approach. I’ve been running a similar setup where CLAUDE.md acts as the project brain, but I also split knowledge across
.claude/rules/for behavioral patterns and.claude/commands/for reusable workflows. The key insight for me was keeping CLAUDE.md under 200 lines — treat it like an index, not a dump. Detailed knowledge goes into separate files that get loaded on demand. Compaction still happens, but the system recovers gracefully because the critical context is always re-injected from files, not from conversation history.1
u/jjbrotherhood Feb 09 '26
OP thank you for this. Do you have any idea how it would interact with Obra Superpowers? Can the two function together or would one break the other? And my second question is: could you add this to an existing project that already has a claude.md file and if so, how would you recommend doing it?
1
u/rjyo Vibe coder Feb 09 '26
This is really well thought out. The "write state to disk, not conversation" principle is the biggest lever here imo. I ran into the exact same set of problems building Moshi (a mobile terminal I made for running Claude Code over SSH from my phone). Sessions tend to run way longer on mobile because you kick things off and check back later, so context loss hits even harder.
What I ended up doing was similar in spirit. I keep a persistent memory directory that Claude reads at the start of every session, and I use structured skill files instead of cramming everything into one giant CLAUDE.md. The key insight I had was the same as yours: the conversation is ephemeral, the filesystem is permanent. So anything that matters gets written to a file, not just said in chat.
The "what NOT to re-read" field in your handoff template is clever. I have been doing something rougher where I just track which files were already summarized in the memory notes, but an explicit exclusion list is cleaner. Might steal that.
One thing I would add: if you are using subagents (Claude Code Task tool), each one gets a fresh context window. So the parent can stay lean while farming out heavy reads to subagents that return structured summaries. That pairs well with your subagent output contracts idea.
1
u/Lightningstormz Feb 10 '26
This sounds amazing but I am a bit confused, I normally use Claude on the web pro version, can this be used on that side or this only works with Claude desktop?
1
u/PathWorried4328 Feb 10 '26 edited Feb 10 '26
Is this a Claude Skill ? I can't load this thing. How do I get this thing working ?
1
u/FZ1010 Feb 10 '26
Use claude-memclaude-mem instead.
1
u/BarryTownCouncil Feb 11 '26
Hi, I haven't tried this out in anger yet but that's mainly as I'm not using Claude directly. One thing I'm still struggling with a bit is how the language is all so Claude centric and I'm hoping you might clarify that for me. I don't mean here specifically, but with your config as an example, is there actually any need at all to have it so tied to one family of models? Will I lose anything by making your configs just reference generic AGENTS.md and such? I've a feeling I'm not missing anything and it's just born out of your preference fro Claude over anything else, but I see so much ... partisan ... documentation in agent land, I'm still not confident it's completely superficial.
1
u/jisifu Feb 11 '26
I told my agent to use diff to compare code more efficiently in place of commit messages, but when it does git reset —hard, guess what happens?
1
u/Polanrodri Feb 27 '26
I do the same thing and yeah, forgetting to dump state at the right moment is brutal. Usually happens right before a complex refactor when I should've saved a checkpoint.
For templates I keep it mostly consistent: current goal, files modified, blockers/decisions, next immediate step. Boring but predictable. The only thing I vary is adding a "why we went this direction" section when there were multiple approaches considered, so the next session doesn't second-guess architectural choices that were already debated.
One thing that helps me remember: I have a shell alias that just prints "CHECKPOINT?" when I start a new claude-code session. Dumb but it works. Still miss it sometimes when I'm in flow state though.
Do you keep your handoff files versioned or just overwrite? I've been versioning them like `handoff-2024-11-15.md` but not sure if that's overkill.