io.github.yuvalsuede/memory-mcp

编码与调试

by yuvalsuede

为 Claude Code 提供持久化记忆与 git 快照,帮助保留上下文和代码,不再轻易丢失。

给 Claude Code 补上持久化记忆和 git 快照,能长期保留上下文与代码,协作或中断后也不怕信息丢失。

什么是 io.github.yuvalsuede/memory-mcp

为 Claude Code 提供持久化记忆与 git 快照,帮助保留上下文和代码,不再轻易丢失。

README

memory-mcp

npm version npm downloads License: MIT Node TypeScript

Persistent memory + automatic git snapshots for Claude Code. Never lose context. Never lose code.

code
🧠 45 memories | 📊 2.8K tokens | 📸 23 snapshots | ⏱️ 5m ago

Why memory-mcp?

ProblemSolution
Re-explaining your project every sessionAuto-captures decisions, patterns, architecture
Context window fills up, knowledge lostTwo-tier memory: CLAUDE.md (instant) + deep search
Broke something, can't remember what workedGit snapshots on every save, instant rollback
No idea what Claude "knows" about your projectVisual dashboard shows all context
Worried about cloud storage100% local files, your git repo

What makes it different

  • Git Snapshots — Every memory save commits your entire project. Roll back anytime.
  • Two-Tier Memory — CLAUDE.md loads instantly, deep store searchable mid-conversation.
  • LLM-Powered — Haiku extracts what matters, consolidates duplicates, prunes stale info.
  • Visual Dashboard — See your context: tokens, memories by type, snapshot history.
  • Zero friction — No commands to run. It just works silently.

Quick Start

bash
# Install globally
npm install -g claude-code-memory

# Interactive setup (API key + hooks)
memory-mcp setup

# Initialize a project
memory-mcp init ~/Projects/my-app

That's it. Start coding. Memories accumulate automatically.

How It Works

mermaid
graph TB
    subgraph "Phase 1: Silent Capture"
        A[Claude Code Session] -->|User sends message| B[Claude responds]
        B -->|Hook fires: Stop/PreCompact/SessionEnd| C[extractor.js]
        C --> D[Read transcript from cursor]
        D --> E[Chunk if >6000 chars]
        E --> F[Send to Haiku LLM]
        F -->|Extract memories as JSON| G[Dedup via Jaccard similarity]
        G --> H[Save to .memory/state.json]
        H --> I[Decay confidence scores]
        I --> J{Consolidation needed?}
        J -->|>80 memories or every 10 extractions| K[Haiku merges/drops]
        J -->|No| L[Sync CLAUDE.md]
        K --> L
    end

    subgraph "Phase 2: Recovery"
        M[New session starts] -->|Built-in behavior| N[Claude reads CLAUDE.md]
        N --> O[Claude has full project context]
    end

    subgraph "Phase 3: Deep Recall"
        O --> P{Need specific context?}
        P -->|memory_search| Q[Keyword search across memories]
        P -->|memory_ask| R[Haiku synthesizes answer from top 30 matches]
        P -->|memory_related| S[Tag-based retrieval]
    end

    subgraph "Data Store"
        H -.-> T[(.memory/state.json<br/>Full memory store)]
        L -.-> U[(CLAUDE.md<br/>~150 line summary)]
        T -.->|MCP tools read| Q
        T -.->|MCP tools read| R
        T -.->|MCP tools read| S
    end

    style A fill:#4a9eff,color:#fff
    style F fill:#ff6b6b,color:#fff
    style K fill:#ff6b6b,color:#fff
    style R fill:#ff6b6b,color:#fff
    style T fill:#ffd93d,color:#000
    style U fill:#6bcb77,color:#000

Two-tier memory architecture:

LayerPurposeSize
CLAUDE.mdAuto-read on session start. Top ~150 lines of the most important context.Compact
.memory/state.jsonFull memory store. Searchable via MCP tools mid-conversation.Unlimited

Silent capture via hooks:

Claude Code hooks fire after every response (Stop), before context compaction (PreCompact), and at session end (SessionEnd). A fast LLM (Haiku) reads the transcript and extracts:

  • Architecture — how the system is structured
  • Decisions — why X was chosen over Y
  • Patterns — conventions and how things are done
  • Gotchas — non-obvious pitfalls
  • Progress — what's done, what's in flight
  • Context — business context, deadlines, preferences

