MemoryRouter
Fix

How to give Claude Code long term memory

There are three honest answers, and they stack. Instruction files, auto memory, and lifecycle hooks each solve part of the problem. Only the last one keeps context through compaction automatically.

Sources checked 2026-09-25.

What each layer actually does

Instruction files. CLAUDE.md is loaded at session start, in full. Best for conventions, commands, and architecture notes. Worst for history, because it grows and gets loaded whether or not it is relevant.

Auto memory. Claude writes its own notes to MEMORY.md, and the first 200 lines or 25KB load at startup. Useful, shallow, and local to the checkout. It does not carry reasoning or survive a machine change.

Lifecycle hooks. The deterministic layer. Hooks fire on session start, before each prompt, after each turn, and around compaction. This is the only mechanism that both recalls relevant memory and survives the compaction boundary without a human noticing.

Start with the free layers

These work today, with no new tools.

  1. 1

    Write CLAUDE.md deliberately

    Keep it under a page. Structure, commands, conventions. Anything historical belongs elsewhere.

  2. 2

    Let auto memory do its job

    Keep MEMORY.md useful by pruning it. The first 200 lines are what load by default, so the top of that file is prime real estate.

  3. 3

    Keep a decisions log and reference it

    A dated Decisions.md that Claude appends to when choices are settled. Cheap, portable, and readable by other tools too.

Add the hook layer

The MemoryRouter package installs the hook layer in one command. Recall runs on UserPromptSubmit so relevant memory is in context before the model sees your prompt, capture runs on Stop so the completed turn is stored, and PreCompact flushes the session before compaction destroys it, with re-injection after.

Memory is scoped per project, so worktrees of the same repository share one memory and unrelated projects stay separate. Your key lives in your home directory, and the hook settings are safe to commit so a team can share them.

  1. 1

    Get a memory key

    Sign up at app.memoryrouter.ai and copy the key. The trial runs 14 days, and pricing is $20 per month after that with 200M memory tokens included.

  2. 2

    Run the installer

    In your project

    npx -y memoryrouter-claude init
  3. 3

    Verify, then test the real thing

    Run doctor for health, then tell Claude a unique fact, finish the turn, and open a new session to ask for it.

    Health check

    npx -y memoryrouter-claude doctor
  4. 4

    Optional: explicit memory tools

    Add the MCP connection when you want to say "remember this" or search memory by hand.

    MCP tools

    npx -y memoryrouter-claude mcp install --local

Full setup guide: Claude Code setup guide

Install for Claude Code

Commands, scopes, and the agent-assisted install are on the Claude Code page. 14-day free trial.

Related

FAQ

Sources

Sources checked 2026-09-25. Tool behavior changes; check the vendor docs before relying on a detail.

Start free