Memory map

From kid-sid/codex-spellbook · View interactive version

Memory map is an AI agent skill from the GitHub repository kid-sid/codex-spellbook. Use when installing or configuring memory_map, writing CLAUDE.md session-setup instructions, choosing what to save in memory vs history, managing cross-project memory, tuning compression, or troubleshooting why Claude isn't loading context at session start.

How to use this skill

Skill file

memory_map

Persistent memory and conversation history MCP server for Claude Code — key-value context store, rolling history, and cross-project recall across sessions.

When to Activate

Architecture

memory_map/
├── server.py          — MCP server (stdio transport)
├── history_hook.py    — hook script: saves history on UserPromptSubmit / Stop / PreCompact
├── CLAUDE.md          — copy into any project to enable session-start loading
└── venv/              — Python virtualenv

Per-project files (written to the project root automatically):
├── .mcp_memory.json   — key-value store (load_memory / save_memory)
└── .mcp_history.json  — rolling conversation history (20 chunks)

MCP registration makes all tools available globally. Per-project activation is controlled by CLAUDE.md — Claude only calls load_memory / load_history automatically if the instructions tell it to.

Installation

Step 1 — Clone and Install

git clone https://github.com/kid-sid/memory_map.git
cd memory_map

# Windows
python -m venv venv
venv\Scripts\pip install -r requirements.txt

# Mac/Linux
python3 -m venv venv
source venv/bin/activate && pip install -r requirements.txt

Step 2 — Register the MCP Server

# Global — available in every project (recommended)
# Windows
claude mcp add -s user memory_map \
  C:/Users/yourname/memory_map/venv/Scripts/python.exe \
  C:/Users/yourname/memory_map/server.py

# Mac/Linux
claude mcp add -s user memory_map \
  python3 /home/yourname/memory_map/server.py

Registration scope options:

| Scope flag | Stored in | Available |

|---|---|---|

| -s user | ~/.claude/mcp.json | All projects on this machine |

| -s project | .claude/mcp.json | This repo only (committed, shared) |

| -s local | .claude/mcp.local.json | This repo only (gitignored, personal) |

Always use -s user for memory_map — it stores files with local paths that differ per machine.

Verify: claude mcp list → should show memory_map.

Step 3 — Lifecycle Hooks

Add to ~/.claude/settings.json so history is captured automatically in every project:

{
  "hooks": {
    "UserPromptSubmit": [
      {
        "matcher": "",
        "hooks": [{
          "type": "command",
          "command": "python C:/Users/yourname/memory_map/history_hook.py",
          "timeout": 10
        }]
      }
    ],
    "PreCompact": [
      {
        "matcher": "",
        "hooks": [{
          "type": "command",
          "command": "python C:/Users/yourname/memory_map/history_hook.py --force",
          "timeout": 15
        }]
      }
    ],
    "Stop": [
      {
        "matcher": "",
        "hooks": [{
          "type": "command",
          "command": "python C:/Users/yourname/memory_map/history_hook.py --force",
          "timeout": 15,
          "async": true
        }]
      }
    ]
  }
}

Mac/Linux: use python3 and POSIX paths.

| Hook | When | Flag |

|---|---|---|

| UserPromptSubmit | Every message — incremental saves | none |

| PreCompact | Before context window compaction | --force |

| Stop | When Claude finishes a turn | --force, async: true |

Step 4 — Enable Per-Project Memory

Copy CLAUDE.md from the memory_map repo into the project root:

# Windows
copy C:\Users\yourname\memory_map\CLAUDE.md CLAUDE.md

# Mac/Linux
cp ~/memory_map/CLAUDE.md ~/your-project/CLAUDE.md

Commit CLAUDE.md — teammates get session-start loading automatically. The file content Claude needs:

## Session Setup (Required)
At the start of every session, before doing anything else:
1. Call `load_memory` with the current working directory
2. Call `load_history` with the current working directory
3. Read both outputs before exploring files or asking questions

Memory Tools

`save_memory` / `load_memory` / `delete_memory`

Per-project key-value store. Values persist in .mcp_memory.json.

save_memory(project_path, key, value)
load_memory(project_path)         → returns all key-value pairs
delete_memory(project_path, key)

