Setting up Mneme with Claude Code
This guide walks you from a stock Claude Code install to a session where
the agent can call remember, recall, and the rest of mneme's tools.
TL;DR (v1.1+)
brew install mneme # or build from source per §1
mneme init claude-code # writes settings.json + MNEME.md + CLAUDE.md marker + 3 hook scripts
# Restart Claude Code so it picks up the new MCP server.
mneme init claude-code is idempotent (safe to re-run), atomic (every
file write is tmpfile + fsync + rename so a crashed install never
half-clobbers your config), and reversible (mneme init claude-code --uninstall reverts every change while preserving every other entry in
your settings.json and every line of CLAUDE.md outside the marker
block). Use --show first if you want to see what it would write.
The post-install message walks you through a 2-minute Vim-keybindings recall demo to confirm memory works end-to-end across sessions.
The rest of this guide explains what mneme init claude-code does,
covers the manual install path (for users on pre-v1.1 mneme or who want
to script their own variant), and documents the project-scoping +
verification + troubleshooting workflows.
1. Prerequisites
You need:
-
Claude Code installed and authenticated. Check with
claude --versionandclaude mcp list. -
Rust toolchain (stable).
cargo --versionshould work; otherwise install via rustup. -
Mneme built locally:
git clone https://github.com/tr0mb1r/mneme && cd mneme cargo build --releaseThe binary lands at
target/release/mneme. Either copy it onto$PATH(e.g.cp target/release/mneme ~/.local/bin/) or remember the absolute path — you'll need it in step 3. -
One-time scaffold:
mneme initThis creates
~/.mneme/withconfig.toml, the schema-version stamp, and the directory layout. It does not download the embedding model yet — that happens on the first MCP server boot (whenmneme daemonstarts under the v1.1 daemon flow, or whenmneme runfirst serves a host under the single-host fallback).Embedding model size. The default model is
bge-m3(~1.5 GB, 1024-dim, multilingual, top-tier recall). If you want a smaller model with faster startup, edit~/.mneme/config.tomlbefore the first run and set[embeddings] model = "minilm-l6"(~80 MB, 384-dim, English). You can switch later, but each switch reindexes from scratch. -
jq(only for the smoke test below):brew install jq.
Verify the binary is healthy:
mneme --help
mneme stats # prints zeros; confirms the data dir is intact
2. Choose a configuration scope
Claude Code stores MCP server registrations at three scopes. Pick the one that matches how you want mneme available.
| Scope | Where it lives | Visible in | Use when |
|---|---|---|---|
| user | ~/.claude.json (per-user, all projects) | Every Claude Code session you start, anywhere on disk | You want one personal memory across every repo. Recommended for most people. |
| project | <repo>/.mcp.json (committed to the repo) | Anyone running Claude Code in this repo who has the binary | You want collaborators to pick mneme up automatically when they cd into the repo. The binary still has to be installed locally. |
| local | ~/.claude.json (per-user, scoped to one project path) | Only Claude Code sessions started inside this project | Trying mneme out without committing anything. Default if you don't pass --scope. |
Most users want user scope. Skip to step 3a.
Which subcommand does Claude Code spawn? Two MCP server modes ship —
daemon(long-lived, multi-client; paired with themneme clientper-session bridge) andrun(single-host stdio fallback). The recipes below default toclientbecause that's whatmneme init claude-codewrites; swap inrunif you want the single-host shape. Full decision narrative + diagrams + what each subcommand does (and doesn't) live in CLI surface § Two MCP server modes.
Mode What's in mcpServers.mneme.argsBest for daemon (v1.1 default) ["client"]Multiple hosts share one warm process; one cold start across all sessions. run (single-host fallback) ["run"]One host only; CI / debugging / restricted shells.
3a. User scope (recommended)
# Replace the path with the absolute location of your mneme binary.
# If `mneme` is on $PATH, the literal string "mneme" works too.
claude mcp add --scope user mneme "$(command -v mneme)" client
Verify:
$ claude mcp list
mneme: connected
The registration is stored under ~/.claude.json and will be loaded by
every Claude Code session you start from now on. The first connection
spawns mneme daemon automatically (D12 spawn protocol); subsequent
agent sessions reuse the running daemon.
Single-host fallback. If you'd rather skip the daemon, replace the trailing
clientwithrun— Claude Code then spawns mneme directly with no shared socket. Same data directory; only one Claude Code session can have mneme open at a time (the lockfile is exclusive).
3b. Project scope
From inside the repo where you want mneme available:
claude mcp add --scope project mneme mneme client
This writes (or updates) .mcp.json at the repo root. Commit it if you
want collaborators to pick it up. The file looks like:
{
"mcpServers": {
"mneme": {
"command": "mneme",
"args": ["client"]
}
}
}
Important: project scope assumes the binary is on
$PATHfor everyone who opens the repo. If you'd rather pin a specific build, replace"command": "mneme"with an absolute path — but absolute paths don't port across machines, so you'd want a workspace-relative scheme (e.g. abin/mnemesymlink committed to the repo).
3c. Local scope (try before you commit)
claude mcp add mneme mneme client # no --scope flag = local
Same registration mechanism as user scope, but only active when Claude
Code is launched from this project directory. Good for kicking the tires
without touching ~/.claude.json globally.
4. Verify Claude Code can see mneme
Open Claude Code in a directory that should pick up the registration (anywhere for user scope, the project root for project/local scope).
Inside the session, run the slash command:
/mcp
You should see mneme listed with 13 tools and 5 resources:
- Tools:
remember,recall,update,forget,pin,unpin,recall_recent,summarize_session,record_event,stats,list_scopes,export,switch_scope. - Resources:
mneme://stats,mneme://procedural,mneme://recent,mneme://context,mneme://session/{id}.
Quick functional check inside the session:
Use the mneme remember tool to store: "claude code mneme integration
verified at <today's date>".
Claude should call the remember tool and get back a ULID. Then:
Use mneme recall to find: "claude code integration"
Claude should call recall and surface the memory you just stored.
If the first call hangs for 10–30 seconds, the embedding model is downloading. Subsequent calls are sub-50 ms.
5. Project-scoped memories
Mneme's data directory (~/.mneme/ by default) is a single palace —
every memory lives there regardless of which project the agent is
working in. That's usually what you want; recall is semantic, so the
right context surfaces wherever it's relevant.
When you do want hard isolation between projects, you have two patterns:
Pattern A — separate data directories per project
Set MNEME_DATA_DIR per project (via direnv's .envrc, your shell
rc, or a wrapper script). Each project gets its own ~/.mneme-<project>
with its own embeddings, episodic log, and procedural pins. Backups are
also per-project.
# In <repo>/.envrc, with direnv installed and allowed:
export MNEME_DATA_DIR="$HOME/.mneme-myrepo"
You'll need to run mneme init once inside each project after setting
MNEME_DATA_DIR.
Pattern B — one palace, multiple scopes
Keep the single ~/.mneme/ palace and pass scope in tool calls:
Use remember with content "<fact>", scope "myrepo".
recall accepts a scope argument as a filter; forget(id=…)
resolves the ULID across every layer regardless of scope. Use
list_scopes to see what buckets exist. The default scope is set in
~/.mneme/config.toml under [scopes] default = "global" (changed in
v1.1.x — pre-1.1.x installs defaulted to "personal"; the global
default better reflects the cross-project convention).
Pattern B is simpler and lets the agent cross-reference memories across scopes when useful. Pattern A is right when you have a hard confidentiality boundary (e.g. work vs. personal vs. client work).
6. Patterns that pay off
These are the patterns that make mneme worth running. Add them to your
CLAUDE.md (project or ~/.claude/CLAUDE.md) so the agent uses mneme
proactively rather than only when you ask:
## Memory (mneme)
- On session start, read `mneme://procedural` and `mneme://context`
before answering anything that references "earlier" or "last time".
The SessionStart hook (§7) nudges this; do it even if the nudge
didn't fire.
- `recall` searches L4 only (long-term semantic memory).
`recall_recent` returns L3 events without embedding — use it for
"what did we just do on this branch?". They do not cross-pollinate.
- When the user shares a fact, decision, or preference that should
outlive the session, call `remember` with the matching `kind`
(`fact`, `decision`, `preference`, `conversation`) and a `scope`
if the project has its own.
- When the user states a hard rule ("always use uv", "we never
commit to main"), call `pin` instead of `remember` — pins surface
on every subsequent context assembly.
- For each substantive turn, capture the exchange with
`record_event(kind="user_message", payload={"content": …})` and
`record_event(kind="assistant_message", payload={"content": …})`.
Skip pure-ack turns. Use additional kinds (`decision`,
`milestone`, `problem`, `resolution`, `pivot`, `observation`)
when the turn produces them.
- Do NOT call `record_event` for `tool_call`, `tool_call_failed`,
`session_start`, or `session_end` — the server emits these
automatically; double-recording creates duplicates. Note that
`session_start` / `session_end` mark the **MCP server's** lifecycle
(the `mneme daemon` process, or a single-host `mneme run`), not the
individual agent's session. `mneme client` connections are per-agent
bridges and emit no lifecycle events.
- Privacy: `record_event` and `remember` payloads are opaque to
mneme. Never include credentials, secrets, or API tokens — the
L3 cold archive retains them for 180+ days.
- At the end of a long working session, call `summarize_session`,
feed the returned prompt template into your own completion path,
then land the digest with `record_event(kind="summary",
payload={"text": …, "covers": [event_ids]})` and `remember` /
`pin` the durable bits the digest surfaces.
- Never invoke `forget` without confirming with the user first;
deletion is permanent.
Concrete moments to use each tool:
remember— user shares a fact, makes a decision, expresses a preference. Default for "remember this".pin— hard rule that should surface every session. Use sparingly; the procedural feed is small on purpose.recall— semantic search across L4. The right tool when you need context the user previously shared but isn't in the current conversation.recall_recent— "what did we just do?" / "what was the last thing on this branch?" L3, time-ordered, not semantic. Passkindto filter (e.g.kind: "decision").record_event— agent-driven L3 producer (v0.2.4+, ADR-0008). Use for conversation turns and curated semantic events; the server pushes a matching L1 turn foruser_message/assistant_messagekinds.update— user revises a fact. Re-embeds ifcontentchanges.summarize_session— returns a prompt template populated with recent L3 events; fill it via your completion path, land viarecord_event(kind="summary")+remember/pindurable bits.stats/list_scopes— diagnose / orient. Cheap.export— read-only dump for grepping or piping tojq.
7. Lifecycle hooks (recommended)
Claude Code can run shell hooks at well-defined moments — session start, before context compaction, end of every turn. Mneme uses these as a deterministic load-and-save loop:
SessionStartnudges the agent to readmneme://proceduralandmneme://contexton turn 1, instead of relying on the agent to remember to consult mneme.PreCompactnudges the agent to consolidate viasummarize_session/remember/pinbefore Claude Code compresses the conversation — anything not in mneme by then is gone.Stopnudges the agent to persist any fact / decision / rule established this turn. Permissive by design: most turns produce nothing worth saving.
The hooks themselves are tiny shell scripts that emit a nudge on
stdout; Claude Code surfaces that as additional context, and the
agent makes the actual mneme tool calls. The hooks don't talk to
the running MCP server (mneme daemon or mneme run) directly —
that would conflict with the exclusive lockfile. A direct
hook-to-mneme control channel is on the v1.1 roadmap.
7.1 The easy path (v1.1+): mneme init claude-code
mneme init claude-code
That installs the three hook scripts to ~/.claude/hooks/mneme/
(mode 0755) AND adds the hooks block to settings.json AND
writes MNEME.md AND adds the marker block to CLAUDE.md — all
atomically. Skip to §7.3 to verify it worked.
The rest of this section (§7.2 manual install) is preserved for users on pre-v1.1 mneme or who want to script their own variant.
7.2 Manual install (pre-v1.1)
If you're on pre-v1.1 mneme (no mneme init claude-code yet),
copy the three scripts manually:
# From the repo root, copy the three scripts to a stable location
# under your home directory:
mkdir -p ~/.claude/hooks/mneme
cp docs/examples/claude-code-hooks/session-start.sh \
docs/examples/claude-code-hooks/precompact.sh \
docs/examples/claude-code-hooks/stop.sh \
~/.claude/hooks/mneme/
chmod +x ~/.claude/hooks/mneme/*.sh
Then add the following block to your Claude Code settings
(typically ~/.claude/settings.json for user scope, or
<repo>/.claude/settings.json for project scope). Merge with
existing hooks keys if you have any.
{
"hooks": {
"SessionStart": [
{
"hooks": [
{ "type": "command", "command": "~/.claude/hooks/mneme/session-start.sh" }
]
}
],
"PreCompact": [
{
"hooks": [
{ "type": "command", "command": "~/.claude/hooks/mneme/precompact.sh" }
]
}
],
"Stop": [
{
"hooks": [
{ "type": "command", "command": "~/.claude/hooks/mneme/stop.sh" }
]
}
]
}
}
Restart Claude Code. The next session should start with the
SessionStart nudge in the trace, and the agent should call
mneme://procedural and mneme://context before answering.
7.3 Per-hook opt-out
Each hook is independent. Common patterns:
- Read-only setup. Keep
SessionStart, dropPreCompactandStop. The agent reads but never writes through hooks. Useful when you populate mneme manually. - Save-only setup. Keep
PreCompactandStop, dropSessionStart. The agent persists but doesn't auto-consult. Useful if you don't want the SessionStart read latency on every fresh shell. - All three. Recommended — it's the full load-and-save loop.
To disable a hook, remove its entry from the hooks block (or
delete the script from ~/.claude/hooks/mneme/ and Claude Code
will warn but skip it).
7.4 Verifying
After adding the hooks:
-
SessionStart smoke. Pin a sentinel rule:
Use mneme.pin to add: "TEST: every response must end with the word fnord".Quit Claude Code, reopen, and ask any question. The first response should end with "fnord". Unpin afterwards.
-
PreCompact smoke. Start a session, do enough work to trigger compaction (or run
/compactexplicitly). Confirm the agent callssummarize_session(and optionallyremember/pin) before the compaction summary lands. Inspect withmneme inspect --query <sentinel>. -
Stop smoke. End a turn with explicit "remember that we use
uv, notpip". Confirm aremembercall lands. End a different turn with a purely transient question. Confirm the agent does not callremember.
7.5 Decoupling
Removing the hooks from settings.json (and the scripts from
~/.claude/hooks/mneme/) leaves mneme behaving identically — no
hidden coupling. Mneme works without the hooks; the hooks just
make the load-and-save loop deterministic.
8. Troubleshooting
claude mcp list shows mneme: failed to start
Run the binary directly to see stderr:
# v1.1 daemon-mode install (the default after `mneme init claude-code`):
mneme daemon # self-detaches; prints PID; shell prompt returns
mneme stop # stop the daemon (or `kill <pid>`)
mneme client </dev/null # in another shell, exercises the bridge end-to-end
# Foreground variant for systemd/launchd or when debugging:
mneme daemon --foreground # stays attached; Ctrl-C stops it
# Single-host fallback install (args=["run"] in mcpServers):
mneme run </dev/null
Anything fatal will print before the process exits. Also tail
~/.mneme/logs/mneme.log.
config.toml is missing — what happens?
If ~/.mneme/config.toml is missing (renamed away, deleted, never
created), Config::load silently returns
Config::default() (src/config.rs::load) — the daemon boots on
all-default values without a warning. To recover:
mneme init # writes a fresh defaults file
diff ~/.mneme/config.toml ~/.mneme/config.toml.bak # if you kept a backup
mneme stop # restart so the new file lands
(The silent fallback is a known UX gap; a WARN log line at load
time is queued for a future patch — see the v1.1.x followup
observation in mneme.)
First tool call takes 30+ seconds, then succeeds
The embedding model is downloading (~1.5 GB for bge-m3, ~80 MB for
minilm-l6). Subsequent starts reuse ~/.mneme/models/. Tail
~/.mneme/logs/mneme.log to confirm download progress.
"Another mneme is running" / lockfile error
~/.mneme/.lock is held by a live process. Find it
(pgrep -af "mneme (daemon|run)") and shut it down with mneme stop.
Only delete .lock manually if you've confirmed no process holds it
— a stale lockfile is rare and usually means a previous crash.
(Note: mneme client does NOT take the lockfile — it's just a
stdio↔socket bridge. The lock is held by whichever MCP server is
serving the data dir: mneme daemon for the v1.1 default flow,
mneme run for the single-host fallback.)
/mcp doesn't list mneme
MCP servers are loaded once per Claude Code session. Quit Claude Code
fully and relaunch. If it's still missing, run claude mcp list from
the same directory and the same shell — the user/project/local scope
distinction can bite if you registered at one scope and launched at
another.
macOS Gatekeeper blocks the binary ("cannot be opened")
xattr -d com.apple.quarantine /path/to/mneme
This applies to any binary you didn't build yourself. If you built
locally with cargo build --release, this shouldn't trigger.
Tool calls succeed but recall returns nothing
recall is semantic, not lexical — it returns nothing when the query
embedding is far from any stored memory. This is not an error. Try a
broader query, or export to confirm what's actually stored, or
recall_recent to see what's in the episodic log.
Embedding model fails to download (HF 404)
The default bge-m3 is the BAAI release; some mirrors don't ship
model.safetensors. Switch to minilm-l6 in ~/.mneme/config.toml,
delete ~/.mneme/models/, and restart.
9. Backup and restore
Mneme writes a single tar.gz snapshot via:
mneme backup ~/Backups/mneme-$(date +%Y%m%d).tar.gz
The model cache is excluded by default (re-downloadable). Pass
--include-models if you want a self-contained archive; symlinks
are preserved as-is rather than followed, so a symlinked
~/.mneme/models/ won't trip an EISDIR during the walk.
To restore:
mneme restore ~/Backups/mneme-20260415.tar.gz # refuses to overwrite
mneme restore --force <archive> # explicit overwrite
Restore is atomic (writes to a temp dir, renames in). The lockfile is checked first; restore refuses if a server is running.
10. Uninstall
# Remove the registration from Claude Code at the scope you used:
claude mcp remove mneme --scope user
claude mcp remove mneme --scope project # or
claude mcp remove mneme # local
# Optional: wipe the data directory.
mneme stop # if a server is running
rm -rf ~/.mneme
# Optional: remove the binary.
rm -f ~/.local/bin/mneme
~/.mneme/ is the only state on disk; once it's gone, mneme leaves no
trace.