How I Built MemCP: Giving Claude a Real Memory
Source: Dev.to
What I built
MemCP is an MCP server that plugs into Claude Code. It prevents loss of context when you issue /compact and provides a structured memory system.
Never lose context again
MemCP watches for /compact commands. When you hit it, Claude is blocked with “save your work first” until the insights and context are saved. Gentle reminders appear every 10 turns if nothing has been saved yet.
Two types of storage
- Memory – stores small pieces of knowledge such as decisions, facts, preferences, and findings.
- Contexts – stores larger artifacts like entire files, documents, or logs on disk. Claude can inspect metadata (file type, size, token count) without loading the full content, then peek at specific sections, grep for patterns, or chunk the file into navigable pieces.
Knowledge that connects itself
Whenever Claude saves an insight, MemCP automatically builds connections:
- Links to similar ideas
- Links to items from the same work session
- Cause‑and‑effect links (detected from “because”, “therefore”, etc.)
- Links to things mentioning the same files or modules
Thus, asking “why did we make that choice?” follows the causal chain instead of a simple keyword search.
Search that improves as you go
| Added feature | Search behavior |
|---|---|
| Basic install | Keyword search |
| One extra package | Ranked search |
| Another package | Typo tolerance |
| Embeddings | Semantic search |
The system automatically selects the best available method—no configuration required.
Navigation tools for large files
For a 50,000‑line codebase file you can:
- Inspect – view type, size, preview (zero token cost)
- Chunk – split into sections
- Peek – read a specific chunk (e.g., chunk 5)
- Filter – extract only function definitions
You decide exactly what enters the context window.
Smart cleanup
After 30 days, unused items are compressed and archived automatically. Items marked critical, accessed frequently, or tagged “keep” remain active. Archived content can be restored instantly when needed.
Quick install
pip install memcp
- PyPI:
- RLM paper:
- MAGMA paper:
MemCP is open source (MIT), has 21 tools, zero mandatory dependencies, and works out of the box. If you’ve ever hit /compact and felt your context disappear, give it a try. Stars and feedback are appreciated.