memory-plugin
Persistent memory management for Claude Code, allowing agents to store and retrieve user preferences, environment notes, and skills across sessions.
README
memory-plugin
Hermes-style bounded, curated persistent memory for Claude Code.
Two files persist across sessions and are injected into context at session start:
File (~/.claude/memory-plugin/) |
Purpose | Limit |
|---|---|---|
MEMORY.md |
Agent notes — environment, conventions, completed work | 2,200 chars |
USER.md |
User profile — preferences, style, habits | 1,375 chars |
How it maps to Claude Code
| Hermes feature | Here |
|---|---|
| Inject memory at session start (frozen snapshot) | SessionStart hook → additionalContext (scripts/inject-memory.mjs) |
memory tool: add / replace / remove |
MCP server mcp/memory-server.mjs → memory_add / memory_replace / memory_remove (+ memory_list) |
| Char limits + "memory full" error | Enforced in the MCP server |
| Substring matching for replace/remove | matchOne() — short unique substring, errors if ambiguous |
| Duplicate prevention | Exact-match no-op on add |
| Security scanning | lib/security.mjs — injection/exfil/backdoor patterns + invisible Unicode |
| Background self-improvement review (memory only) | Stop hook → detached claude -p review (scripts/review.mjs, opt-in) |
| Correction detector | UserPromptSubmit hook → regex (lib/correction.mjs, scripts/detect-correction.mjs) |
| Skill capture (procedural memory) | Always-on policy injected at session start — agent writes SKILL.md inline |
The model decides what to save via skills/memory/SKILL.md; the server enforces how.
Three learning loops
Modeled on the real pi-hermes-memory
implementation (which splits learning into separate loops on purpose):
- Background review (memory) —
Stophook fires a detachedclaude -pthat mines the finished turn for durable facts/preferences/corrections and saves them via the memory tools. It is explicitly forbidden from writing skills — a stale subprocess with only a transcript snapshot would author bad procedures. Opt-in (token cost). - Correction detector —
UserPromptSubmithook runs a free, two-pass regex over each prompt (strong patterns always fire; weak patterns need a following directive word; negative patterns suppress). On a hit it nudges the agent to persist the lesson before answering. Detection is pure regex — no LLM call. - Skill capture (procedural) — done inline by the main agent, never in a subprocess.
The session-start policy tells it to write a structured
SKILL.md(## When to Use / ## Procedure / ## Pitfalls / ## Verification) to~/.claude/skills/(portable) or.claude/skills/(repo-specific) the moment it finishes a complex, reusable workflow — while it still has full context. Claude Code's native skill discovery then handles progressive disclosure.
The Curator (skill lifecycle)
Ports Hermes' active → stale (30d) → archived (90d) aging so captured skills don't
pile up forever.
- Use signal — a
PostToolUsehook on theSkilltool records real invocations into a.last-usedsidecar (scripts/track-skill-use.mjs). "Last used" ismax(.last-used, SKILL.md mtime, dir mtime), so a skill that's invoked but never edited isn't falsely aged out, and a fresh skill is never stale. - Weekly sweep — a
SessionStarthook (scripts/curate.mjs) throttled to once per 7 days via a sentinel. Approximates Hermes' "every 7 days after idle" without a daemon. - Safety — notify-only by default: it reports stale/archivable skills in the
session context and only moves files when
MEMORY_CURATOR_ARCHIVE=1.pinned: truein frontmatter is never touched. Archiving moves (never deletes) into~/.claude/skills/.archive/and is fully reversible.
Install (as a Claude Code plugin)
This repo is also a single-plugin marketplace (.claude-plugin/marketplace.json),
so installation is two slash commands inside Claude Code. There is no build or
npm install step — the MCP server is zero-dependency.
/plugin marketplace add alexanderop/claude-code-memory
/plugin install memory@memory
marketplace add <owner>/<repo>registers this GitHub repo as a marketplace.install <plugin>@<marketplace>— both are namedmemoryhere (plugin namememory, marketplace namememory).
Claude Code copies the plugin into ~/.claude/plugins/cache and resolves
${CLAUDE_PLUGIN_ROOT} automatically, so the bundled MCP server and hooks just
work. They activate on the next turn — run /reload-plugins to pick them up
without restarting. Verify with /plugin (shows memory enabled) and /mcp
(shows the memory server with its memory_* tools).
Non-interactive / team install
Declare it in .claude/settings.json (project) or ~/.claude/settings.json (global):
{
"extraKnownMarketplaces": {
"memory": { "source": { "source": "github", "repo": "alexanderop/claude-code-memory" } }
},
"enabledPlugins": { "memory@memory": true }
}
Local development
Point the marketplace at a local checkout instead of GitHub:
/plugin marketplace add ~/Projects/memory-plugin
/plugin install memory@memory
Background review (optional)
Off by default — it spawns a headless claude -p after each turn and costs tokens.
Enable by exporting MEMORY_REVIEW_ENABLED=1 in the environment Claude Code runs in.
It is recursion-guarded (MEMORY_REVIEW=1 on the child) and never blocks the turn.
Config (env vars)
| Var | Default | Effect |
|---|---|---|
MEMORY_PLUGIN_DIR |
~/.claude/memory-plugin |
Where the two files live |
MEMORY_CHAR_LIMIT |
2200 |
MEMORY.md limit |
MEMORY_USER_CHAR_LIMIT |
1375 |
USER.md limit |
MEMORY_REVIEW_ENABLED |
unset | 1 enables the Stop-hook review |
MEMORY_SKILLS_DIR |
~/.claude/skills |
Skills dir the Curator manages |
MEMORY_CURATOR_ARCHIVE |
unset | 1 lets the Curator move (not just report) stale skills |
MEMORY_CURATOR_STALE_DAYS |
30 |
Unused-days before a skill is "stale" |
MEMORY_CURATOR_ARCHIVE_DAYS |
90 |
Unused-days before a skill is archivable |
MEMORY_CURATOR_INTERVAL_DAYS |
7 |
Min days between Curator sweeps |
Testing
Layered by cost, zero dev dependencies (plain Node — no Bun, no npm install):
npm test # unit + integration — zero token, ~1s, run on every edit
npm run test:unit # manifests, skill frontmatter, and the store/security/correction/curator modules
npm run test:integration # version consistency, hook wiring, MCP path, markdown links, real MCP stdio round-trip
npm run test:e2e # model-backed: loads the plugin via `claude --plugin-dir` (~$0.01, needs auth)
The unit suite exercises the real logic modules against temp dirs (never your
~/.claude); the integration suite spawns the actual MCP server and drives it
over JSON-RPC. See docs/testing-strategy.md for the
full layout and CI policy.
Not included (vs Hermes)
- Write-approval gating — add a
PreToolUsehook matchingmcp__memory__memory_*that returns{"permissionDecision":"ask"}(or stages to a pending file). - Session search — Claude Code already ships a
conversation-searchskill over~/.claude/projects/*/*.jsonl; no FTS5 server needed.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。