Skip to content

Latest commit

 

History

History
342 lines (267 loc) · 14.4 KB

File metadata and controls

342 lines (267 loc) · 14.4 KB

Mnemonic Architecture

Overview

Mnemonic is a pure filesystem-based memory system for Claude Code. It provides persistent knowledge storage across sessions using markdown files with YAML frontmatter.

Design Principles

  1. No External Dependencies: All operations use standard Unix tools (git, rg, find) and Claude's native capabilities
  2. Skill-First Architecture: Skills are self-contained and work without hooks or libraries
  3. MIF Level 3 Compliance: Standardized Memory Interchange Format for interoperability
  4. Filesystem as Database: Markdown files are the source of truth

Academic Foundations

These principles are grounded in both empirical research and theoretical foundations:

System Components

┌─────────────────────────────────────────────────────────────┐
│                      Claude Code CLI                        │
├─────────────────────────────────────────────────────────────┤
│  Plugin Layer                                               │
│  ┌─────────┐  ┌─────────┐  ┌─────────┐  ┌─────────┐         │
│  │Commands │  │ Skills  │  │ Agents  │  │  Hooks  │         │
│  └────┬────┘  └────┬────┘  └────┬────┘  └────┬────┘         │
│       │            │            │            │              │
│       └────────────┴────────────┴────────────┘              │
│                         │                                   │
├─────────────────────────┼───────────────────────────────────┤
│  Storage Layer          ▼                                   │
│  ┌──────────────────────────────────────────────────────┐   │
│  │              Filesystem (.memory.md files)           │   │
│  │  ┌─────────────────┐    ┌─────────────────────────┐  │   │
│  │  │  User-Level     │    │  Project-Level          │  │   │
│  │  │  ~/.claude/     │    │     │  │   │
│  │  │  mnemonic/{org}/│    │                         │  │   │
│  │  └─────────────────┘    └─────────────────────────┘  │   │
│  └──────────────────────────────────────────────────────┘   │
│                         │                                   │
│  ┌──────────────────────┴───────────────────────────────┐   │
│  │                    Git Repository                    │   │
│  └──────────────────────────────────────────────────────┘   │
└─────────────────────────────────────────────────────────────┘

Component Details

Commands

Simple slash commands for direct user interaction:

Command Purpose
/mnemonic:setup Initialize and configure mnemonic
/mnemonic:capture Create a new memory
/mnemonic:recall Retrieve memories
/mnemonic:search Full-text search and iterative synthesis
/mnemonic:status System status
/mnemonic:gc Garbage collection

Skills

Self-contained instruction sets that work without external dependencies:

  • core: Complete memory operations
  • setup: CLAUDE.md configuration
  • search: Advanced search patterns and iterative synthesis
  • format: MIF Level 3 templates and schema
  • blackboard: Cross-session coordination and agent patterns
  • ontology: Custom ontology support with entity types and discovery
  • custodian: Memory health checks and maintenance
  • integrate: Plugin integration via sentinel markers
  • qmd-setup: Semantic search bootstrap
  • qmd-reindex: Memory re-indexing for semantic search

Hooks

Event-driven context injection via hookSpecificOutput.additionalContext:

SessionStart ──────► Memory status, health score, registry status
                     Blackboard pending items

PreToolUse ────────► Relevant memory paths when editing files
                     File pattern detection (auth, api, db, test, etc.)

UserPromptSubmit ──► Capture/recall trigger detection
                     Topic extraction for search

PostToolUse ───────► Capture opportunity context
                     Error/success detection

Stop ──────────────► Commit pending changes
                     Session summary

Key Principle: Hooks provide context, Claude decides. Hooks do not instruct Claude to take specific actions—they inform Claude about available memories and detected patterns, and Claude autonomously decides whether to read memories or use agents.

Agents

Autonomous background operations:

  • memory-curator: Conflict detection, deduplication, decay management
  • mnemonic-search-subcall: Efficient search agent for iterative query refinement (Haiku model)
  • compression-worker: Memory summarization for gc --compress (Haiku model)

Agents coordinate through the blackboard pattern. See the blackboard skill for details.

Tools

Validation and maintenance utilities:

  • mnemonic-validate: Validates memories against MIF Level 3 schema. See Validation.

Memory Model

MIF Level 3 Format

---
id: UUID
type: semantic|episodic|procedural
namespace: category/scope
created: ISO-8601
modified: ISO-8601
title: "Human readable title"
tags: [list, of, tags]
temporal:
  valid_from: ISO-8601
  recorded_at: ISO-8601
  decay:
    model: exponential
    half_life: P7D
    strength: 0.0-1.0
