DEV Community

Ali Baizhanov
Ali Baizhanov

Posted on

How to Give Claude Code Persistent Memory (2 Commands)

Claude Code is incredible for coding — but it starts fresh every session. It doesn't know you used Railway yesterday, that you prefer Sora over Inter, or that you spent 3 hours debugging that psycopg2 pool deadlock last week.

Here's how to fix that in 2 commands.

Setup (30 seconds)

pip install mengram-ai
mengram setup
Enter fullscreen mode Exit fullscreen mode

mengram setup creates a free account and installs Claude Code hooks. That's it.

What happens next

Every Claude Code session now does this automatically:

Session Start  →  Loads your cognitive profile (who you are, tech stack, preferences)
Every Prompt   →  Searches past sessions for relevant context
After Response →  Saves new knowledge in background
Enter fullscreen mode Exit fullscreen mode

No manual saves. No tool calls. No MCP configuration. Claude just remembers.

What it actually remembers

Mengram stores 3 types of memory — not just facts:

Semantic memory — facts and preferences:

"Uses Python 3.12, deploys to Railway, prefers PostgreSQL over MySQL"

Episodic memory — events and decisions:

"March 15: Debugged pool deadlock, fixed by increasing pool_max from 2 to 5"

Procedural memory — workflows that evolve:

"Deploy flow: git push → Railway auto-deploys from main → check logs"

The procedural part is key: if a workflow fails, Mengram updates the procedure with what went wrong and how you fixed it. Next time Claude encounters a similar task, it already knows the correct approach.

Quick example

After a few sessions, Claude Code builds a cognitive profile of you:

"Ali is a solo founder building Mengram. Uses Python/Flask on Railway
with Supabase PostgreSQL. Prefers concise code, avoids over-engineering.
Uses gunicorn with 1 worker. Common issues: psycopg2 pool sizing,
OpenAI API rate limits."
Enter fullscreen mode Exit fullscreen mode

When you start a new session and say "fix the deploy", Claude already knows your stack, your deploy process, and what went wrong last time.

How it works under the hood

Mengram uses Claude Code hooks — shell commands that run at specific lifecycle points:

  • PreToolUse — before each prompt, searches your memory for relevant context
  • PostToolUse — after each response, extracts and saves new knowledge
  • SessionStart — loads your cognitive profile into the system prompt

All data goes to Mengram's API where it's chunked, embedded, and stored in a knowledge graph. Search uses hybrid retrieval (vector + graph traversal + reranking).

Beyond Claude Code

Same API works with any AI tool:

from mengram import Mengram
m = Mengram()

# Store a conversation
m.add([
    {"role": "user", "content": "Deploy the app to production"},
    {"role": "assistant", "content": "Pushed to main, Railway auto-deployed. Took 45s."}
])

# Later, in a different session
results = m.search("how do I deploy?")
# → Returns the deploy procedure + past deployment events
Enter fullscreen mode Exit fullscreen mode

Works with MCP (29 tools), LangChain, CrewAI, OpenClaw, and plain REST API.

Pricing

Free tier: 50 adds/month, 300 searches. Enough for personal use. Paid plans start at $5/mo.

Open source, Apache 2.0.

Top comments (0)