Skip to main content
Glama

Claude Engram

为 AI 编程助手提供持久化记忆和会话智能。挂载到 Claude Code 的生命周期中以自动跟踪错误、决策和上下文——然后挖掘您的完整会话历史,以呈现模式、预测您所需的内容,并搜索您讨论过的所有内容。

零手动操作。适用于任何兼容 MCP 的客户端。

功能特点

自动化(钩子——零调用):

  • 跟踪每一次编辑、错误、测试结果和会话事件

  • 从您的提示中自动捕获决策(“让我们使用 X”,“切换到 Y”)

  • 在每次文件编辑前注入 3 条最相关的记忆

  • 当您即将重复过去的错误时发出警告

  • 检测编辑循环(同一文件在没有进展的情况下被编辑 3 次以上)

  • 在上下文压缩中存活——压缩前设置检查点,压缩后重新注入

  • 在每次会话后在后台挖掘您的会话历史

会话挖掘(自动,后台):

  • 在每次会话后解析 Claude Code 的完整对话日志 (JSONL)——包括子代理对话(Explore、Plan、code-reviewer 等)

  • 使用结构分析 + AllMiniLM 语义评分(容错)提取决策、错误、方法和用户更正

  • 构建跨所有过去对话的可搜索索引(超过 2 万个带有子代理的块)

  • 检测反复出现的困难、错误模式和文件编辑相关性

  • 在编辑前预测您需要的文件和上下文

  • 使用本地 LLM 反思模式,以综合根本原因和架构见解

  • 首次安装时,追溯挖掘您的整个会话历史

按需使用(MCP 工具):

  • memory — 存储、搜索、归档和管理记忆

  • session_mine — 搜索过去对话、查找决策、重放文件历史、检测模式

  • work — 记录带有推理的决策和错误

  • 此外:范围保护、上下文检查点、约定跟踪、影响分析

Related MCP server: io.github.420247jake/session-forge

工作原理

Claude Code
    |
    +-- Hooks (remind.py)                    <- Intercepts every tool call
    |   SessionStart / Edit / Bash / Error / Compact / Stop
    |
    +-- Session Mining (mining/)             <- Background intelligence
    |   JSONL parser -> Extractors -> Search index -> Pattern detection
    |
    +-- MCP Server (server.py)              <- Tools for manual operations
    |   memory, session_mine, work, scope, context, ...
    |
    +-- Scorer Server (scorer_server.py)    <- Persistent AllMiniLM process
        TCP localhost, ~90MB RAM, batch embeddings

钩子在每次工具调用时触发(每个预算 1-2 秒)。繁重的处理在会话结束后在后台子进程中进行。评分服务器保留在内存中,以实现快速的语义评分。

基准测试

集成基准测试

这些测试产品实际执行的功能。

基准测试

测试内容

结果

决策捕获 (220 条提示)

从用户提示中自动检测决策

97.8% 精度, 36.7% 召回率

注入相关性 (50 条记忆, 15 个案例)

编辑前呈现正确的记忆

14/15 通过, 100% 隔离

压缩存活 (6 种场景)

规则/错误在上下文压缩中存活

6/6

错误自动捕获 (53 个负载)

提取错误,拒绝噪声,去重

100% 召回率, 97% 精度

多项目范围界定 (11 个案例)

子项目隔离 + 工作区继承

11/11

编辑循环检测 (12 种场景)

检测螺旋式 vs 迭代式改进

12/12

会话挖掘 (27 项测试)

JSONL 解析、索引、搜索、增量处理

27/27

Obsidian 库 (25 项测试)

与 PARA + CLAUDE.md 库结构的兼容性

25/25

复现: python tests/bench_integration.py, bench_session_mining.py, bench_obsidian_vault.py

检索基准测试

仅检索 (recall@k) — 是否在顶部结果中找到了正确的记忆。

基准测试

分数

LongMemEval Recall@5 (500 个问题)

0.966

LongMemEval Recall@10

0.982

ConvoMem (250 项, 5 个类别)

0.960

LoCoMo R@10 (1,986 个问题)

0.649

速度

43ms/查询

跨会话搜索

112ms/查询 (超过 7310 个块)

