Skip to content
Mnema docs

Connect your coding agent

To capture agent sessions, cost and git you install a small local hook. This is separate from the MCP connection (which lets an agent read your workspace — see Connect your AI); the hook is what records what an agent did and what it cost.

Today the hook supports Claude Code. Cursor, Windsurf and other clients connect over MCP for knowledge but do not yet capture sessions — see Other agents below.

You need a workspace hook token and your workspace id, both in Settings → Developer.

Terminal window
MNEMA_HOOK_TOKEN=<your_hook_token> MNEMA_WORKSPACE_ID=<your_workspace_id> \
bash <(curl -sf https://mnema.theboringpeople.in/install/claude-hooks.sh)

That installs a Node hook into ~/.claude/hooks/ and registers it in ~/.claude/settings.json for the SessionStart, SessionEnd, Stop, PostToolUse and PostToolUseFailure events. It is idempotent (safe to re-run) and preserves any hooks you already have. Start a new Claude Code session and it appears under Sessions with its cost.

The hook is deliberately narrow. On each event it sends metadata and file paths only:

  • your session id, developer id and workspace id
  • the tool name and, for file tools, the file path it touched — never the file contents
  • git branch, HEAD commit and a dirty flag, derived from the working directory
  • on session end, the model and token usage (input / output / cache) it reads from the session transcript already on your disk — Claude Code wrote them there; the hook just sums them
  • the contents of any file, your prompts, your code, or command output
  • anything at all if you have not set a token — the hook exits silently

It always exits 0, times out in under two seconds, and queues locally if the network is down, so telemetry can never block or slow a coding session.

Sessions that ended before you installed the hook (or on another machine) can be swept in. This reads your local transcripts and only ingests those created after you installed the hook — it never backfills your whole history:

Terminal window
node ~/.claude/hooks/mnema-sweep.mjs
Terminal window
curl -sf https://mnema.theboringpeople.in/install/claude-hooks.sh | bash -s uninstall

This removes the hook files and its entries from ~/.claude/settings.json.

By default the hook sends metadata and file paths only. You can additionally let Mnema turn a finished session into durable knowledge in your graph — the decisions, gotchas and invariants it uncovered — so a future engineer or agent doesn’t repeat the work.

This is off by default and opt-in per repo, because it sends the session transcript (your prompts and the assistant’s prose — never file contents, tool output, or secrets) for LLM extraction. Enable it with the CLI:

Terminal window
npx mnema init --knowledge

That sets knowledge: true in .mnema/config.json. Edit .mnema/NOTABILITY.md to describe, in your own words, what’s worth remembering in this repo — Mnema consults it when deciding what to keep, and a trivial session produces nothing. Extraction runs on the knowledge graph (a paid feature) and its token cost is metered against your workspace. The raw transcript is discarded once the knowledge is extracted.

Cursor, Windsurf, Cline, Zed and others connect to Mnema over MCP so they can read your workspace (see Connect your AI). They do not capture sessions or cost yet — a first-class hook for those clients is planned. Until then, run Claude Code for session and cost capture.