Skip to main content

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

License: MIT Python 3.10+ Claude Code Plugin Dependencies

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:

  1. Open any entity file (e.g., entities/concepts/STDERR_PIPE_BLOCKING.md)
  2. 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
  1. 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:

  1. Install Obsidian from obsidian.md
  2. Open Obsidian โ†’ Open folder as vault โ†’ In the file picker, press Cmd+Shift+G and type ~/.engram/vault
    • Alternatively, use a visible path: engram init ~/engram/vault
  3. Toggle Graph View (Ctrl/Cmd + G) to see your knowledge graph
Engram knowledge graph in Obsidian

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

engram_echo-0.1.0.tar.gz (48.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

engram_echo-0.1.0-py3-none-any.whl (27.3 kB view details)

Uploaded Python 3

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

Hashes for engram_echo-0.1.0.tar.gz
Algorithm Hash digest
SHA256 52ec0a09170292349c8e6c1e22c8f3d49274024b9859c239734af95519fac85d
MD5 39ef5a7c8a235c57614b1aea346e9483
BLAKE2b-256 bc21c993bcda908abb053bf121fe1f780252d4a1279c3696275794fe3444cc42

See more details on using hashes here.

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

Hashes for engram_echo-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 852a2ee4b4b13a65d30955ad9a61e835162979eaa91105c40fedc58e6f8560ec
MD5 791bcb9545726c88666f14607b0ed5fc
BLAKE2b-256 b6c6e1953dc6c3a38ac83e04ffbe9b79a9800325485f3e792f296bba05b4ac68

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page