复现: python tests/bench_longmemeval.py, bench_locomo.py, bench_convomem.py

兼容性

平台

功能

自动捕获

Claude Code (CLI, 桌面端, VS Code, JetBrains)

全部

完全 — 钩子 + 会话挖掘

Cursor

MCP 工具 (记忆, 搜索等)

无钩子

Windsurf

MCP 工具

无钩子

Continue.dev

MCP 工具

无钩子

Zed

MCP 工具

无钩子

任何 MCP 客户端

MCP 工具

无钩子

Obsidian 库

全部 (根目录需有 CLAUDE.md)

使用 Claude Code 时完全支持

安装

git clone https://github.com/20alexl/claude-engram.git
cd claude-engram
python -m venv venv
source venv/bin/activate  # or venv\Scripts\activate on Windows

pip install -e .                # Core
pip install -e ".[semantic]"    # + AllMiniLM for vector search and semantic scoring

python install.py               # Configure hooks, MCP server, and /engram skill

项目配置

python install.py --setup /path/to/your/project

或者将 .mcp.json 复制到您的项目根目录。

注意: 本仓库中的 CLAUDE.md 是 engram 特定的文档——engram 的工作并不需要它。钩子会自动触发,/engram 技能提供按需快速参考。如果您已经为项目准备了 CLAUDE.md,请保持原样,不要覆盖它。如果您希望在项目规则旁边使用 engram 文档,请将其重命名为 CLAUDE-ENGRAM.md(或类似名称),以免覆盖现有文件——Claude 在相关时会看到它。

更新

cd claude-engram
git pull
pip install -e ".[semantic]"    # Reinstall if dependencies changed
python install.py               # Re-run to update hooks and /engram skill

钩子和 MCP 工具会立即获取代码更改(可编辑安装)。在 Claude Code (/mcp) 中重新连接 MCP 服务器以重新加载服务器进程。

项目中途采用

已经在项目中深入工作了?正常安装即可。在第一次会话中,engram 会自动检测您现有的 Claude Code 会话历史并在后台进行挖掘——从所有过去的对话中提取决策、错误和模式。无需手动操作。

核心功能

记忆系统

  • 混合搜索 — 关键词 + AllMiniLM 向量 + 重排序。无需 ChromaDB。

  • 评分注入 — 在每次编辑前,根据文件匹配、标签、时效性和重要性注入前 3 条记忆。

  • 分层存储 — 热数据(快速)+ 归档(冷数据,可搜索,可恢复)。规则和错误永远不会归档。

  • 多项目 — 记忆按子项目划分范围。工作区规则向下级联。

会话挖掘

  • 结构提取 — 分析对话流程(确认、重定向、错误->修复序列、方法变更)而不是模板匹配。

  • 工具内容索引 — bash 命令 + 输出、编辑差异和错误追踪信息可与对话文本一起搜索。

  • 批量嵌入 — 通过批量 TCP 协议比单独调用快 22 倍。

  • 跨会话搜索 — 索引了 4.4 万多个对话块,支持语义 + 关键词 + 混合搜索。

  • 模式检测 — 跨会话的反复困难、错误模式、编辑相关性。

  • 预测性上下文 — 在编辑前,呈现相关文件和历史中可能的错误。

  • 跨项目学习 — 聚合您所有项目的模式。

  • 追溯引导 — 首次安装时挖掘所有现有的会话历史。

  • 评分器自动启动 — AllMiniLM 服务器在未运行时按需启动。不会静默降级。

生命周期

  • 自动捕获决策 — 结构模式(确认、重定向、明确选择)+ 语义评分作为奖励。

  • 自动跟踪错误 — 来自任何失败的工具。仅记录项目文件中的错误(过滤瞬态噪声)。在重复编辑前发出警告。

  • 压缩存活 — 使用会话决策/错误设置检查点,压缩后重新注入。

  • 编辑循环检测 — 当同一文件在没有进展的情况下被编辑 3 次以上时进行标记。

配置

变量

默认值

描述

CLAUDE_ENGRAM_MODEL

gemma3:12b

Ollama 模型(可选——仅用于 scout_search, 约定检查)

CLAUDE_ENGRAM_ARCHIVE_DAYS