Key conventions:

| Key | What to store |

|---|---|

| stack | Language, framework, runtime versions |

| current_work | Active feature, bug, or initiative |

| gotchas | Non-obvious constraints, known failures, env quirks |

| key_files | Entry points, config files, critical paths |

| conventions | Non-obvious team decisions not in the code |

| blockers | Current blockers or dependencies on others |

Rules:

What NOT to save in memory:

Global Memory

Shared across all projects on the machine:

save_global_memory(key, value)
load_global_memory()

Use for: user identity, preferred tools, cross-project conventions, API key locations (not values). Never store secrets.


History Tools

`load_history` / `save_history`

Rolling conversation history stored in .mcp_history.json (20 chunks max). history_hook.py calls save_history automatically via hooks — no manual calls needed during normal use.

load_history(project_path, last_n=5)   → returns N most recent chunks
save_history(project_path, content)

Manual Checkpoint: `/mem_save`

Run /mem_save at any time to force-save the current conversation as a history chunk. Use before long operations, context compaction, or ending a session mid-task.


Cross-Project Tools

| Tool | What it does |

|---|---|

| list_projects | List all projects that have saved memory |

| get_project_summary(project_path) | One-line summary of a project's memory |

| load_cross_project_memory(project_path) | Load memory from a different project |

| search_across_projects(query) | Full-text search across all project memories |

Use cases:


Utility Tools

| Tool | What it does |

|---|---|

| get_local_structure(project_path) | Gitignore-aware directory tree |

| get_github_structure(owner, repo, branch?) | GitHub repo file tree via API |

| get_git_history(project_path, limit?) | Recent commits |

These are read-only exploration tools — call them at session start to orient quickly without reading every file.


Compression

set_compression(project_path, level)

| Level | Output | When to use |

|---|---|---|

| 0 | Raw — full fidelity | Debugging, inspecting history content |

| 1 | Compact — whitespace stripped | Normal use |

| 2 | Dense — abbreviations, no filler | Low context budget, large histories |

Set per-project; persists until changed. Default is compact (1).


Privacy and External Summarization

History is stored locally by default using simple truncation — no data leaves the machine.

To enable OpenAI-backed summarization (richer history compression):

# Add to your environment / shell profile
export OPENAI_API_KEY="sk-..."
export MCP_HISTORY_EXTERNAL_SUMMARIZE=1

When both are set, history_hook.py sends up to 4 000 characters of recent conversation to gpt-4o-mini before storing the summary locally.

What gets sent: recent dialogue including source code, file contents, and environment details. Only enable if you're comfortable with that leaving your machine. Do not enable on machines with proprietary codebases unless your org has approved the OpenAI data-processing agreement.


CLAUDE.md Session-Start Pattern

Minimal session-setup block for any project:

## Session Setup (Required)
At the start of every session, before doing anything else:
1. Call `load_memory` with the current working directory
2. Call `load_history` with the current working directory
3. Read both outputs before exploring files or asking questions

Save or update memory entries whenever you learn something worth keeping across sessions.
If something loaded from memory is no longer accurate, update it with `save_memory` using the same key.
Use short, lowercase keys: `stack`, `current_work`, `gotchas`, `key_files`. Keep values concise.

Extend this block with project-specific keys or additional tool calls (get_local_structure, etc.) when the project benefits from them.


Troubleshooting

| Symptom | Likely cause | Fix |

|---|---|---|

| Claude starts sessions cold with no memory | CLAUDE.md missing or not instructing load_memory | Copy CLAUDE.md from memory_map repo into project root |

| load_memory returns "no memory saved yet" | First session, or memory was deleted | Normal — save entries as context is established |

| History not saving between sessions | Hooks missing or wrong path in settings.json | Verify history_hook.py path; run it manually: python memory_map/history_hook.py --force |

| MCP server not found | Not registered, or wrong Python path | Re-run claude mcp add; verify with claude mcp list |

| history_hook.py hangs the session | No timeout on hook or slow Python startup | Ensure "timeout": 10 is set; use virtualenv Python, not system Python |

| Memory values growing stale | Not updating keys after project shifts | Always overwrite with the same key rather than adding new ones |


Red Flags


Checklist

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.