Claude Code Memory: How to Give Your AI Agent a Second Brain (2026)
Claude Code has built-in memory — a CLAUDE.md file it reads each session — but it only holds short, hand-written notes. To make it understand a large codebase or docs set, you add a second brain: turn the repo into a knowledge graph, fold that into an Obsidian vault, and let the agent query the map instead of re-reading every file.
This is a practical map of how Claude Code remembers things — from the built-in file most people underuse to the knowledge-graph 'second brain' that helps it reason over a large repo. No hands-on benchmarks here; it's the working approach and the real tools, with the trade-offs stated plainly.

Why does Claude Code 'forget' on a big codebase?
An AI coding agent only knows what fits in its context window. On a large repository it can't hold every file at once, so each session it re-reads or greps the parts it guesses matter — and loses how those parts connect. People call that a memory problem; it's closer to a map problem.
Claude Code's built-in answer is CLAUDE.md, a file of notes it loads at the start of every session. That's genuinely useful for conventions, commands, and 'always do X' rules. But it's small and hand-maintained — not a way to map a 100,000-line codebase or a 150-page documentation set.
What are the three layers of Claude Code memory?
Treat memory as three layers, each fixing a limit of the one below. Most setups stop at the first and hit a wall on large projects.
- Claude Code
Anthropic's terminal coding agent. Its CLAUDE.md file is the built-in memory layer — set that up before adding anything else.
- MCP Memory Server
A Model Context Protocol server that gives the agent a persistent place to store and recall facts between sessions.
- MCP Sequential Thinking
An MCP server for structured step-by-step reasoning — handy alongside memory on complex, multi-step work.
- 01Built-in project memory (CLAUDE.md) — hand-written notes the agent reads every session. Best for conventions, commands, and rules you'd otherwise repeat.
- 02A persistent store (an MCP memory server) — lets the agent save and recall facts across sessions over the Model Context Protocol, instead of you re-typing context each time.
- 03A knowledge graph (the second brain) — a generated map of the whole codebase or docs: the concepts and how they connect, so the agent reasons over relationships instead of reading file by file.
How do you turn a repo into a knowledge graph?
A knowledge graph reads a codebase or a folder of documents and pulls out concepts (nodes) and the links between them (edges), then groups related concepts into clusters. Instead of searching text, the agent follows connections — what relates to a sub-agent, what touches the context window, and why.
Graphify does this from inside Claude Code: point it at a repo and it parses the real code — functions, classes, imports, call graphs — not just file names. It handles docs, schemas, scripts, and images too. In one public walkthrough, pointing it at the roughly 145-page Claude Code documentation produced about 590 linked concept notes — fewer than one note per file, because it maps ideas, not pages.
The payoff is retrieval that understands structure. Ask about sub-agents and the agent already has the connected concepts — agent teams, separate context windows, hooks — because the map encodes relationships, not just keywords.
- Graphify
Open-source skill that turns a codebase or document set into a queryable knowledge graph from inside Claude Code (and other agents), with an --obsidian export. Not yet in the Vibedonalds directory.
How do you fold the graph into Obsidian — and should you?
Graphify's --obsidian flag turns the graph into a vault: every concept becomes a markdown note and every connection becomes a backlink, so the map opens in Obsidian's own graph view. A second pass wires each note to its source document, so the agent lands on the real text, not a bare label.
The catch is volume — a real graph can drop hundreds of notes into your vault at once. You have four ways to handle that, from safest to most invasive:
- Obsidian
Local-first markdown notes with backlinks and a graph view — the optional home for your knowledge graph if you want it beside your other project notes. Not in the Vibedonalds directory.
- 01Standalone vault — keep the import as its own vault. Self-contained and easy to throw away. Graphify does this by default.
- 02Quarantine subfolder — drop all the notes into one folder in your main vault. If you dislike the fit, delete one folder and you're clean.
- 03Cherry-pick — have the agent pull only the notes you want (say, everything about sub-agents) and ignore the rest.
- 04Redistribute — let the agent file each note into wherever it fits your existing structure. Most coherent, hardest to undo.
When is a second brain overkill?
For a small project, CLAUDE.md plus the odd note is plenty — building a graph and a vault is effort you won't recoup. The second brain earns its keep on large codebases, big documentation sets, or when you want one map shared across several projects.
It's one tool, not a default. Set up the built-in memory first, add a persistent store if you keep re-explaining context, and reach for a knowledge graph when the agent's real problem is that it can't see how a large system fits together.
Frequently asked questions
- Does Claude Code have built-in memory?
- Yes. Claude Code reads a CLAUDE.md file at the start of every session — your project's conventions, commands, and rules. It's the first memory layer and the place to start. Because it's small and hand-maintained, it doesn't replace a knowledge graph for large codebases.
- What's the difference between CLAUDE.md and a knowledge graph?
- CLAUDE.md is short notes you write by hand. A knowledge graph is generated: a tool reads the whole codebase or docs, extracts concepts and how they connect, and gives the agent a map to follow instead of grepping file by file. Use both — they solve different problems.
- Do I need Obsidian to give Claude Code memory?
- No. Obsidian is optional. The knowledge graph helps the agent on its own; folding it into an Obsidian vault mainly helps when you want that map beside your other project notes, or you prefer Obsidian's interface. Skip it if you only need the graph.
- Can I build a knowledge graph from a codebase, not just docs?
- Yes. Graphify parses real code — functions, classes, imports, call graphs — as well as docs, schemas, scripts, and images. The documentation example is just easy to demo; the same process maps an actual repository into concepts and connections.
- Will a second brain cut Claude Code's token use?
- It can, by saving the agent from re-reading many files each session to get oriented. How much depends on your repo and setup, so treat specific multipliers you see online with caution. The reliable win is better answers on large projects, not a guaranteed token number.