14

不活跃记忆归档前的天数

CLAUDE_ENGRAM_SCORER_TIMEOUT

1800

AllMiniLM 服务器空闲超时(秒)

重新索引

如果搜索质量较差,或者您想在更新后重建索引:

python scripts/reindex.py "E:\workspace" --force            # rebuild search index
python scripts/reindex.py "E:\workspace" --force --extract   # also re-extract decisions/mistakes

或者通过 MCP: session_mine(operation="reindex", mode="bootstrap")

文档

图书馆手册 — 设计理念、内部结构、完整使用指南、API 参考、注意事项和更新日志。

/engram — 带有快速工具参考的斜杠命令(由 install.py 安装)。

许可证

MIT

Available Tools

21 tools
audit_batchC

Audit multiple files for issues. Supports glob patterns.

Inputs: file_paths (required), min_severity.

claude_engram_statusB

Check Claude Engram health. Returns: status, model, memory stats.

Inputs: no named parameters.

code_pattern_checkC

Check code against stored conventions using LLM.

Inputs: project_path (required), code (required).

code_quality_checkC

Check code for AI slop: long functions, vague names, deep nesting.

Inputs: code (required), language.

contextA

Context protection for long tasks. Operations:

  • checkpoint_save: Save task state (task_description, current_step, completed_steps, pending_steps, files_involved)

  • checkpoint_restore: Restore last checkpoint (task_id optional)

  • checkpoint_list: List saved checkpoints

  • verify_completion: Claim task done + verify (task, evidence, verification_steps)

  • instruction_add: Register critical instruction (instruction, reason, importance)

  • instruction_reinforce: Get instructions to remember

  • handoff_create: Create session handoff (handoff_summary, pending_steps, handoff_context_needed, handoff_warnings)

  • handoff_get: Retrieve latest handoff document

Inputs: operation (required), task_description, current_step, completed_steps, +14 more.

conventionB

Project conventions. Operations:

  • add: Store rule (project_path, rule, category, reason, examples, importance)

  • get: Get rules (project_path, category)

  • check: Check code/filename (project_path, code_or_filename)

  • remove: Remove convention by matching text (project_path, rule)

Inputs: operation (required), project_path (required), rule, category, +4 more.

deps_mapC

Map file dependencies. Shows imports and optionally reverse deps.

Inputs: file_path (required), include_reverse, project_root.

file_summarizeC

Summarize file purpose. Modes: quick (pattern-based) or detailed (LLM).

Inputs: file_path (required), mode.

find_similar_issuesC

Search codebase for bug pattern (e.g., 'except:\s*pass').

Inputs: issue_pattern (required), project_path (required), file_extensions, exclude_paths.

impact_analyzeC

Analyze change impact. Shows dependents, exports, risk level.

Inputs: file_path (required), project_root (required), proposed_changes.

loopA

Loop detection to prevent death spirals. Operations:

  • record_edit: Log file edit (file_path, description)

  • record_test: Log test result (passed, error_message)

  • check: Check if safe to edit (file_path)

  • status: Get edit counts and warnings

  • reset: Clear all loop tracking for a fresh start

Inputs: operation (required), file_path, description, passed, +1 more.

memoryC

Memory operations. Operations:

  • remember: Store a note (just content - category/relevance optional)

  • recall: Get all memories for project

  • forget: Clear project memories

  • search: Find by file/tags/query (file_path, tags, query, limit)

  • clusters: View grouped memories (cluster_id to expand)

  • cleanup: Dedupe/cluster/decay (dry_run, min_relevance, max_age_days)

  • consolidate: LLM-powered merge of related memories (tag, dry_run)

  • add_rule: Add permanent rule (content, reason) - never decays

  • list_rules: Get all rules for project

  • modify: Edit memory (memory_id, content, relevance, category)

  • delete: Remove single memory (memory_id)

  • batch_delete: Bulk delete by IDs (memory_ids) or by category. Rules/mistakes protected from category delete.

  • promote: Promote memory to rule (memory_id, reason)

  • recent: Get recent memories newest first (category, limit)

  • archive: Move old inactive memories to cold storage (dry_run to preview)

  • restore: Bring archived memory back to active (memory_id)

  • archive_search: Search archived memories (query, tags, limit)

  • archive_status: Show hot vs archived memory counts

  • hybrid_search: Semantic + keyword + scored search (query, file_path, tags, limit). Best retrieval.

  • embed_all: Generate AllMiniLM embeddings for all memories (enables hybrid_search)