provenance:
  source_type: conversation|user_explicit|inferred
  agent: model-identifier
  confidence: 0.0-1.0
citations:                        # Optional external references
  - type: documentation|paper|blog|github|stackoverflow|article
    title: "Source Title"
    url: https://example.com
    relevance: 0.0-1.0
---

# Markdown Content

Body of the memory...

Memory Types

Type Description Decay Rate
semantic Facts, concepts, specifications Slow (P30D)
episodic Events, experiences, incidents Fast (P7D)
procedural Processes, workflows, how-tos Medium (P14D)

Namespace Hierarchy

{root}/
├── apis/           # API documentation
├── blockers/       # Issues, impediments
├── context/        # Background information
├── decisions/      # Architectural choices
├── learnings/      # Insights, discoveries
├── patterns/       # Code conventions
├── security/       # Security policies
├── testing/        # Test strategies
├── episodic/       # General events
└── .blackboard/    # Cross-session coordination

Data Flow

Capture Flow

User/Claude identifies capturable content
           │
           ▼
    ┌──────────────┐
    │ Generate UUID │
    │ Set timestamps│
    │ Classify type │
    └──────┬───────┘
           │
           ▼
    ┌──────────────┐
    │ Write .memory│
    │ .md file     │
    └──────┬───────┘
           │
           ▼
    ┌──────────────┐
    │ Git add +    │
    │ commit       │
    └──────────────┘

Recall Flow

User query or topic detection
           │
           ▼
    ┌──────────────┐
    │ ripgrep      │
    │ search       │
    └──────┬───────┘
           │
           ▼
    ┌──────────────┐
    │ Parse matches│
    │ Extract meta │
    └──────┬───────┘
           │
           ▼
    ┌──────────────┐
    │ Rank by      │
    │ relevance    │
    └──────┬───────┘
           │
           ▼
    ┌──────────────┐
    │ Update access│
    │ timestamps   │
    └──────────────┘

Cross-Session Coordination

The blackboard provides a shared space for session handoffs:

Session A                    Session B
    │                            │
    ├── Write to blackboard ─────┤
    │   (active-tasks.md)        │
    │                            │
    └── Stop hook commits ───────┼── SessionStart reads
                                 │   blackboard
                                 │
                                 └── Continues work

Git Integration

All memories are version-controlled:

  • Atomic commits: Each capture creates a commit
  • History tracking: Full audit trail of changes
  • Branching: Support for experimental memories
  • Conflict resolution: Git merge for concurrent sessions

Memory Maintenance

Garbage Collection

The /mnemonic:gc command manages memory lifecycle:

  • Age-based cleanup: Archive memories older than threshold
  • TTL expiry: Remove memories past their time-to-live
  • Decay-based cleanup: Archive low-strength memories
  • Compression: Summarize verbose older memories (via --compress)

Compression

Large memories can be compressed while preserving content:

# Added by gc --compress
summary: "Concise summary (max 500 chars)"
compressed_at: 2026-01-24T10:00:00Z

Compression criteria:

  • Age > 30 days AND lines > 100, OR
  • Strength < 0.3 AND lines > 100

Validation

The mnemonic-validate tool checks MIF Level 3 compliance:

# Validate all memories
./tools/mnemonic-validate

# CI-friendly JSON output
./tools/mnemonic-validate --format json

See Validation for details.

Multi-Agent Coordination

Agents coordinate using the blackboard pattern (ADR-003):

┌─────────────────────────────────────────────────────────────┐
│                       Blackboard                            │
│  ┌──────────────┐  ┌──────────────┐  ┌──────────────┐      │
│  │session-notes │  │active-tasks  │  │shared-context│      │
│  └──────┬───────┘  └──────┬───────┘  └──────┬───────┘      │
│         │                 │                 │               │
│         ▼                 ▼                 ▼               │
│      Register          Handoff          Workflow            │
│      Status            Context          State               │
└─────────────────────────────────────────────────────────────┘
         ▲                 ▲                 ▲
         │                 │                 │
┌────────┴─────┐  ┌────────┴─────┐  ┌────────┴─────┐
│memory-curator│  │search-subcall│  │compress-worker│
└──────────────┘  └──────────────┘  └───────────────┘

See the blackboard skill for patterns.

Performance Considerations

  • Search: ripgrep provides fast full-text search
  • Indexing: Filesystem is the index (no separate DB)
  • Caching: Recent memories cached in context
  • Decay: Exponential decay reduces noise over time
  • Compression: Reduces storage for older memories
  • Agent isolation: Subcall agents run in separate context (haiku model)

Related Documentation