Claude
Skills
Sign in
Back

claude-memory-compiler

Included with Lifetime
$97 forever

```markdown

Writing & Docs

What this skill does

```markdown
---
name: claude-memory-compiler
description: Give Claude Code an evolving memory that captures sessions, extracts decisions and lessons via the Claude Agent SDK, and compiles everything into structured cross-referenced knowledge articles.
triggers:
  - set up claude memory compiler
  - give claude code persistent memory
  - capture my coding sessions automatically
  - compile my claude conversations into a knowledge base
  - set up session hooks for claude code
  - install llm knowledge base for my project
  - make claude remember decisions across sessions
  - auto-capture claude code session transcripts
---

# Claude Memory Compiler

> Skill by [ara.so](https://ara.so) — Daily 2026 Skills collection.

Claude Memory Compiler gives Claude Code a persistent, evolving memory. Claude Code hooks automatically capture conversation transcripts at session end or pre-compaction. A background process using the Claude Agent SDK extracts decisions, lessons, and patterns, appending them to daily logs. A compiler then organizes those logs into structured, cross-referenced knowledge articles — no vector database or RAG required at personal scale.

Inspired by [Karpathy's LLM Knowledge Base](https://gist.github.com/karpathy/442a6bf555914893e9891c11519de94f) architecture.

---

## Installation

### Option 1 — Tell your AI agent

```
Clone https://github.com/coleam00/claude-memory-compiler into this project.
Set up the Claude Code hooks so my conversations automatically get captured
into daily logs, compiled into a knowledge base, and injected back into
future sessions. Read the AGENTS.md for the full technical reference.
```

### Option 2 — Manual setup

```bash
# Clone into your project root
git clone https://github.com/coleam00/claude-memory-compiler .claude-memory

cd .claude-memory

# Install dependencies (requires uv)
uv sync

# Copy hooks config into your project's Claude settings
cp .claude/settings.json ../.claude/settings.json
# Or merge the hooks block into an existing .claude/settings.json
```

### Dependency requirements

- Python 3.10+
- [`uv`](https://github.com/astral-sh/uv) package manager
- Claude Code (with Max, Team, or Enterprise subscription — no separate API credits needed)

---

## How It Works

```
Conversation
  -> SessionEnd / PreCompact hooks
  -> flush.py  (Claude Agent SDK extracts knowledge)
  -> daily/YYYY-MM-DD.md
  -> compile.py (after 6 PM or manually)
  -> knowledge/concepts/, connections/, qa/
  -> SessionStart hook injects index.md into next session
  -> cycle repeats
```

### Hook events used

| Hook | Purpose |
|------|---------|
| `SessionEnd` | Primary capture — fires when a session closes |
| `PreCompact` | Safety net — fires before mid-session compaction |
| `SessionStart` | Injects the knowledge index into each new session |

---

## Key Commands

```bash
# Compile new daily logs into knowledge articles
uv run python scripts/compile.py

# Ask a question against the knowledge base
uv run python scripts/query.py "Why did we switch from SQLite to Postgres?"

# Ask + save the answer back into the knowledge base
uv run python scripts/query.py "What auth strategy are we using?" --file-back

# Run all 7 health checks (broken links, orphans, contradictions, staleness)
uv run python scripts/lint.py

# Run only free structural checks (no LLM calls)
uv run python scripts/lint.py --structural-only
```

---

## Directory Structure

```
your-project/
├── .claude/
│   └── settings.json          # Hook configuration
├── daily/
│   └── YYYY-MM-DD.md          # Raw daily session logs
├── knowledge/
│   ├── index.md               # Master index (injected at session start)
│   ├── concepts/              # Structured concept articles
│   ├── connections/           # Cross-reference articles
│   └── qa/                    # Q&A articles saved with --file-back
└── scripts/
    ├── flush.py               # Session capture + extraction
    ├── compile.py             # Daily logs -> knowledge articles
    ├── query.py               # Index-guided retrieval
    └── lint.py                # Knowledge base health checks
```

---

## Configuration — `.claude/settings.json`

```json
{
  "hooks": {
    "SessionEnd": [
      {
        "command": "uv run python scripts/flush.py",
        "cwd": "${workspaceFolder}"
      }
    ],
    "PreCompact": [
      {
        "command": "uv run python scripts/flush.py --pre-compact",
        "cwd": "${workspaceFolder}"
      }
    ],
    "SessionStart": [
      {
        "command": "uv run python scripts/inject.py",
        "cwd": "${workspaceFolder}"
      }
    ]
  }
}
```

If you already have a `.claude/settings.json`, merge only the `hooks` block — don't overwrite existing settings.

---

## Code Examples

### Manually flush a transcript

```python
# scripts/flush.py is called automatically by hooks, but you can invoke it directly
import subprocess

result = subprocess.run(
    ["uv", "run", "python", "scripts/flush.py"],
    capture_output=True,
    text=True
)
print(result.stdout)
```

### Programmatic query

```python
# Query the knowledge base from your own scripts
import subprocess
import sys

def query_knowledge_base(question: str, save_back: bool = False) -> str:
    cmd = ["uv", "run", "python", "scripts/query.py", question]
    if save_back:
        cmd.append("--file-back")
    result = subprocess.run(cmd, capture_output=True, text=True)
    return result.stdout

answer = query_knowledge_base("What database migration strategy are we using?")
print(answer)
```

### Trigger compilation manually

```python
import subprocess

def compile_knowledge():
    """Compile all unprocessed daily logs into knowledge articles."""
    result = subprocess.run(
        ["uv", "run", "python", "scripts/compile.py"],
        capture_output=True,
        text=True
    )
    if result.returncode != 0:
        print("Compile error:", result.stderr)
    else:
        print(result.stdout)

compile_knowledge()
```

### Run lint checks programmatically

```python
import subprocess

def lint_knowledge_base(structural_only: bool = False) -> dict:
    cmd = ["uv", "run", "python", "scripts/lint.py"]
    if structural_only:
        cmd.append("--structural-only")
    result = subprocess.run(cmd, capture_output=True, text=True)
    return {
        "passed": result.returncode == 0,
        "output": result.stdout,
        "errors": result.stderr
    }

report = lint_knowledge_base(structural_only=True)
print(report["output"])
```

---

## Daily Log Format (`daily/YYYY-MM-DD.md`)

Each flush appends an entry like:

```markdown
## Session — 2026-04-10 14:32

### Decisions
- Switched auth from JWT to session cookies to simplify SSR compatibility.

### Lessons Learned
- `prisma migrate dev` resets the shadow DB on every run — use `--skip-generate` in CI.

### Patterns Identified
- All new API routes follow the `app/api/[resource]/route.ts` convention.

### Gotchas
- The `useRouter` hook from `next/navigation` behaves differently in Server Components — always import from the correct package.
```

---

## Knowledge Article Format (`knowledge/concepts/`)

Compiled articles use structured markdown:

```markdown
# Authentication Strategy

**Last Updated:** 2026-04-10
**Related:** [[Session Management]], [[API Security]]

## Summary
We use session cookies (not JWTs) for authentication to simplify SSR compatibility with Next.js App Router.

## Key Decisions
- Chose session cookies over JWTs on 2026-04-08 after discovering JWT refresh complexity with RSC.

## Lessons
- Always import `useRouter` from `next/navigation` in client components, never from `next/router`.

## Open Questions
- Should we add refresh token rotation for long-lived sessions?
```

---

## Automatic Compilation Trigger

`flush.py` checks local time after each session. If it is **after 6 PM**, it automatically triggers `compile.py` to process that day's logs. This means no manual scheduling is needed for end-of-day compilation.

To compile at any time:

```bash
uv 

Related in Writing & Docs