Skip to content

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:

~/.claude.json (first attempt)
{
"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:

Memory 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:

ToolWhat it does
kb_searchFull-text search with highlighted snippets
kb_search_smartHybrid keyword + semantic search
kb_contextToken-efficient summaries
kb_readLoad full document by ID
kb_writeWrite notes to knowledge base
kb_ingestIngest documents and files
kb_capture_sessionRecord debugging findings
kb_capture_fixDocument bug fixes

Setup Process

First, I cloned and set up the knowledge base server:

Terminal
git clone https://github.com/willynikes2/knowledge-base-server.git
cd knowledge-base-server
npm install
npm link
kb setup
kb register
kb start

For automatic integration with my Obsidian vault:

Terminal
kb setup --auto --vault=~/obsidian-vault --agents=claude

Then I added the server to my Claude configuration:

~/.claude.json
{
"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:

Capturing a 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:

Searching past learnings
const results = await mcp.kb_search("useEffect infinite loop");
// Returns the fix I captured previously

Token-Efficient Context

The kb_context tool gives summaries first, not full documents:

Token efficiency comparison
Traditional approach: Load 50KB of notes = 50KB tokens
kb_context approach: Load 5 summaries = 2KB tokens
Token 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:

Learning Loop
+------------+ +------------+ +------------+
| Capture |---->| Store |---->| Retrieve |
| (session) | | (indexed) | | (new query)|
+------------+ +------------+ +------------+
^ |
| v
+-------------< Compound >-----------+
(each session builds
on previous knowledge)

Each session:

  1. Claude attempts a task
  2. Corrections and learnings are captured
  3. Knowledge is indexed with context
  4. Future sessions query relevant past learnings
  5. 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:

.git/hooks/post-commit
#!/bin/bash
cd ~/claude-vault
git add -A
git commit -m "Auto-sync: $(date '+%Y-%m-%d %H:%M')"
git push origin main

Mistake 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:

Memory Tiers
+------------------+-------------------+------------------+
| 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:

Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!

Comments