claudecode-infinite-memory
A lightweight MCP memory server built on SQLite + FTS5, providing cross-session long-term memory for Claude Code.
README
claudecode-infinite-memory
A lightweight MCP memory server built on SQLite + FTS5, providing cross-session long-term memory for Claude Code. Supports three-source merged retrieval: long-term memories, session history, and knowledge base indexing.
Features
- Long-term memory — Store and retrieve persistent memories across sessions with deduplication
- Session indexing — Automatically indexes Claude Code session transcripts (user + assistant messages)
- Knowledge base — Drop
.mdfiles in a folder and get them auto-indexed with FTS5 - Three-source search — Queries all three sources simultaneously with importance-weighted re-ranking
- Incremental sync — Only re-indexes files that actually changed (hash + mtime detection)
- Zero external model dependencies — Pure keyword-based retrieval using FTS5 BM25, no embedding models needed
How It Works
graph BT
subgraph Data Sources
CC["Claude Code Sessions\nauto-generated .jsonl"]
MD["Knowledge Files\nuser-managed .md"]
STORE["memory_store() calls\nfrom Claude Code"]
end
subgraph Index & Storage
SESS["Layer 1: session_chunks\nFTS5 indexed"]
KNOW["Layer 2: knowledge_chunks\nFTS5 indexed"]
MEM["Layer 3: memories\nFTS5 indexed"]
end
CC -->|auto sync| SESS
MD -->|auto sync| KNOW
STORE -->|store + dedup| MEM
SESS --> SEARCH["memory_search(query)"]
KNOW --> SEARCH
MEM --> SEARCH
subgraph Claude Code Client
USER["User Input"] --> LLM["Claude LLM"]
end
SEARCH -->|results| LLM
Requirements
- Node.js 18+ (20+ recommended)
- Run
npm installin the project directory
Quick Start
# Development mode (stdio)
npm run dev
# Production build
npm run build
npm start
Integration with Claude Code
Add the following to your Claude Code MCP config (~/.claude.json):
{
"mcpServers": {
"claudecode-infinite-memory": {
"command": "npm",
"args": ["--prefix", "/path/to/claudecode-infinite-memory", "run", "-s", "dev"],
"env": {
"MCP_MEMORY_DB_PATH": "/path/to/claudecode-infinite-memory/memory.sqlite",
"MCP_MEMORY_CLAUDE_HISTORY_PATH": "~/.claude/history.jsonl",
"MCP_MEMORY_SESSIONS_PATH": "~/.claude/projects",
"MCP_MEMORY_KNOWLEDGE_PATH": "/path/to/your/knowledge-base",
"MCP_MEMORY_DEFAULT_LIMIT": "5",
"MCP_MEMORY_MAX_LIMIT": "20",
"MCP_MEMORY_WATCH": "false"
}
}
}
}
Replace
/path/to/...with your actual paths. Merge into your existingmcpServersif needed.
Tools
memory_store(text, category?)
Store a long-term memory entry.
text(required) — The memory contentcategory(optional) — One of:preference,fact,decision,entity,other- Deduplication — Uses
sha256(text + category)as a unique hash. Duplicate writes returnaction: "duplicate", successful writes returnaction: "stored".
memory_search(query, limit?)
Search across all three data sources with merged ranking.
Data sources:
- Long-term memories (
memoriestable) — FTS5 full-text search with BM25 ranking, LIKE fallback - Session history (session JSONL files) — FTS5 full-text search on indexed session transcripts
- Knowledge base (
knowledge_chunkstable) — FTS5 full-text search on chunked.mdfiles
Ranking strategy:
- Each source produces TopK candidates (
limit * 5, capped at 50) - Results are re-ranked:
finalScore = baseScore + importanceBoost - Importance boost factors: source weight + structure weight + category weight
- Final results sorted by
finalScoredesc, thencreatedAtdesc
memory_forget(id)
Delete a specific memory entry by ID. Returns { deleted: true | false }.
Environment Variables
| Variable | Default | Description |
|---|---|---|
MCP_MEMORY_DB_PATH |
./memory.sqlite |
SQLite database path |
MCP_MEMORY_CLAUDE_HISTORY_PATH |
~/.claude/history.jsonl |
Claude Code session history file |
MCP_MEMORY_SESSIONS_PATH |
~/.claude/projects |
Directory containing session JSONL files |
MCP_MEMORY_KNOWLEDGE_PATH |
(empty, disabled) | Knowledge directory path; put .md files here for auto-indexing |
MCP_MEMORY_DEFAULT_LIMIT |
5 |
Default search result count |
MCP_MEMORY_MAX_LIMIT |
20 |
Maximum search result count |
MCP_MEMORY_CHUNK_TOKENS |
400 |
Knowledge indexing chunk size (approximate tokens) |
MCP_MEMORY_CHUNK_OVERLAP_TOKENS |
80 |
Chunk overlap size (approximate tokens) |
MCP_MEMORY_SYNC_COOLDOWN_MS |
5000 |
Cooldown before incremental sync on search (ms) |
MCP_MEMORY_SYNC_ON_START |
true |
Full sync on server startup |
MCP_MEMORY_WATCH |
false |
Enable file watcher for knowledge directory |
MCP_MEMORY_WATCH_DEBOUNCE_MS |
1500 |
File watcher debounce interval (ms) |
Knowledge Base (Layer 2)
Set MCP_MEMORY_KNOWLEDGE_PATH to a directory containing .md files.
How it works:
- On startup — Full scan, approximate token-based chunking (default 400 tokens/chunk, 80 overlap), FTS5 indexing
- On search — Cooldown check + change detection, incremental rebuild if needed
- Incremental sync — mtime change triggers hash comparison, only changed files are re-chunked
- Deletion sync — Files removed from disk are automatically cleaned from the index
- Config change rebuild — Changing chunk parameters triggers a full rebuild (detected via
knowledge_meta) - File watcher (optional) — Set
MCP_MEMORY_WATCH=trueforfs.watch-based monitoring with debounce
When MCP_MEMORY_KNOWLEDGE_PATH is not set, this feature is silently skipped.
Three-Layer Memory Architecture
| Layer | Source | Write Method | Index Method | Characteristics |
|---|---|---|---|---|
| Layer 1 | Session JSONL files | Auto (Claude Code) | FTS5 chunked index | Zero-config, session transcript search |
| Layer 2 | Knowledge .md files |
Manual (user drops files) | FTS5 chunked index (approx. tokens) | High precision, requires file maintenance |
| Layer 3 | memory_store calls |
Claude Code / user-triggered | FTS5 + triggers | Precise, driven by CLAUDE.md instructions |
See ARCHITECTURE.md for detailed technical documentation.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。