TL;DR
Agent memory is what an AI agent knows when a new session starts. Without it, every session begins from zero.
Claude's built-in memory helps, but Claude Code reads only the first 200 lines of MEMORY.md and 10,000 characters of hook text.
The setup that lasts is plain markdown files, a small recall budget and a nightly cleanup. No vector database needed below about 50,000 notes.
Every AI agent I use forgets. Claude Code, Codex, Grok Bot: close the session and the decisions, the people and the dead ends are gone. The next session starts from zero, and I explain the same things again.
I spent most of 2026 fixing that for myself. The result is obsidian-second-brain, a free memory layer that 8 AI agents can share. It has over 5,400 stars on GitHub.
This guide puts everything I learned in one place. What agent memory is, what Claude already gives you, why agents still forget, and the setup that holds up.
What is agent memory?
Agent memory is what an AI agent knows at the start of a session without you telling it again. It sits in three layers:
Working memory. The context window: everything in the current chat. It is gone when the session ends.
Project memory. Rules files such as CLAUDE.md or AGENTS.md, read at the start of every session.
Long-term memory. Decisions, people, lessons and history, stored outside the model and pulled in when they matter.
Most "my AI forgot" problems are a missing third layer. Models do not learn between your sessions. Whatever your agent knows next week, something outside the model has to store it and hand it back.
What are the types of agent memory?
Research papers and memory tools sort long-term memory into three kinds. Semantic memory holds facts, like your stack or a client's name. Episodic memory holds what happened, like last week's session and why a fix failed. Procedural memory holds how to do things, like your rules and saved workflows. One notes folder can hold all three: fact notes, a dated log and rules files.
What memory does Claude have built in?
Claude gives you three kinds today:
Chat memory in the Claude app, which carries facts across conversations.
Projects, which hold files and instructions for one topic.
Auto memory in Claude Code, which writes a MEMORY.md file per project. It is on by default.
All three remember the project more than they remember you. Auto memory keeps things like a test command or a lint setting. It does not keep why you rejected an idea in March.
They also have size limits. Claude Code loads only the first 200 lines or 25KB of MEMORY.md. Anything past that point is never read.
Why do AI agents forget?
Agents forget for three reasons, and I have hit all three.
The window resets
The context window is the only thing a model sees. When the session ends, it empties. Long sessions get compacted, which means summarized, and the summary drops details.
Memory gets cut without a warning
Hooks are small scripts that can hand Claude your notes when a session starts. Claude Code reads only the first 10,000 characters of that text. Past the limit, it saves the text to a file and shows Claude a 2,000-character preview. Nothing tells you this happened.
My own hook sent 11,970 characters. 0 of my 20 newest jobs reached Claude, and I found out only because a user reported it. I wrote up the 10,000-character limit and the fix: newest items first, and under 10,000 characters.
Old notes go stale
Notes do not delete themselves. A decision from June still sits next to the one that replaced it in October. If the agent reads both, it can pick the wrong one.
Do you need a memory tool or a vector database?
Probably not. In October, a study called Memory Tax tested 11 AI memory tools against plain search over the raw chat history. Search won in 90 of 99 head-to-head results. The tools rewrite your history into short notes, and the rewrite drops facts. A second study found no memory tool beat the best search setup. I covered both in AI memory tools lost to search.
My own numbers point the same way. In June, my vault search found the right note in the top 10 zero times on 35 test questions. By July, with meaning search running on my own laptop, it found the right note 77% of the time. The fix was better search and cleaner notes, not a new memory product.
Below about 50,000 notes, plain text search with a hard limit on what it returns beats a vector database. It is faster, and you run nothing extra beside it. I explained how my recall hook works without a vector database.
How do you give Claude a memory that lasts?
This is the setup I run, and the one obsidian-second-brain installs. It has five parts:
One folder of markdown notes. An Obsidian vault works. Plain files mean any agent can read them, and you can open and fix any fact.
A rules file. CLAUDE.md or AGENTS.md tells the agent where the memory lives and how to write to it.
A recall hook with a budget. On each prompt, a hook searches the notes and adds at most 4 notes, about 900 characters. When it is not confident, it adds nothing.
Write-back. At the end of a task, the agent saves new decisions, people and lessons to the right note.
A nightly cleanup. A scheduled agent fixes contradictions, links orphan notes and rebuilds the index, so the next session starts from clean notes.
The budget in step 3 matters most. Memory that floods the prompt crowds out the task. Four short notes that fit beat forty that do not. The install takes about 5 minutes, and every step is in the obsidian-second-brain setup guide.
How do several AI agents share one memory?
Point them all at the same folder. That is the whole trick, and it works only because the memory is plain files.
One codebase in obsidian-second-brain builds the same commands for 8 agents, including Claude Code, Codex, Gemini and Grok Bot. I run one vault across four command-line agents every day, and most of the 45 commands run on all four.
Agents also need to know what the others did. Crew, a shared logbook in obsidian-second-brain, records each finished job. So Codex sees what Claude Code did an hour ago.
Where does agent memory break?
At a few hundred notes, a setup that is only "Claude reads my folder" starts to fail. At 2,000 notes you cannot load the whole vault into context, and simple search misses the chain of cause and effect. Old notes go stale, and nothing prunes them.
Karpathy's LLM wiki pattern runs into the same wall. I covered how I rebuilt Karpathy's LLM wiki so it maintains itself, and what to keep from LLM Wiki v2.
The other risk is ownership. Built-in memory lives on someone else's server, inside one product. A file-based memory is yours. You can read every fact, fix the wrong ones and move to a different model later. I compared both in Claude Code as a second brain.
A vault you own can even push back: my Obsidian vault argues with me before I repeat an old mistake.
What about a company brain?
The same problem gets bigger in a team. Each person's knowledge sits in their own notes, chats and head, and the agents they use see none of it.
I tested the two places most teams keep notes. In a 50-note test with Claude, Obsidian and Notion both scored 36 of 36. Obsidian took a median of 27 steps and $0.11 a run. Notion took 64 steps and $0.25.
Team memory needs more than a shared folder: one home per fact, an owner for each note, and rules for who can change what. That is the next problem I am working on.
Want the ready-made version? The Vault has AI tools for paid members, each set up in 10 minutes or less.
Frequently asked questions
What is memory in AI?
Memory in AI is what a model or agent can recall from before the current request. The model starts fresh every session, so memory is stored outside it and handed back: a rules file, saved notes or a searchable history.
Does Claude have built-in memory?
Yes. The Claude app saves memory from your chats as topics, and each project keeps its own memory. Claude Code writes a MEMORY.md file per project and loads only the first 200 lines or 25KB of it.
Does Claude have memory for free?
Yes. Memory is on by default for Free, Pro, Max and Ultra plans on the web, desktop and mobile apps. Searching your past chats needs a paid plan.
What is the best memory for AI agent?
For most people, plain notes you own plus good search. In the Memory Tax study, search over the raw history beat 11 memory tools in 90 of 99 results. Below about 50,000 notes you do not need a vector database.
How to use memory for AI agents?
Keep one folder of markdown notes and add a rules file that says where the memory lives. Let a hook add at most 4 relevant notes per prompt, have the agent write new decisions back, and run a nightly cleanup.
How do I share memory between Claude Code and Codex?
Point both at the same folder of markdown notes, and give each a rules file that says where the memory lives. obsidian-second-brain builds this for 8 agents from one codebase.
Key takeaways
Agent memory is what an AI agent knows when a session starts, and the model itself never keeps it between sessions.
Claude Code reads only the first 200 lines or 25KB of MEMORY.md, and only 10,000 characters of hook text.
Plain search beat 11 AI memory tools in 90 of 99 results in the 2026 Memory Tax study.
A recall budget of about 4 notes per prompt keeps memory from crowding out the task.
Plain markdown files let several AI agents share one memory, and let you fix any wrong fact by hand.
A memory that is only "the agent reads my folder" breaks at a few hundred notes without a cleanup.
Further reading
Claude Code memory docs, Anthropic
Memory Tax paper, arXiv, October 2026
Karpathy's LLM Wiki gist, Andrej Karpathy
The components of agent memory, Anthropic
About the author
I'm Eugeniu Ghelbur, an AI Automation Engineer working on agent memory. I built obsidian-second-brain, an open-source memory layer that 8 AI agents can share. It's MIT-licensed and starred by over 5,400 people on GitHub. I write The AI Operator.








The rule that the hook adds nothing when it isn't confident matters more than the four note cap, I think. A wrong note in the prompt is worse than an empty one, because the agent treats whatever it's handed as true. Most memory setups tune how much to recall and skip the question of when to recall nothing.
Low key I needed this one. my agents keep forgetting stuff from last week and I just keep re-explaining the same context over and over, the plain files thing is way simpler than I thought it would be. do you run the nightly cleanup on a schedule or just when you remember?