How coleam00/claude-memory-compiler works
1. What this repo is
- This is a local, filesystem-based knowledge compiler for Claude conversations.
- It is not a web app or a database-backed service; the architecture centers on Claude Code hooks, Python scripts, and Markdown files.
2. Primary integration boundary
- The main external integration is Claude Code via .claude/settings.json.
- The repo’s behavior is driven by hook events at session start, session end, and pre-compact, which makes it an event-driven capture system rather than a polling job.
3. Hook layer
- hooks/session-start.py injects the current knowledge base index back into the next Claude session.
- hooks/session-end.py and hooks/pre-compact.py act as capture triggers so transcripts are not lost at normal end-of-session or compacting boundaries.
- This layer is the bridge between interactive conversation and persistent storage.
4. Capture and extraction path
- scripts/flush.py is the ingestion step.
- It takes the captured transcript and uses the Claude Agent SDK to decide what is worth preserving: decisions, lessons, patterns, gotchas, etc.
- Output is appended to a daily log, which is the first persistent knowledge artifact.
5. Daily log storage
- The daily log appears to live under daily/YYYY-MM-DD.md.
- This is an append-only intermediate store: raw-ish distilled knowledge, grouped by day, before being reorganized into durable topics.
- The system uses local time and has an end-of-day behavior; the README notes compilation after 6 PM local time.
6. Compilation layer
- scripts/compile.py converts daily logs into the structured knowledge base.
- The compiled output is organized into topic-oriented Markdown collections such as concepts, connections, and qa.
- This is the main “knowledge normalization” step: turning chronological notes into cross-referenced articles.
7. Knowledge base shape
- The repository uses a markdown-first content model with an index file rather than embeddings or a vector database.
- The important architectural boundary is: raw conversation → daily log → structured knowledge articles → index.
- Cross-links matter more than semantic search infrastructure here.
8. Retrieval path
- scripts/query.py answers questions against the compiled knowledge base.
- It relies on the index-guided structure of the markdown corpus instead of RAG/vector similarity.
- There is also a --file-back mode that writes the answer back into files, indicating retrieval can feed curation workflows.
9. Quality and maintenance
- scripts/lint.py performs repository health checks such as broken links, orphaned notes, contradictions, and staleness.
- The --structural-only option suggests a fast validation mode focused on graph/structure integrity rather than content semantics.
10. Shared script infrastructure
- scripts/config.py and scripts/utils.py are the shared support layer.
- They likely centralize path conventions, timestamps, file discovery, and common helpers so compile, flush, query, and lint operate consistently on the same corpus.
11. Operational model
- uv.lock and pyproject.toml show a Python package managed with uv.
- There is no server process to deploy; the system is run as local CLI commands and hook-invoked background jobs.
12. End-to-end data flow
- The full loop is:
- conversation captured by Claude Code hooks
- flush.py extracts durable knowledge into daily logs
- compile.py reshapes daily logs into topic articles
- session-start.py injects the index into future sessions
- query.py and lint.py operate on the compiled corpus
- That loop is the central architecture diagram: a closed feedback system that continuously feeds prior knowledge back into future conversations.
13. Important architectural takeaway
- The repo’s core design choice is structured markdown plus an index, not vector search.
- Everything else exists to support that choice: hooks for capture, scripts for compilation/querying, and linting for maintaining the knowledge graph.
Main entry points: compile.py Compile · query.py Query · lint.py Lint · flush.py Flush
Components 16
Claude boundary
Hook-driven integration with Claude Code
- Claude settings · Claude Code hook registration and event wiring
.claude/settings.json - Session start · Injects current knowledge back into a new Claude session
hooks/session-start.py - Session end · Captures transcript at normal session termination
hooks/session-end.py - Pre-compact · Captures transcript before Claude compaction
hooks/pre-compact.py
Capture pipeline
Transcript ingestion and daily log creation
- Flush · Extracts durable knowledge from captured conversation
scripts/flush.py - Agent SDK · Claude-powered extraction of decisions, lessons, patterns, and gotchas
- Daily logs · Intermediate knowledge store grouped by day
Knowledge corpus
Markdown knowledge base, index, and retrieval
- Compile · Turns daily logs into structured topic notes
scripts/compile.py - Knowledge index · Entry point for the structured markdown corpus
- Concepts · Core topic articles in the compiled corpus
- Connections · Cross-linked relationship notes in the compiled corpus
- Q&A · Question-answer style notes in the compiled corpus
- Query · Answers questions from the compiled markdown knowledge base
scripts/query.py
Connections 29
- Claude settings → Session start: registers · Hooks bind Claude Code events to local scripts
- Claude settings → Session end: registers · Hooks bind Claude Code events to local scripts
- Claude settings → Pre-compact: registers · Hooks bind Claude Code events to local scripts
- Session end → Flush: triggers · Session end hands captured conversation to ingestion
- Pre-compact → Flush: triggers · Pre-compaction ensures transcript is not lost
- Flush → Agent SDK: uses · Extraction is delegated to Claude Agent SDK reasoning
- Agent SDK → Daily logs: appends · Preserved knowledge is written into daily logs
- Daily logs → Compile: inputs · Daily logs are normalized into durable topic notes
- Compile → Concepts: produces · Creates concept-oriented markdown articles
- Compile → Connections: produces · Creates cross-reference and relationship notes
- Compile → Q&A: produces · Creates question-answer style knowledge pages
- Compile → Knowledge index: updates · Compilation refreshes the index for retrieval and feedback
- Session start → Knowledge index: injects · Current index is fed back into new Claude sessions
- Query → Knowledge index: reads · Retrieval is guided by the compiled index
- Query → Concepts: searches · Answers are drawn from compiled notes
- Query → Connections: searches · Answers are drawn from compiled notes
- Query → Q&A: searches · Answers are drawn from compiled notes
- Lint → Knowledge index: validates · Checks structural integrity of the corpus
- Lint → Concepts: validates · Checks for broken links and stale content
- Lint → Connections: validates · Checks for broken links and stale content
- Lint → Q&A: validates · Checks for broken links and stale content
- Config → Flush: supports · Shared conventions and path handling
- Config → Compile: supports · Shared conventions and path handling
- Config → Query: supports · Shared conventions and path handling
- Config → Lint: supports · Shared conventions and path handling
- Utils → Flush: supports · Common helper layer used by scripts
- Utils → Compile: supports · Common helper layer used by scripts
- Utils → Query: supports · Common helper layer used by scripts
- Utils → Lint: supports · Common helper layer used by scripts