Smart memory management:

  • Jaccard similarity deduplication (no duplicate memories)
  • Confidence decay (progress fades after 7 days, context after 30)
  • LLM-powered consolidation (merges overlapping memories, prunes stale ones)
  • Line-budgeted CLAUDE.md (stays under ~150 lines, most important first)

Updating

To update an existing installation:

bash
npm install -g claude-code-memory --force

To update hooks (e.g., after a bug fix):

bash
memory-mcp setup

Requirements

  • Claude Code CLI
  • Node.js 18+
  • Anthropic API key (for the Haiku-based extractor, ~$0.001 per extraction)

CLI Commands

code
memory-mcp setup              Interactive first-time setup
memory-mcp init [dir]          Initialize memory for a project
memory-mcp status [dir]        Show memory status and health
memory-mcp statusline [dir]    Compact one-line status (great for shell prompts)
memory-mcp context [dir]       Show context metrics and token usage
memory-mcp context --html      Generate visual HTML dashboard
memory-mcp search <query>      Search memories by keyword
memory-mcp ask <question>      Ask a question, get answer from memory
memory-mcp consolidate [dir]   Merge duplicates, prune stale memories
memory-mcp key [api-key]       Set or check Anthropic API key
memory-mcp snapshots [dir]     List git snapshot history
memory-mcp snapshot-enable     Enable automatic git snapshots
memory-mcp snapshot-disable    Disable git snapshots
memory-mcp help                Show help

Context Dashboard

Visualize your memory usage with memory-mcp context:

code
Context Dashboard

  Project: my-app

  Total Context
  2.8K estimated tokens

  Tier 1 CLAUDE.md (auto-loaded)
  █████████████████░░░░░░░░░░░░░ 1.0K
  45 lines, 44 in memory block

  Tier 2 .memory/state.json (searchable)
  ██████████████████████████████ 1.8K
  29 active, 5 archived, 24 superseded

  Memories by Type
  architecture ███░░░░░░░░░░░░░░░░░   8 memories (291 tokens)
  decision     ██████░░░░░░░░░░░░░░  18 memories (540 tokens)
  gotcha       ████░░░░░░░░░░░░░░░░  10 memories (332 tokens)
  progress     ██████░░░░░░░░░░░░░░  19 memories (538 tokens)

  Git Snapshots
  ● Enabled on __memory-snapshots
  42 commits → origin

Use memory-mcp context --html to generate an interactive browser dashboard.

Git Snapshots

Automatic project versioning tied to your working sessions. Every memory extraction commits your entire project to a hidden branch.

bash
# Enable during init (you'll be prompted)
memory-mcp init ~/Projects/my-app

# Or enable later
memory-mcp snapshot-enable

# View snapshot history
memory-mcp snapshots

# Compare two snapshots
memory-mcp snapshot-diff abc123 def456

# Restore to a previous state
memory-mcp snapshot-restore abc123

# Disable (preserves existing snapshots)
memory-mcp snapshot-disable

How it works:

  • Commits go to __memory-snapshots branch (invisible in normal workflow)
  • Optional push to remote (e.g., origin)
  • Commit messages include what memories were extracted
  • Full project state captured, not just memory files

Use cases:

  • Roll back after breaking changes
  • See what your project looked like during a specific session
  • Track project evolution alongside context evolution

MCP Tools (used by Claude mid-conversation)

When configured as an MCP server, Claude can access these tools during a session:

ToolDescription
memory_searchKeyword search across all memories
memory_relatedGet memories by tag or area
memory_askAsk a question, get an LLM-synthesized answer from memory
memory_saveManually save a memory
memory_recallList all memories with filters
memory_deleteRemove a memory
memory_consolidateTrigger memory consolidation
memory_consciousnessGenerate the full consciousness document
memory_statsShow memory statistics
memory_initSet project name and description

What Gets Stored

Memories are categorized into six types:

code
architecture   "Next.js 14 app router with Supabase backend, Stripe for billing"
decision       "Chose server components for public pages because of SEO requirements"
pattern        "All API routes validate input with zod and return NextResponse"
gotcha         "Supabase RLS policy on word_lists requires user_id OR org_id, not both"
progress       "Auth complete, billing webhook handling in progress"
context        "Client wants launch by March, focus on core features only"

File Structure

After initialization, your project gets:

code
your-project/
├── CLAUDE.md              ← auto-updated memory summary (read on session start)
├── .memory/
│   ├── state.json         ← full memory store
│   └── cursor.json        ← tracks what's been processed
├── .mcp.json              ← MCP server configuration
└── .claude/
    └── settings.json      ← hook configuration

