How PAI's Memory System Captures and Retains Learning Signals Across Sessions
PAI's memory system records every interaction in a unified ~/.claude/MEMORY/ hierarchy, using event hooks for real-time signal capture and periodic harvesting tools to synthesize persistent learning data across sessions.
The Personal AI Infrastructure (PAI) by Daniel Miessler implements a sophisticated memory architecture that ensures no learning signal is lost between conversations. Unlike transient state files, PAI's memory system creates a durable record of user preferences, corrections, and behavioral patterns that persist indefinitely.
The Foundation: Persistent Storage Architecture
At the core of PAI's memory system lies a strict separation between transient runtime state and permanent learning storage. The architecture centers on the ~/.claude/MEMORY/ directory, which serves as the immutable record of all learning signals.
Native session transcripts form the primary data source. Claude Code automatically stores complete interaction logs in ~/.claude/projects/…/*.jsonl, capturing every message, tool call, and response in JSON Lines format. These files represent the single source of truth for session reconstruction.
The system distinguishes between two critical storage types:
MEMORY/— Persistent learning data that survives across sessions and system restartsSTATE/— Fast, mutable runtime state (likecurrent-work.json) that can be rebuilt fromMEMORY/logs if corrupted or deleted
Real-Time Signal Capture via Event Hooks
PAI's memory system employs a hook-driven architecture that listens for specific interaction events and immediately persists relevant data to dedicated sub-folders. This ensures learning signals are captured at the moment they occur, not retroactively.
Explicit and Implicit Feedback Capture
Two primary hooks handle user satisfaction signals:
ExplicitRatingCapture— Records user-provided ratings (thumbs up/down, numerical scores) toLEARNING/SIGNALS/ratings.jsonlImplicitSentimentCapture— Detects frustration signals, confusion markers, or enthusiasm cues from conversation patterns and stores them in the same ratings file
Work and Response Tracking
Additional hooks funnel operational learning into the LEARNING/ tree:
AutoWorkCreation.hook.ts— Captures automatically generated work itemsResponseCapture.hook.ts— Records significant AI responses for pattern analysisWorkCompletionLearning.hook.ts— Extracts "what we learned" summaries when tasks finish
These hooks write to specific paths within ~/.claude/MEMORY/LEARNING/, creating a structured hierarchy that separates raw signals from synthesized insights.
Periodic Harvesting and Synthesis
While hooks capture real-time signals, harvesting tools run periodically to scan raw session transcripts and consolidate learning data into actionable intelligence.
Session Harvesting
SessionHarvester.ts processes the projects/ directory JSONL files to extract:
- User corrections and error fixes
- Repeated query patterns
- Tool usage preferences
- Session insights and metadata
This tool writes processed learnings back into the LEARNING/ directory, transforming raw transcript data into structured knowledge.
Pattern Synthesis
LearningPatternSynthesis.ts operates on accumulated ratings and signals to generate higher-level reports:
- Aggregates weekly or monthly satisfaction trends
- Identifies recurring friction points
- Builds user preference profiles
These synthesis reports live in LEARNING/SYNTHESIS/, providing the AI with long-term behavioral context that persists across entirely new projects and sessions.
Directory Structure and Key Files
Understanding the file layout is essential for managing PAI's memory system:
| File/Path | Role |
|---|---|
~/.claude/MEMORY/LEARNING/SIGNALS/ratings.jsonl |
Stores explicit ratings and implicit sentiment captures |
~/.claude/MEMORY/LEARNING/SYNTHESIS/ |
Contains aggregated pattern reports from synthesis tools |
~/.claude/MEMORY/STATE/current-work.json |
Runtime pointer to active work (rebuildable from logs) |
~/.claude/projects/*/*.jsonl |
Native Claude Code session transcripts |
.claude/skills/CORE/SYSTEM/MEMORYSYSTEM.md |
Master specification for memory architecture |
.claude/skills/CORE/Tools/SessionHarvester.ts |
Periodic transcript processor |
.claude/skills/CORE/Tools/LearningPatternSynthesis.ts |
Aggregates signals into trend reports |
Inspecting and Managing Learning Signals
You can interact directly with PAI's memory system using standard command-line tools.
Inspect the latest rating signals:
tail ~/.claude/MEMORY/LEARNING/SIGNALS/ratings.jsonl
This displays the most recent user satisfaction entries and sentiment captures.
Run the harvesting pipeline manually:
# Extract learnings from the last 10 sessions
bun run ~/.claude/skills/CORE/Tools/SessionHarvester.ts --recent 10
# Build a weekly pattern report
bun run ~/.claude/skills/CORE/Tools/LearningPatternSynthesis.ts --week
View the current active work pointer:
cat ~/.claude/MEMORY/STATE/current-work.json
This helps debug the runtime state and verify which work items are currently active.
Summary
- PAI's memory system uses a dual-layer architecture: transient
STATE/files for runtime performance and persistentMEMORY/files for long-term learning retention. - Event hooks (
ExplicitRatingCapture,ImplicitSentimentCapture, and work-related hooks) capture learning signals in real-time and write them toLEARNING/SIGNALS/. - Periodic harvesting tools (
SessionHarvester.ts,LearningPatternSynthesis.ts) process raw session transcripts and aggregate signals into actionable reports underLEARNING/SYNTHESIS/. - All learning data persists across sessions because it resides in the
~/.claude/MEMORY/directory, which is never automatically cleared.
Frequently Asked Questions
How does PAI distinguish between temporary state and permanent memory?
PAI maintains a strict separation between ~/.claude/MEMORY/ and ~/.claude/MEMORY/STATE/. The MEMORY/ directory contains permanent learning signals, ratings, and synthesis reports that persist indefinitely. The STATE/ subdirectory holds fast, mutable runtime pointers like current-work.json that can be deleted and rebuilt from the permanent logs if corrupted.
What types of learning signals does PAI capture automatically?
PAI captures both explicit and implicit signals. Explicit signals include user-provided ratings (thumbs up/down) recorded by ExplicitRatingCapture. Implicit signals include detected frustration, confusion, or enthusiasm patterns captured by ImplicitSentimentCapture. Additionally, work-related hooks capture completion summaries, response patterns, and automatically generated work items.
How can I manually trigger the learning synthesis process?
You can run the harvesting tools manually using bun run commands. Execute ~/.claude/skills/CORE/Tools/SessionHarvester.ts with the --recent flag to process specific session counts, or run ~/.claude/skills/CORE/Tools/LearningPatternSynthesis.ts with --week or --month flags to generate aggregated pattern reports from the accumulated signal data.
Where are the raw session transcripts stored and why do they matter?
Raw session transcripts live in ~/.claude/projects/…/*.jsonl files. These JSON Lines files contain the complete record of every message, tool call, and response from Claude Code sessions. They serve as the single source of truth that harvesting tools scan to extract corrections, errors, and usage patterns, making them essential for the synthesis of long-term learning data.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →