Claude Code 3-Layer Memory Architecture: What 512K Lines of TypeScript Revealed
Description
When 512K lines of Claude Code's TypeScript source leaked, most attention went to the model interactions. The interesting part was the **memory architecture** — elegant, model-agnostic, and directly applicable to any agentic system. The key insight from the codebase: **if it can be looked up, it should not be remembered.** Layer 1 is `MEMORY.md`, always loaded. The foundation is not a database or an embedding store but a lightweight markdown file injected into every context window automatically, and its design constraints are the whole trick: it is an **index, not storage** — each line a pointer to where information lives rather than the information itself, a table of contents rather than the book. Each line stays under 150 characters, so brevity is enforced and the index stays useful as context grows. Only the first 200 lines are injected, with the rest available for lookup. The always-on context stays tiny: no bloat, no tokens spent on what the agent does not need right now. Layer 2 is topic files, loaded on demand — separate markdown files, one per topic, pulled in only when the index says the topic is relevant. Layer 3 is old conversation transcripts, searched with **plain text search rather than a vector database**, which is the choice most readers find surprising and is defensible for exactly the reason the insight states. Part 12 of the Agentic AI Builder's Playbook.
Series part SER-AGT-012. Originally published at https://www.maxresearchcollective.com/articles/claude-code-3-layer-memory-architecture.html
Files
claude-code-3-layer-memory-architecture.pdf
Additional details
Related works
- Is identical to
- Other: https://www.maxresearchcollective.com/articles/claude-code-3-layer-memory-architecture.html (URL)