Inputs: operation (required), project_path (required), content, category, +13 more.

outputC

Output validation. Operations:

  • validate_code: Check for fake/silent failures (code, context)

  • validate_result: Check output for fakes (output, expected_format, should_contain, should_not_contain)

Inputs: operation (required), code, context, output, +3 more.

pre_edit_checkB

Run BEFORE editing important files. Checks: past mistakes, loop risk, scope violations.

Inputs: file_path (required).

scopeA

Scope guard for multi-file tasks. Operations:

  • declare: Set task scope (task_description, in_scope_files, in_scope_patterns)

  • check: Verify file is in scope (file_path)

  • expand: Add files to scope (files_to_add, reason)

  • status: Get violations

  • clear: Reset scope

Inputs: operation (required), task_description, in_scope_files, in_scope_patterns, +3 more.

scout_analyzeC

Analyze code with local LLM. Provide code and question.

Inputs: code (required), question (required).

session_endA

Optional. Shows session summary. All memories auto-save without this - just a nice recap.

Inputs: project_path.

session_mineA

Mine session history. Operations:

  • search: Search across past conversations (query, project_path, limit, method=hybrid|semantic|keyword)

  • decisions: Find when/why a decision was made (query, project_path)

  • replay: Find discussions about a file (file_path, project_path)

  • struggles: Files/areas with repeated difficulty (project_path)

  • errors: Recurring error patterns across sessions (project_path)

  • correlations: Files always edited together (project_path)

  • timeline: Project development timeline (project_path)

  • summaries: Auto-generated session summaries (project_path)

  • overview: High-level project stats (project_path)

  • status: Mining index coverage (project_path)

  • reindex: Trigger background re-indexing (project_path, mode=post_session|bootstrap|full)

  • predict: Predict context needed for a file edit (file_path, project_path)

  • cross_project: Patterns across all projects (no project_path needed)

  • reflect: LLM-powered analysis of mistakes, patterns, and decisions (project_path)

Inputs: operation (required), project_path, query, file_path, +5 more.

session_startA

Load full context: memories, checkpoints, decisions, memory health. Auto-cleans duplicates. Hook auto-starts basic session, but this gives deep context.

Inputs: project_path (required).

workB

Work tracking. Operations:

  • log_mistake: Record error (description, file_path, how_to_avoid)

  • log_decision: Record choice (decision, reason, alternatives)

Inputs: operation (required), description, file_path, how_to_avoid, +3 more.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.2/5.0

    Scored across 21 tools

    Disambiguation4/5

    Most tools have distinct purposes, but there is some overlap between code_pattern_check, code_quality_check, and convention.check, which all analyze code against rules. Additionally, scout_search and find_similar_issues both search code for patterns, though they target different use cases. Descriptions help differentiate, but an agent might occasionally misselect.

    Naming Consistency4/5

    Tool names consistently use underscore_case with a verb_noun or noun_verb pattern (e.g., audit_batch, session_start, code_quality_check). However, a few names like claude_engram_status and find_similar_issues break the pattern slightly, and the nested operation prefixes (e.g., 'checkpoint_save' under 'context') could be more uniform.

    Tool Count4/5

    With 21 tools, the count is on the higher side but still reasonable for a comprehensive developer assistant server. Each tool serves a distinct purpose, and the inclusion of nested operations (e.g., under 'memory' and 'session_mine') keeps the top-level list manageable. A slight reduction could improve navigability.

    Completeness4/5

    The tool set covers a wide range of features: memory management, session/handoff handling, code analysis, conventions, scope, output validation, and work tracking. It lacks direct file I/O tools, but that is likely handled by other servers. Overall, the surface is comprehensive for a context and memory management server, with only minor gaps like a dedicated planning or task decomposition tool.

    Maintenance

    ActivityNo data
    ResponsivenessSyncing

    Related MCP Connectors

    Related MCP Servers