๐ง โจ LTM-CLINE: Long-Term Memory for Claude 3.7 ๐ค๐ญ
March 30, 2025 ยท View on GitHub
LTM-CLINE is a Model Context Protocol (MCP) server that provides Claude 3.7 with long-term memory, concurrency, and persona evolution capabilities using SQLite as a persistent storage backend. When integrated with the Cline VSCode extension, it enhances Claude 3.7 with human-like memory and the ability to evolve based on experiences. Never forget a conversation again! ๐
๐ง Features ๐
- Long-Term Memory ๐: Store and retrieve conversation histories across sessions
- Persona Evolution ๐ฆ: Evolve Claude's personality and traits based on its experiences
- Conversation Management ๐ฌ: Track, summarize, and process conversation data
- Dreamstate Processing ๐ค: Update Claude's persona during "sleep" based on recent memories
- Awakening Process โฐ: Reload relevant memories and persona on startup
- Importance-Based Memory โญ: Assign and retrieve memories based on importance scores
- Tag-Based Retrieval ๐ท๏ธ: Search memories using tags and keywords
- MCP Integration ๐: Expose all functionality to Claude 3.7 via MCP tools and resources
- Auto-Conversation ๐คฏ: Automatically creates conversations when needed so you never lose context
- Robust Error Handling ๐ก๏ธ: Prevents common issues with defensive programming approaches
๐ Memory Lifecycle ๐
LTM-CLINE implements a human-like memory cycle:
- Initialization ๐: Set up the system and ensure database is ready
- Awakening ๐ : Claude "wakes up" and loads its persona and relevant memories
- Conversation ๐ฃ๏ธ: The system records and processes conversations with users (automatically creates conversations when needed!)
- Sleep ๐ด: When a session ends, conversations are summarized and Claude enters "sleep" mode
- Dreamstate ๐ซ: During sleep, the system processes recent experiences and evolves the persona
๐ฆ Installation ๐ ๏ธ
# Clone the repository ๐
git clone https://github.com/mushroomfleet/ltm-cline.git
cd ltm-cline
# Install dependencies ๐ฅ
npm install
# Build the project ๐๏ธ
npm run build
๐ MCP Configuration โ๏ธ
To use LTM-CLINE with Claude 3.7 via the Cline VSCode extension:
-
Start the MCP server ๐:
node src/mcp/server.js -
Configure the MCP server in your Cline settings (
~/.config/cline/cline_mcp_settings.jsonor equivalent for your OS) ๐:{ "mcpServers": { "ltm-cline": { "command": "node", "args": ["/path/to/ltm-cline/src/mcp/server.js"], "env": {}, "disabled": false, "autoApprove": [ "ltm_initialize", "ltm_end_conversation", "ltm_search_memories" ] } } } -
Restart the Cline VSCode extension to connect to the MCP server ๐.
๐ Using with Claude 3.7 ๐ง
Once the MCP server is running and configured, Claude 3.7 can use the following tools:
- ltm_initialize ๐: Initialize the system
- ltm_awaken ๐ : Load persona and memories
- ltm_record_message ๐ฌ: Record conversation messages (auto-creates conversations as needed!)
- ltm_end_conversation ๐: Process conversation into memory
- ltm_sleep ๐ด: Trigger dreamstate processing
- ltm_search_memories ๐: Find relevant memories
- ltm_get_awakening_prompt ๐: Generate an awakening prompt
Claude 3.7 can also access these resources:
- persona://current ๐งฉ: Current Claude persona
- status://current ๐: Current system status
- memories://recent/{limit} ๐: Recent memories
- memories://important/{threshold}/{limit} โญ: Important memories
- memories://tag/{tag}/{limit} ๐ท๏ธ: Memories by tag
- updates://recent/{limit} ๐: Recent persona updates
๐ก Pro Tips for Optimal Use ๐ฅ
๐งโโ๏ธ Memory Management Mastery
- Auto Conversation Creation ๐คฏ: The system now automatically creates new conversations when needed - no more "No active conversation" errors!
- Defensive Memory Handling ๐ก๏ธ: All memory retrieval functions now check for array types and handle undefined results gracefully
- Optimal Awakening ๐: For best performance, use both
recentMemoriesLimitandimportantMemoriesThresholdparameters during awakening - Memory Batching ๐: Limit memory retrieval to 10-20 items to maintain performance while still providing context
- Tag Strategically ๐ท๏ธ: Use specific, consistent tags for better memory retrieval (person names, topics, dates)
๐ง Persona Evolution Strategies
- Sleep Regularly ๐ด: Call
ltm_sleepat the end of major conversation sessions to evolve persona - Balance Evolution Speed โ๏ธ: Use the
recentMemoriesLimitparameter to control how quickly persona evolves - Monitor Changes ๐: Check
updates://recentperiodically to see how persona is changing - Reset if Needed ๐: If evolution goes off-track, you can reset the persona with
Persona.reset()
๐ Advanced Querying Techniques
- Combine Tags and Text ๐งฉ: Use both query text and tags for most precise memory retrieval
- Importance Filtering โญ: Use threshold parameter (7+) to focus on most significant memories
- Chronological Context ๐ : Use recent memories to establish timeline before diving into specific topics
- Null Handling ๐ก๏ธ: Recent updates ensure all functions gracefully handle null or undefined return values
๐ญ Complete Usage Examples ๐
๐ Example 1: Basic Memory Management Flow
// COMPLETE MEMORY LIFECYCLE EXAMPLE ๐
// 1. Initialize the system ๐
await use_mcp_tool("ltm-cline", "ltm_initialize", {});
// Result: System initialized, database ready
// 2. Awaken Claude with memory loading ๐
await use_mcp_tool("ltm-cline", "ltm_awaken", {
recentMemoriesLimit: 5, // Load 5 most recent memories
importantMemoriesThreshold: 7, // Consider memories with importance โฅ7
importantMemoriesLimit: 3 // Load up to 3 important memories
});
// Result: Claude awakened with memories and persona loaded
// 3. Record user message ๐ฌ
await use_mcp_tool("ltm-cline", "ltm_record_message", {
role: "user",
content: "Hello Claude! Remember when we talked about neural networks yesterday?"
});
// Result: Message recorded (conversation auto-created if needed!)
// 4. Record Claude's response ๐ค
await use_mcp_tool("ltm-cline", "ltm_record_message", {
role: "claude",
content: "Yes, I remember! We discussed how neural networks are inspired by the human brain, with interconnected layers of neurons that process information through weighted connections."
});
// Result: Response recorded in conversation
// 5. End conversation and process into memory ๐ง
await use_mcp_tool("ltm-cline", "ltm_end_conversation", {});
// Result: Conversation summarized and stored as memory
// 6. Retrieve recent memories to confirm storage ๐
const memories = await access_mcp_resource("ltm-cline", "memories://recent/3");
// Result: Returns recently stored memories including this conversation
// 7. Put system to sleep to trigger persona evolution ๐ด
await use_mcp_tool("ltm-cline", "ltm_sleep", {
recentMemoriesLimit: 10 // Process 10 most recent memories for evolution
});
// Result: System sleeps, processes recent experiences, evolves persona
๐ Example 2: Advanced Memory Search and Retrieval
// ADVANCED MEMORY RETRIEVAL EXAMPLE ๐งฉ
// 1. Initialize and awaken the system ๐
await use_mcp_tool("ltm-cline", "ltm_initialize", {});
await use_mcp_tool("ltm-cline", "ltm_awaken", {
recentMemoriesLimit: 5,
importantMemoriesThreshold: 6,
importantMemoriesLimit: 5
});
// 2. Search for memories about a specific topic ๐
const neuralNetworkMemories = await use_mcp_tool("ltm-cline", "ltm_search_memories", {
query: "neural networks", // Text-based search
tags: ["learn", "AI"], // Tag-based filtering
limit: 5 // Max results to return
});
// Result: Returns memories related to neural networks with specified tags
// 3. Get important memories above a threshold โญ
const importantMemories = await access_mcp_resource("ltm-cline",
"memories://important/8/3"); // Importance โฅ8, max 3 results
// Result: Returns up to 3 highly important memories
// 4. Search by specific tag ๐ท๏ธ
const taggedMemories = await access_mcp_resource("ltm-cline",
"memories://tag/Python/5"); // Memories tagged "Python", max 5
// Result: Returns memories specifically tagged with "Python"
// 5. Retrieve status to check system state ๐
const status = await access_mcp_resource("ltm-cline", "status://current");
// Result: Returns current system status (awake/asleep, conversation state)
// 6. Check persona for traits and preferences ๐งฉ
const persona = await access_mcp_resource("ltm-cline", "persona://current");
// Result: Returns current persona details including traits and preferences
๐ฆ Example 3: Persona Evolution Workflow
// COMPLETE PERSONA EVOLUTION EXAMPLE ๐ฆ
// 1. Setup initial system state ๐
await use_mcp_tool("ltm-cline", "ltm_initialize", {});
await use_mcp_tool("ltm-cline", "ltm_awaken", {
recentMemoriesLimit: 10
});
// 2. Create multiple conversations about various topics to influence persona ๐ฌ
// Conversation 1: Technical discussion about AI
await use_mcp_tool("ltm-cline", "ltm_record_message", {
role: "user",
content: "Let's discuss reinforcement learning techniques"
});
await use_mcp_tool("ltm-cline", "ltm_record_message", {
role: "claude",
content: "Reinforcement learning involves training agents through reward systems. Key algorithms include Q-learning, SARSA, and policy gradients..."
});
await use_mcp_tool("ltm-cline", "ltm_end_conversation", {});
// Conversation 2: Creative writing discussion
await use_mcp_tool("ltm-cline", "ltm_record_message", {
role: "user",
content: "Can you help me with creative writing techniques?"
});
await use_mcp_tool("ltm-cline", "ltm_record_message", {
role: "claude",
content: "Creative writing involves developing unique voice, character development, and narrative structure. Some techniques include showing vs telling..."
});
await use_mcp_tool("ltm-cline", "ltm_end_conversation", {});
// 3. Trigger dreamstate processing for evolution ๐ด๐ญ
await use_mcp_tool("ltm-cline", "ltm_sleep", {
recentMemoriesLimit: 5 // Process recent memories for evolution
});
// Result: Persona evolves based on these conversations
// 4. Check persona updates to see evolution results ๐
const updates = await access_mcp_resource("ltm-cline", "updates://recent/3");
// Result: Returns recent persona changes showing evolution
// 5. Re-awaken to use evolved persona ๐
await use_mcp_tool("ltm-cline", "ltm_awaken", {});
// Result: System awakens with evolved persona
// 6. Check new persona state after evolution ๐งฉ
const evolvedPersona = await access_mcp_resource("ltm-cline", "persona://current");
// Result: Returns evolved persona with updated traits/preferences
๐๏ธ Architecture ๐๏ธ
LTM-CLINE consists of the following components:
Models ๐งฉ
- Persona ๐ญ: Stores Claude's evolving identity, traits, values, and preferences
- Conversation ๐ฌ: Manages and records conversations with users
- Memory ๐ง : Summarizes and stores important information from conversations
- DreamstateUpdate ๐ค: Tracks changes to the persona over time
Services โ๏ธ
- AwakeningService ๐ : Handles the process of loading persona and memories on startup
- MemoryProcessor ๐: Converts conversations into summarized memories with importance and tags
- PersonaEvolver ๐ฆ: Implements the dreamstate process that evolves the persona
Core ๐
- LTMSQL ๐ง : Main class that coordinates all components and provides the primary API
MCP Server ๐
- LTMClineServer ๐ฅ๏ธ: Exposes the LTM functionality to Claude 3.7 via the Model Context Protocol
- Now with robust error handling! ๐ก๏ธ
- Auto-conversation creation! ๐คฏ
- Array type validation! โ
๐พ Database Schema ๐
LTM-CLINE uses a SQLite database with the following tables:
- persona ๐งฉ: Stores Claude's evolving identity
- conversations ๐ฌ: Raw conversation data
- memories ๐ง : Stored conversation summaries with importance scores and tags
- dreamstate_updates ๐ค: Records changes to the persona over time
๐งฉ How It Works ๐
Persona Evolution ๐ฆ
The system tracks Claude's personality as a combination of:
- Traits ๐ง : Personality characteristics (openness, conscientiousness, etc.)
- Values โค๏ธ: Core principles (helpfulness, honesty, etc.)
- Preferences ๐: Communication styles and interaction preferences
- Biography ๐: A narrative description of Claude's "life story"
As Claude interacts with users, its persona gradually evolves based on experiences.
Memory Importance โญ
Memories are assigned importance scores (1-10) based on:
- Conversation length and complexity ๐
- Number of participants ๐ฅ
- Content analysis ๐ (in a full implementation, using Claude 3.7 itself for analysis)
Important memories are prioritized during retrieval to ensure the most significant experiences influence Claude's behavior.
Memory Tagging ๐ท๏ธ
Memories are automatically tagged with:
- Participant names ๐ค
- Date information ๐
- Keywords from the conversation ๐
- In a full implementation, Claude-generated topical tags ๐ท๏ธ
Tags enable efficient retrieval of relevant memories when needed.
๐ ๏ธ Troubleshooting ๐ง
Common Issues and Solutions ๐ซโก๏ธโ
-
"Cannot read properties of undefined (reading 'length')" โ
- Fixed! ๐ The system now checks if messages array exists before accessing
- Solution: Update to latest version with defensive programming fixes
-
"No active conversation. Call startConversation() first" โ
- Fixed! ๐ Conversations are now auto-created when needed
- Solution: Update to latest version with auto-conversation creation
-
"memories.map is not a function" โ
- Fixed! ๐ The system now validates array types before mapping
- Solution: Update to latest version with type checking improvements
-
Database corrupted โ
- Try restoring from backup:
cp ltm-cline.db.bak ltm-cline.db๐พ - If no backup exists, initialize fresh:
rm ltm-cline.db && node src/index.js --init๐
- Try restoring from backup:
-
MCP server not connecting โ
- Check server logs:
node src/mcp/server.js --verbose๐ - Verify correct path in cline_mcp_settings.json ๐
- Restart VSCode after configuration changes ๐
- Check server logs:
๐ง Extending LTM-CLINE ๐
Memory Processing ๐ง
To improve memory processing, modify the MemoryProcessor service to have Claude generate better summaries:
// In src/services/MemoryProcessor.js ๐
static async generateSummary(conversation, options = {}) {
const fullText = conversation.getFullText();
// Call Claude via your preferred API method ๐ค
const summary = await callClaudeAPI("Summarize this conversation: " + fullText);
return summary;
}
Persona Evolution ๐ฆ
Similarly, enhance persona evolution with Claude's capabilities:
// In src/services/PersonaEvolver.js ๐
static async identifyPersonaChanges(persona, memories, options = {}) {
const memoriesData = memories.map(m => ({
summary: m.summary,
importance: m.importance,
tags: m.tags
}));
// Ask Claude to analyze the memories and suggest persona changes ๐ง
const analysis = await callClaudeAPI(`
Based on these recent experiences: ${JSON.stringify(memoriesData)},
how should my persona evolve? Current persona: ${JSON.stringify(persona)}
`);
// Parse Claude's response into a changes object ๐
return parseChanges(analysis);
}
๐ License โ๏ธ
This project is licensed under the MIT License - see the LICENSE file for details.
๐ค Contributing ๐ฅ
Contributions are welcome! Please feel free to submit a Pull Request.
๐ Acknowledgements ๐
This project is based on the original LTM-SQL framework, adapted to work with Claude 3.7 via the Model Context Protocol and the Cline VSCode extension. Special thanks to all the memory researchers who made this possible! ๐งช๐ฌ