claude-engram
Claude Engram
AIコーディングアシスタントのための永続メモリとセッションインテリジェンス。Claude Codeのライフサイクルにフックして、ミス、決定事項、コンテキストを自動追跡します。さらに、セッション履歴全体をマイニングしてパターンを浮き彫りにし、必要な情報を予測し、過去のすべての対話を検索可能にします。
手動操作は一切不要。MCP互換クライアントであれば何でも動作します。
機能
自動化(フック — 呼び出し不要):
すべての編集、エラー、テスト結果、セッションイベントを追跡
プロンプトからの決定事項(「Xを使おう」「Yに切り替えよう」など)を自動キャプチャ
ファイル編集のたびに、最も関連性の高い3つのメモリを自動注入
過去のミスを繰り返そうとした際に警告
編集ループ(進捗なしで同じファイルを3回以上編集)を検知
コンテキスト圧縮に対応 — 圧縮前にチェックポイントを作成し、後に再注入
セッション終了後、バックグラウンドでセッション履歴をマイニング
セッションマイニング(自動、バックグラウンド):
セッション終了ごとにClaude Codeの全会話ログ(JSONL)を解析(サブエージェントの会話を含む)
構造解析と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シナリオ) | スパイラルと反復的改善の区別 | 12/12 |
セッションマイニング (27テスト) | JSONL解析、インデックス作成、検索、増分処理 | 27/27 |
Obsidian Vault (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 vaults | フル (ルートに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回以上編集された場合にフラグを立てる。
設定
変数 | デフォルト | 説明 |
|
| Ollamaモデル(オプション — scout_search、規約チェック用) |
|
| 非アクティブなメモリがアーカイブされるまでの日数 |
|
| 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 toolsaudit_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).
scout_searchB
Search codebase semantically. Returns findings with files, lines, connections.
Inputs: query (required), directory (required), max_results.
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
Scored across 21 tools
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.
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.
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.
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
Related MCP Connectors
One shared project memory for your AI coding tools: recall, save and brief decisions anywhere.
Persistent engineering memory designed to follow developers across coding agents.
Shared memory for coding agents. Stop re-explaining your codebase every session.
Persistent cross-session memory shared by Codex, Claude Code, ChatGPT, and other AI agents.
Related MCP Servers
AlicenseNot gradedqualityCmaintenanceProvides persistent memory for AI coding assistants, storing and retrieving architectural decisions, patterns, and solutions across sessions using semantic search, while also offering git integration for commit messages and code expertise mapping.MIT- AlicenseNot gradedqualityDmaintenanceNever start from zero. Persistent session intelligence for AI coding assistants.70 npm1MIT
- AlicenseAqualityDmaintenanceLong-term memory for AI coding assistants. Remembers context once and recalls it across sessions.724MIT
- AlicenseNot gradedqualityCmaintenancePersistent memory for AI coding tools that captures conversations, builds a searchable knowledge graph, and automatically injects relevant context into new prompts.249MIT