Core Architecture Overview
Component Details
1. TranscriptCompressor - Core Processing Engine
Central orchestrator for memory creation:- Transcript parsing and message filtering
- Large content filtering and optimization
- Chunked processing for large transcripts
- Archive creation and indexing
- Claude SDK integration for analysis
- Coordinates multiple specialized components
- Manages complex multi-step workflows
- Provides centralized error handling
2. PromptOrchestrator - Centralized Prompt Management
- Single source of truth for all prompt generation
- Type-safe context interfaces
- Template-based prompt construction
- Separation of concerns between prompt types
3. ChunkManager - Intelligent Content Splitting
- Token-based size estimation (3.5 chars/token)
- Context preservation with message overlap
- Metadata tracking for chunk relationships
- Adaptive sizing based on content type
Data Flow Architecture
Memory Creation Pipeline
Session Context Loading
Memory Storage Architecture
ChromaDB Integration via MCP
Claude-mem uses the Model Context Protocol (MCP) to interact with ChromaDB:Memory Document Structure
Collection Strategy
- Single Collection:
claude_memories
for all projects - ID Format:
{project}_{session}_{index}
ensures uniqueness - Metadata Filtering: Project isolation via metadata queries
- Semantic Search: Vector embeddings for content similarity
Hook System Architecture
Hook Lifecycle
Hook Implementation Pattern
Path Resolution Strategy
Multi-Environment Support
Path Discovery Algorithm
- Current Working Directory Analysis
- Git Repository Detection
- Project Name Extraction
- Configuration Path Resolution
Error Handling Philosophy
”Make It Work First” Implementation
Following the project’s core philosophy, error handling is minimal and focused:Graceful Degradation
- Hook Failures: Session continues with limited context
- MCP Errors: Return empty results, don’t block operation
- Parse Errors: Skip malformed messages, process remainder
- Storage Failures: Log diagnostics, provide user feedback
Performance Considerations
Token Management
- Estimation Algorithm: 3.5 characters per token approximation
- Chunk Sizing: 22.4K tokens per chunk (20% buffer from 28K limit)
- Context Overlap: 2 messages between chunks for continuity
Memory Optimization
- Large Content Filtering: 1MB threshold for tool results
- Streaming Processing: Handle large transcripts without loading entirely
- Lazy Loading: Commands load only required components
Caching Strategy
- Path Resolution: Cache discovered paths per session
- Project Detection: Cache project metadata
- Configuration: Load once per process lifecycle
Extension Points
Custom Hook Development
- Hook Template System: Standardized response formats
- Payload Validation: Type-safe input processing
- Helper Functions: Shared utilities for common operations
Command Extensions
- Commander.js Integration: Automatic CLI generation
- Option Parsing: Consistent flag handling
- Error Reporting: Standardized user feedback
MCP Tool Integration
Architecture Decisions & Trade-offs
Why MCP Over Direct ChromaDB?
Benefits:- Claude SDK integration for natural language processing
- Standardized tool interface
- Future flexibility for different backends
- Additional abstraction layer
- Dependency on Claude Code executable
- More complex error handling
Why Single Collection Strategy?
Benefits:- Simplified administration
- Cross-project discovery potential
- Consistent semantic search space
- Requires careful ID management
- Metadata filtering dependency
- Potential scaling concerns
Why Chunking Over Summarization?
Benefits:- Preserves conversation context
- No information loss
- Parallel processing capability
- Increased processing time
- More complex coordination
- Higher token usage