Persistent memory for Claude Code โ knowledge graph in Obsidian vault
Project description
๐ง Engram
Persistent memory for Claude Code โ your coding sessions become a knowledge graph
Like sleep consolidates human memory, /engram consolidates your coding sessions into reusable knowledge.
โจ What It Does
You work in Claude Code as usual. When you're done, run /engram. That's it.
You: /engram
CC: Analyzing session... Found 5 entities, 3 relations.
โ
Saved to vault: STDERR_PIPE_BLOCKING, CLAUDE_SLACK_BRIDGE, ...
๐ Daily note: 2026-04-06.md
Behind the scenes:
CC Session โ /engram โ Entity Extraction โ Knowledge Graph โ Obsidian Vault
(CC as LLM) (NetworkX) (Markdown + [[wikilinks]])
Your knowledge accumulates across sessions. Query it anytime:
You: /engram-query how did I fix the stderr bug?
CC: Found STDERR_PIPE_BLOCKING โ Bug where claude process stderr fills 64KB
pipe buffer, blocking stdout. Fixed by adding _drain_stderr async task.
Related: [[CLAUDE_SLACK_BRIDGE]]
๐๏ธ Architecture
Built on the OODA loop โ the same decision framework used by fighter pilots:
| Phase | What | How |
|---|---|---|
| ๐ Observe | Capture session conversations | CC session JSONL parser |
| ๐งญ Orient | Extract entities & relations | CC does entity extraction โ no external API |
| ๐ฏ Decide | Consolidate memory | 7-stage: replay โ feedback โ integrate โ prune โ community โ abstract โ lint |
| โก Act | Persist to vault | Obsidian markdown + NetworkX GraphML |
Zero External Dependencies
- No API keys โ CC itself is the LLM
- No vector database โ graph-only retrieval with CC entity routing
- No Docker โ just Python + networkx
- No cloud services โ everything runs locally
๐ฆ Installation
Prerequisites
- Claude Code installed
- Python 3.10+ with
networkx:pip install networkx
Setup
# 1. Clone and install
git clone https://github.com/qianheng-aws/engram.git
cd engram
pip install -e .
# 2. Initialize vault
engram init ~/.engram/vault
# 3. Register as CC plugin
claude plugin marketplace add ./
claude plugin install engram
# 4. (Optional) Enable auto-capture on session end
engram auto on
๐ฎ Commands
| Command | Description |
|---|---|
/engram |
Extract entities and relations from current session |
/engram-full |
Full consolidation: replay โ feedback โ integrate โ prune โ community โ abstract โ lint |
/engram-feedback |
Process human corrections from Obsidian callouts |
/engram-community |
Detect and summarize knowledge clusters (Louvain) |
/engram-status |
Show vault statistics, graph analysis, and pending sessions |
/engram-query <question> |
Search knowledge graph (keyword + graph traversal) |
/engram-on |
Enable auto-capture on session end |
/engram-off |
Disable auto-capture |
/engram vs /engram-full
/engram |
/engram-full |
|
|---|---|---|
| Stages | Replay only | All 6 stages + lint |
| Speed | Fast (one extraction) | Slower (multi-step) |
| When | Every session | Auto-triggered when needed |
Auto-consolidation: After each /engram, the CLI tracks how many replays have occurred since the last full run. When thresholds are reached, /engram will remind you (tier 1) or automatically escalate to a full consolidation (tier 2). Thresholds are configurable in ~/.engram/config.json:
{
"consolidation": {
"remind_after_replays": 10,
"remind_after_days": 7,
"force_after_replays": 15,
"force_after_days": 14
}
}
๐ Consolidation Stages
โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโโ โโโโโโโโโโโ โโโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโ
โ Replay โ โ โ Feedback โ โ โ Integrate โ โ โ Prune โ โ โ Community โ โ โ Abstract โ โ โ Lint โ
โ โ โ โ โ โ โ โ โ โ โ โ โ โ
โ Extract โ โ Human โ โ Merge โ โ Decay โ โ Cluster โ โ Discover โ โ Verify โ
โ entities โ โ review โ โ dupes โ โ old โ โ & label โ โ patterns โ โ vault โ
โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโโ โโโโโโโโโโโ โโโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโ
- Replay โ CC extracts entities/relations from session โ writes to graph + daily note
- Feedback โ Scans entity files for
[!correction]/[!merge]/[!delete]callouts left by the user in Obsidian โ CC applies fixes - Integrate โ Detects duplicate entities (token similarity) โ CC decides merge
- Prune โ Scores entities by decay (30-day half-life) โ archives stale ones
- Community โ Louvain clustering on the graph โ CC titles and summarizes each cluster
- Abstract โ Analyzes daily notes โ discovers behavioral patterns (e.g., "user always debugs by observe โ hypothesize โ verify")
- Lint โ Validates vault consistency: GraphML โ markdown sync, dead wikilinks, orphan nodes, frontmatter completeness
Human Feedback (Obsidian)
The Feedback stage processes corrections you leave directly in entity files. In Obsidian:
- Open any entity file (e.g.,
entities/concepts/STDERR_PIPE_BLOCKING.md) - Add a callout โ either
Cmd+Pโ search "callout", or type the syntax directly:
> [!correction] More accurate description
> Actually the buffer limit is 64KB, not 32KB
> [!merge] Should be same as ASYNC_DRAIN_STDERR
> [!delete] False extraction, not a real entity
- Run
/engram-feedback(or/engram-full) โ CC reads the callouts, applies fixes, and removes them
๐๏ธ Vault Structure
Open the vault in Obsidian to get an interactive knowledge graph:
- Install Obsidian from obsidian.md
- Open Obsidian โ Open folder as vault โ In the file picker, press
Cmd+Shift+Gand type~/.engram/vault- Alternatively, use a visible path:
engram init ~/engram/vault
- Alternatively, use a visible path:
- Toggle Graph View (Ctrl/Cmd + G) to see your knowledge graph
Entity nodes colored by type, with tags, wikilinks, and Graph View visualization
~/.engram/vault/
โโโ ๐ entities/ # Knowledge graph nodes
โ โโโ people/ # PERSON entities
โ โโโ concepts/ # Bugs, patterns, designs
โ โโโ projects/ # Repos, packages
โ โโโ tools/ # Libraries, frameworks
โ โโโ orgs/ # Teams, companies
โโโ ๐ relations/ # Edge table with weights
โโโ ๐ communities/ # Louvain cluster summaries
โโโ ๐ groups/ # Hyperedge MOC (Map of Content) files
โโโ ๐ daily/ # Session summaries by date
โโโ ๐ patterns/ # Discovered behavioral patterns
โโโ ๐ _meta/ # System data (GraphML, queue, lock)
Entity Example
---
entity_type: CONCEPT
tags:
- entity/concept
aliases:
- "Stderr Pipe Blocking"
created: 2026-04-03
last_updated: 2026-04-03
degree: 1
cssclasses:
- entity
- concept
---
# STDERR_PIPE_BLOCKING
Bug in claude-slack-bridge where claude process writes verbose logs
to stderr but daemon never reads it, causing 64KB buffer to fill
and block the entire process. Fixed by adding _drain_stderr task.
## Relations
- [[CLAUDE_SLACK_BRIDGE]] `PROJECT` โ Bridge had this bug causing sessions to hang (weight: 0.8)
Every entity links to related entities via [[wikilinks]] โ Obsidian renders these as an interactive graph. Tags, aliases, and cssclasses enable Dataview queries and Graph View styling.
๐ง Design Decisions
| Decision | Why |
|---|---|
| CC as LLM | No API keys needed. CC extracts entities directly. |
| Graph-only retrieval | No embeddings. CC picks relevant entities from the full list. Scales to ~2000 entities. |
| nano-graphrag reference | Reused prompt templates and storage format, not runtime. |
| Obsidian-native | All output is valid Obsidian markdown. Open vault โ instant graph view. |
| Description cap | Keep first + latest description only. Prevents infinite growth. |
| File lock | fcntl.LOCK_EX + read-merge-write prevents concurrent corruption. |
๐ ๏ธ CLI Reference
engram init [PATH] # Initialize vault + register in ~/.claude/CLAUDE.md
engram auto [on|off|status] # Toggle auto-capture on session end
engram status # Vault statistics + hub entities + density
engram query --question "..." # Search graph
engram replay --stdin # Process extracted entity/relation JSON
engram integrate # Detect duplicate entities
echo '<json>' | engram integrate --stdin # Execute merges
engram prune # Report decay scores
echo '<json>' | engram prune --stdin # Archive entities
engram community # Detect knowledge clusters
echo '<json>' | engram community --stdin # Save community summaries
engram abstract # Gather data for pattern discovery
echo '<json>' | engram save-pattern --stdin # Save discovered patterns
engram feedback # Scan entity files for correction callouts
echo '<json>' | engram feedback --stdin # Apply corrections/merges/deletes
engram context # Compact summary for system prompt injection
engram lint # Validate vault consistency
engram consolidation # Show consolidation tracking state
engram consolidation --reset # Reset counter (after full consolidation)
engram install # Re-register in ~/.claude/CLAUDE.md (auto on init)
engram uninstall # Remove from ~/.claude/CLAUDE.md
# All commands use the vault from last `engram init`. Override with --vault PATH.
๐ License
MIT โ do whatever you want with it.
Built in one afternoon with Claude Code. The tool that remembers itself. ๐พ
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file engram_echo-0.1.0.tar.gz.
File metadata
- Download URL: engram_echo-0.1.0.tar.gz
- Upload date:
- Size: 48.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52ec0a09170292349c8e6c1e22c8f3d49274024b9859c239734af95519fac85d
|
|
| MD5 |
39ef5a7c8a235c57614b1aea346e9483
|
|
| BLAKE2b-256 |
bc21c993bcda908abb053bf121fe1f780252d4a1279c3696275794fe3444cc42
|
File details
Details for the file engram_echo-0.1.0-py3-none-any.whl.
File metadata
- Download URL: engram_echo-0.1.0-py3-none-any.whl
- Upload date:
- Size: 27.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
852a2ee4b4b13a65d30955ad9a61e835162979eaa91105c40fedc58e6f8560ec
|
|
| MD5 |
791bcb9545726c88666f14607b0ed5fc
|
|
| BLAKE2b-256 |
b6c6e1953dc6c3a38ac83e04ffbe9b79a9800325485f3e792f296bba05b4ac68
|