How to Give Claude Persistent Memory Across Sessions
Problem
Every time I started a new Claude session, I had to re-explain my project. Claude would forget:
- My coding preferences (functional over class components, etc.)
- Project architecture decisions I’d already discussed
- Bug fixes and solutions from previous sessions
- Custom patterns and conventions for my codebase
I was copy-pasting context files, re-explaining the same concepts, and losing accumulated knowledge with every new chat. The friction was real.
What I Tried First
I tried using CLAUDE.md files with detailed project context. That helped a bit, but I had to manually update them and they couldn’t store learnings from sessions.
Then I tried the Memory MCP server:
{ "mcpServers": { "memory": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-memory"] } }}This worked for simple key-value storage, but it had limitations:
- No full-text search
- No semantic understanding
- Couldn’t store and retrieve documents
- Not useful for accumulated knowledge over time
I needed something more powerful.
The Solution: Knowledge Base MCP Server
I found a pattern that works: connecting an Obsidian vault to Claude through a knowledge base MCP server.
Here’s the architecture:
+-------------------+ +----------------------+| Claude Session | | Obsidian Vault || | | (My notes, docs) |+--------+----------+ +----------+-----------+ | | | MCP Protocol | | |+--------v----------+ +----------v-----------+| Knowledge Base |<-------------->| SQLite Database || Server | | (FTS5 Index) |+-------------------+ +----------------------+The knowledge base server provides these tools:
| Tool | What it does |
|---|---|
kb_search | Full-text search with highlighted snippets |
kb_search_smart | Hybrid keyword + semantic search |
kb_context | Token-efficient summaries |
kb_read | Load full document by ID |
kb_write | Write notes to knowledge base |
kb_ingest | Ingest documents and files |
kb_capture_session | Record debugging findings |
kb_capture_fix | Document bug fixes |
Setup Process
First, I cloned and set up the knowledge base server:
git clone https://github.com/willynikes2/knowledge-base-server.gitcd knowledge-base-servernpm installnpm linkkb setupkb registerkb startFor automatic integration with my Obsidian vault:
kb setup --auto --vault=~/obsidian-vault --agents=claudeThen I added the server to my Claude configuration:
{ "mcpServers": { "knowledge-base": { "command": "node", "args": ["/path/to/knowledge-base-server/dist/index.js"], "env": { "KB_VAULT_PATH": "~/obsidian-vault", "KB_DB_PATH": "~/.knowledge-base/kb.db" } } }}How I Use It
Storing Learnings
When Claude helps me fix a bug, I capture the fix:
await mcp.kb_capture_fix({ issue: "useEffect infinite loop", solution: "Use functional update: setCount(c => c + 1)", context: "React hooks dependency array"});Retrieving Knowledge
In a new session, Claude can search for past solutions:
const results = await mcp.kb_search("useEffect infinite loop");// Returns the fix I captured previouslyToken-Efficient Context
The kb_context tool gives summaries first, not full documents:
Traditional approach: Load 50KB of notes = 50KB tokenskb_context approach: Load 5 summaries = 2KB tokensToken savings: ~90%This matters because I don’t want to burn through my context window just loading context.
The Self-Learning Loop
The real power is the compounding effect:
+------------+ +------------+ +------------+| Capture |---->| Store |---->| Retrieve || (session) | | (indexed) | | (new query)|+------------+ +------------+ +------------+ ^ | | v +-------------< Compound >-----------+ (each session builds on previous knowledge)Each session:
- Claude attempts a task
- Corrections and learnings are captured
- Knowledge is indexed with context
- Future sessions query relevant past learnings
- Each session builds on accumulated knowledge
Common Mistakes I Made
Mistake 1: Storing Everything
At first, I ingested every document I had. The search results became noisy.
Fix: Use hot/warm/cold tiers. Only actively used knowledge goes in hot tier.
Mistake 2: Loading Full Documents
I was using kb_read for everything, loading 10KB documents to find one sentence.
Fix: Use kb_context for summaries, then kb_read only when I know the document is relevant.
Mistake 3: Mixing Personal and Claude Notes
I tried using my main Obsidian vault. Confusion ensued.
Fix: Separate vaults. As one Reddit user suggested: “I keep a separate Obsidian vault for Claude and for Personal use.”
Mistake 4: No Version Control
I didn’t track changes to my knowledge base. When something broke, I couldn’t recover.
Fix: Auto-sync with Git:
#!/bin/bashcd ~/claude-vaultgit add -Agit commit -m "Auto-sync: $(date '+%Y-%m-%d %H:%M')"git push origin mainMistake 5: Forgetting to Ingest
New documents weren’t searchable because I didn’t run ingestion.
Fix: I set up a cron job to auto-ingest new files daily.
Token Optimization Strategy
The knowledge base uses a three-tier system:
+------------------+-------------------+------------------+| HOT (Active) | WARM (Recent) | COLD (Archive) |+------------------+-------------------+------------------+| Last 7 days | 7-30 days | 30+ days || Always loaded | On-demand | Search-only || ~5KB tokens | ~15KB tokens | ~50KB tokens |+------------------+-------------------+------------------+This prevents context pollution while keeping relevant information accessible.
Summary
Claude’s session-based memory was frustrating me. Every new chat meant re-explaining context. I solved this with a knowledge base MCP server connected to an Obsidian vault.
The key points:
- MCP enables external data sources to connect to Claude
- Knowledge base servers provide searchable, persistent storage
- Token-efficient retrieval saves context window
- Self-learning loop compounds knowledge across sessions
- Separate vaults prevent personal/claude context confusion
- Git sync provides version history and recovery
Now when I start a new Claude session, it can search my accumulated knowledge and continue where we left off. No more copy-pasting context files. No more re-explaining the same concepts. The memory persists.
Final Words + More Resources
My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me
Here are also the most important links from this article along with some further resources that will help you in this scope:
- 👨💻 Knowledge Base Server on GitHub
- 👨💻 Reddit: Obsidian + Claude = no more copy paste
- 👨💻 MCP Memory Server
- 👨💻 Model Context Protocol Documentation
Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!
Comments