This is a research tool made by AlteredCraft
This is a demonstration app showing use of Claude's autonomous memory management using Anthropic's Memory Tool. Claude decides what to remember from your conversations and manages its own persistent memory across sessions - no explicit commands needed.
Related Articles:
- Node.js 18+ and npm
- Anthropic API key (get one here)
# 1. Install dependencies
npm install
# 2. Configure your API key (optional - can also set in UI)
cp .env.example .env
# Edit .env and add your ANTHROPIC_API_KEY
# 3. Run the app
npm run dev
# Open http://localhost:3000- Real-time streaming chat - See Claude's responses as they're generated
- Memory file browser - Visual explorer for Claude's memory files
- Session history - Review past conversations with token usage stats
- Sequence diagrams - Generate Mermaid diagrams from session traces
- System prompt selection - Choose from different assistant personalities
Claude decides what to remember during natural conversations:
Example:
You: Hi, I'm Alex. My son Leo turns 5 next Tuesday.
Claude: Hi Alex! Nice to meet you. Happy early 5th birthday to Leo!
[Creates /memories/user_profile.txt]
# Later...
You: What gift ideas do you have?
Claude: For Leo's 5th birthday, here are some age-appropriate ideas...
[Recalls Leo's age from memory]
How it works:
- You chat naturally - No special commands needed
- Claude decides what to remember - Names, preferences, project details
- Memory persists - Stored as text files in
./memories/ - Automatic recall - Claude retrieves relevant memories when needed
- Every conversation traced to
./sessions/as JSON - Full observability: messages, tool calls, token usage
- Generate visual sequence diagrams showing interaction flow
- Export and analyze conversation patterns
Single Next.js Full-Stack Application:
- Frontend: Next.js 16 + TypeScript + Tailwind CSS
- Backend: Next.js API Routes (server-side TypeScript)
- Communication: Server-Sent Events (SSE) for streaming
- Storage: Local filesystem for memory files and sessions
- AI: Anthropic Claude with Memory Tool integration
Key Components:
ConversationManager- Orchestrates Claude conversationsLocalFilesystemMemoryTool- File-based memory storageSessionTrace- Records all interactions for analysis- 14 API Routes - Session, chat, memory, and history management
See CLAUDE.md for detailed architecture documentation.
Choose from different assistant personalities in the UI settings:
prompts/
βββ concise prompt_explanatory.txt # Verbose memory logging
βββ concise prompt.txt # Standard behavior
βββ more precise prompt_explanatory.txt # Detailed explanations
βββ more precise prompt.txt # Fine-tuned responses
Custom Prompts:
- Create
.txtfiles inprompts/directory - They'll automatically appear in the UI selector
- Lines starting with
#are comments (stripped automatically) - Current date/time appended automatically
Every conversation is recorded with complete observability:
{
"session_id": "20250117_143022_abc123",
"start_time": "2025-01-17T14:30:22Z",
"model": "claude-sonnet-4-5-20250929",
"events": [
{"event_type": "user_input", "content": "..."},
{"event_type": "tool_call", "tool_name": "memory", "command": "create"},
{"event_type": "llm_response", "content": "..."},
{"event_type": "token_usage", "cumulative": {...}}
]
}Generate Sequence Diagrams:
- View any session in the UI
- Click "Generate Diagram"
- See Mermaid visualization of interaction flow
- Article: Implicit Memory Systems for LLMs : When Code Surrenders to Context
- Anthropic Docs: Memory Tool
- Architecture Details: CLAUDE.md - Comprehensive technical documentation
- Original v1: simple_llm_memory_poc
The LocalFilesystemMemoryTool class implements Anthropic's Memory Tool API with a custom filesystem-based storage system. Located at lib/server/memory-tool.ts, it provides Claude with six autonomous memory operations for persistent, file-based memory management.
- view - Read files or list directory contents
- create - Create new memory files (prevents overwrites)
- str_replace - Find and replace text within files
- insert - Insert text at specific line numbers
- delete - Remove files or directories recursively
- rename - Move or rename files/directories
- Path validation - Prevents directory traversal attacks via
_validatePath()method - Dual logging - MemoryOperationLogger (
./logs/memory-operations.log) + console output - Session tracing - All operations logged to session JSON files
- Real-time UI updates - Operation tracking powers MemoryBrowser animations
- Integration - Registered with ConversationManager and Anthropic's toolRunner
Memory files are stored in ./memories/ as plain text. Claude autonomously decides the file structure (flat or hierarchical) and naming conventions.
lib/server/memory-tool.ts- Main implementation (618 lines)lib/server/conversation-manager.ts- Tool instantiation and integrationlib/server/memory-operation-logger.ts- Dedicated logging systemlib/server/session-trace.ts- Session recording and tracing
For detailed documentation, see CLAUDE.md.
The UI displays memory operations in real-time as Claude executes them, creating responsive visual feedback through the Memory Tool Calls console and file browser animations.
Tool call events are generated via callbacks during SDK execution, but callbacks cannot directly yield values in async generators. Initially, events were accumulated in an array and only emitted after each message stream completed, causing all memory operations to appear batched at the end of responses.
A lightweight synchronous queue bridges the callback-to-generator gap:
AsyncEventQueue(lib/server/async-event-queue.ts) - 71-line queue withenqueue()(callback-safe) anddrain()(generator-safe) methods- Frequent draining - Queue checked after every SDK streaming event (~50ms intervals)
- Multi-layered - Additional drains after message completion, before done event, and in error handlers
Memory Tool Executes β SessionTrace callback β eventQueue.enqueue(event)
β
SDK streaming event arrives β drainEventQueue() β yield to SSE stream
β
Frontend receives β ToolCallConsole + MemoryBrowser update immediately
Memory operations appear in the UI within <50ms of execution with word-by-word text streaming preserved. The queue is drained after each content_block_delta event, ensuring tool calls are never batched even when they execute before text generation.
Implementation: lib/server/conversation-manager.ts:64-134
