# coleam00/claude-memory-compiler architecture

> Architecture diagram of the GitHub repository coleam00/claude-memory-compiler, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/coleam00/claude-memory-compiler
- Repository: https://github.com/coleam00/claude-memory-compiler

## Overview

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: [`scripts/compile.py`](https://github.com/coleam00/claude-memory-compiler/blob/main/scripts/compile.py) (Compile), [`scripts/query.py`](https://github.com/coleam00/claude-memory-compiler/blob/main/scripts/query.py) (Query), [`scripts/lint.py`](https://github.com/coleam00/claude-memory-compiler/blob/main/scripts/lint.py) (Lint), [`scripts/flush.py`](https://github.com/coleam00/claude-memory-compiler/blob/main/scripts/flush.py) (Flush)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_integration["Claude boundary"]
  node_claude_settings["Claude settings<br/>hook config<br/>[settings.json]"]
  node_session_start["Session start<br/>hook<br/>[session-start.py]"]
  node_session_end["Session end<br/>hook<br/>[session-end.py]"]
  node_pre_compact["Pre-compact<br/>hook<br/>[pre-compact.py]"]
end

subgraph group_capture["Capture pipeline"]
  node_flush["Flush<br/>ingest<br/>[flush.py]"]
  node_agent_sdk{{"Agent SDK<br/>llm runtime"}}
  node_daily_logs["Daily logs<br/>append-only store"]
end

subgraph group_knowledge["Knowledge corpus"]
  node_compile["Compile<br/>normalizer<br/>[compile.py]"]
  node_knowledge_index["Knowledge index"]
  node_concepts["Concepts<br/>topic notes"]
  node_connections["Connections<br/>topic notes"]
  node_qa["Q&A<br/>topic notes"]
  node_query["Query<br/>retrieval cli<br/>[query.py]"]
end

subgraph group_maintenance["Maintenance"]
  node_lint["Lint<br/>health check<br/>[lint.py]"]
  node_config["Config<br/>shared support<br/>[config.py]"]
  node_utils["Utils<br/>shared support<br/>[utils.py]"]
end

node_claude_settings -->|"registers"| node_session_start
node_claude_settings -->|"registers"| node_session_end
node_claude_settings -->|"registers"| node_pre_compact
node_session_end -->|"triggers"| node_flush
node_pre_compact -->|"triggers"| node_flush
node_flush -->|"uses"| node_agent_sdk
node_agent_sdk -->|"appends"| node_daily_logs
node_daily_logs -->|"inputs"| node_compile
node_compile -->|"produces"| node_concepts
node_compile -->|"produces"| node_connections
node_compile -->|"produces"| node_qa
node_compile -->|"updates"| node_knowledge_index
node_session_start -->|"injects"| node_knowledge_index
node_query -->|"reads"| node_knowledge_index
node_query -->|"searches"| node_concepts
node_query -->|"searches"| node_connections
node_query -->|"searches"| node_qa
node_lint -->|"validates"| node_knowledge_index
node_lint -->|"validates"| node_concepts
node_lint -->|"validates"| node_connections
node_lint -->|"validates"| node_qa
node_config -->|"supports"| node_flush
node_config -->|"supports"| node_compile
node_config -->|"supports"| node_query
node_config -->|"supports"| node_lint
node_utils -->|"supports"| node_flush
node_utils -->|"supports"| node_compile
node_utils -->|"supports"| node_query
node_utils -->|"supports"| node_lint

click node_claude_settings "https://github.com/coleam00/claude-memory-compiler/blob/main/.claude/settings.json"
click node_session_start "https://github.com/coleam00/claude-memory-compiler/blob/main/hooks/session-start.py"
click node_session_end "https://github.com/coleam00/claude-memory-compiler/blob/main/hooks/session-end.py"
click node_pre_compact "https://github.com/coleam00/claude-memory-compiler/blob/main/hooks/pre-compact.py"
click node_flush "https://github.com/coleam00/claude-memory-compiler/blob/main/scripts/flush.py"
click node_compile "https://github.com/coleam00/claude-memory-compiler/blob/main/scripts/compile.py"
click node_query "https://github.com/coleam00/claude-memory-compiler/blob/main/scripts/query.py"
click node_lint "https://github.com/coleam00/claude-memory-compiler/blob/main/scripts/lint.py"
click node_config "https://github.com/coleam00/claude-memory-compiler/blob/main/scripts/config.py"
click node_utils "https://github.com/coleam00/claude-memory-compiler/blob/main/scripts/utils.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_claude_settings,node_session_start,node_session_end,node_pre_compact toneBlue
class node_flush,node_agent_sdk,node_daily_logs toneAmber
class node_compile,node_knowledge_index,node_concepts,node_connections,node_qa,node_query toneMint
class node_lint,node_config,node_utils toneRose
```

## Components

### Claude boundary

Hook-driven integration with Claude Code

- [Claude settings](https://github.com/coleam00/claude-memory-compiler/blob/main/.claude/settings.json): hook config · Claude Code hook registration and event wiring · `.claude/settings.json`
- [Session start](https://github.com/coleam00/claude-memory-compiler/blob/main/hooks/session-start.py): hook · Injects current knowledge back into a new Claude session · `hooks/session-start.py`
- [Session end](https://github.com/coleam00/claude-memory-compiler/blob/main/hooks/session-end.py): hook · Captures transcript at normal session termination · `hooks/session-end.py`
- [Pre-compact](https://github.com/coleam00/claude-memory-compiler/blob/main/hooks/pre-compact.py): hook · Captures transcript before Claude compaction · `hooks/pre-compact.py`

### Capture pipeline

Transcript ingestion and daily log creation

- [Flush](https://github.com/coleam00/claude-memory-compiler/blob/main/scripts/flush.py): ingest · Extracts durable knowledge from captured conversation · `scripts/flush.py`
- **Agent SDK**: llm runtime · Claude-powered extraction of decisions, lessons, patterns, and gotchas
- **Daily logs**: append-only store · Intermediate knowledge store grouped by day

### Knowledge corpus

Markdown knowledge base, index, and retrieval

- [Compile](https://github.com/coleam00/claude-memory-compiler/blob/main/scripts/compile.py): normalizer · Turns daily logs into structured topic notes · `scripts/compile.py`
- **Knowledge index**: index · Entry point for the structured markdown corpus
- **Concepts**: topic notes · Core topic articles in the compiled corpus
- **Connections**: topic notes · Cross-linked relationship notes in the compiled corpus
- **Q&A**: topic notes · Question-answer style notes in the compiled corpus
- [Query](https://github.com/coleam00/claude-memory-compiler/blob/main/scripts/query.py): retrieval cli · Answers questions from the compiled markdown knowledge base · `scripts/query.py`

### Maintenance

Shared config and repository checks

- [Lint](https://github.com/coleam00/claude-memory-compiler/blob/main/scripts/lint.py): health check · Checks links, orphan notes, contradictions, and staleness · `scripts/lint.py`
- [Config](https://github.com/coleam00/claude-memory-compiler/blob/main/scripts/config.py): shared support · Shared path and runtime conventions · `scripts/config.py`
- [Utils](https://github.com/coleam00/claude-memory-compiler/blob/main/scripts/utils.py): shared support · Common helpers used across the scripts · `scripts/utils.py`

## Connections

- 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