CLAUDE.md Format

The memory block is inserted between markers, preserving any existing CLAUDE.md content:

markdown
<!-- MEMORY:START -->
# MyProject
A brief description

_Last updated: 2026-01-27 | 45 active memories, 62 total_

## Architecture
- Next.js 14 app router with Supabase backend
- Auth via NextAuth with Google and email providers

## Key Decisions
- Chose server components for SEO pages
- Using Supabase RLS instead of API-level auth

## Patterns & Conventions
- All API routes use zod validation
- Tailwind only, no CSS modules

## Gotchas & Pitfalls
- RLS policy requires user_id OR org_id, not both

## Current Progress
- Auth: complete
- Billing: in progress

## Context
- Launch target: March

_For deeper context, use memory_search, memory_related, or memory_ask tools._
<!-- MEMORY:END -->

Global vs Per-Project Install

Global (recommended): hooks work for all projects automatically.

bash
memory-mcp setup  # select "global" when prompted

Per-project: hooks and MCP configured per project.

bash
memory-mcp init /path/to/project

Configuration

API key is resolved in order:

  1. ANTHROPIC_API_KEY environment variable
  2. ~/.memory-mcp/config.json
  3. ~/.config/anthropic/api_key
  4. ~/.anthropic/api_key

Cost

The extractor uses Claude Haiku for memory extraction and consolidation. Typical cost:

  • ~$0.001 per extraction (after each Claude response)
  • ~$0.005 per consolidation (every ~10 extractions)
  • A full day of coding: ~$0.05–0.10

License

MIT

常见问题

io.github.yuvalsuede/memory-mcp 是什么?

为 Claude Code 提供持久化记忆与 git 快照,帮助保留上下文和代码,不再轻易丢失。

相关 Skills

前端设计

by anthropics

Universal
热门

面向组件、页面、海报和 Web 应用开发,按鲜明视觉方向生成可直接落地的前端代码与高质感 UI,适合做 landing page、Dashboard 或美化现有界面,避开千篇一律的 AI 审美。

想把页面做得既能上线又有设计感,就用前端设计:组件到整站都能产出,难得的是能避开千篇一律的 AI 味。

编码与调试
未扫描111.1k

网页构建器

by anthropics

Universal
热门

面向复杂 claude.ai HTML artifact 开发,快速初始化 React + Tailwind CSS + shadcn/ui 项目并打包为单文件 HTML,适合需要状态管理、路由或多组件交互的页面。

在 claude.ai 里做复杂网页 Artifact 很省心,多组件、状态和路由都能顺手搭起来,React、Tailwind 与 shadcn/ui 组合效率高、成品也更精致。

编码与调试
未扫描111.1k

网页应用测试

by anthropics

Universal
热门

用 Playwright 为本地 Web 应用编写自动化测试,支持启动开发服务器、校验前端交互、排查 UI 异常、抓取截图与浏览器日志,适合调试动态页面和回归验证。

借助 Playwright 一站式验证本地 Web 应用前端功能,调 UI 时还能同步查看日志和截图,定位问题更快。

编码与调试
未扫描111.1k

相关 MCP Server

GitHub

编辑精选

by GitHub

热门

GitHub 是 MCP 官方参考服务器,让 Claude 直接读写你的代码仓库和 Issues。

这个参考服务器解决了开发者想让 AI 安全访问 GitHub 数据的问题,适合需要自动化代码审查或 Issue 管理的团队。但注意它只是参考实现,生产环境得自己加固安全。

编码与调试
83.0k

by Context7

热门

Context7 是实时拉取最新文档和代码示例的智能助手,让你告别过时资料。

它能解决开发者查找文档时信息滞后的问题,特别适合快速上手新库或跟进更新。不过,依赖外部源可能导致偶尔的数据延迟,建议结合官方文档使用。

编码与调试
51.7k

by tldraw

热门

tldraw 是让 AI 助手直接在无限画布上绘图和协作的 MCP 服务器。

这解决了 AI 只能输出文本、无法视觉化协作的痛点——想象让 Claude 帮你画流程图或白板讨论。最适合需要快速原型设计或头脑风暴的开发者。不过,目前它只是个基础连接器,你得自己搭建画布应用才能发挥全部潜力。

编码与调试
46.2k

评论