๐Ÿง โœจ 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:

  1. Initialization ๐Ÿ: Set up the system and ensure database is ready
  2. Awakening ๐ŸŒ…: Claude "wakes up" and loads its persona and relevant memories
  3. Conversation ๐Ÿ—ฃ๏ธ: The system records and processes conversations with users (automatically creates conversations when needed!)
  4. Sleep ๐Ÿ˜ด: When a session ends, conversations are summarized and Claude enters "sleep" mode
  5. 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:

  1. Start the MCP server ๐Ÿš€:

    node src/mcp/server.js
    
  2. Configure the MCP server in your Cline settings (~/.config/cline/cline_mcp_settings.json or 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"
          ]
        }
      }
    }
    
  3. 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 recentMemoriesLimit and importantMemoriesThreshold parameters 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_sleep at the end of major conversation sessions to evolve persona
  • Balance Evolution Speed โš–๏ธ: Use the recentMemoriesLimit parameter to control how quickly persona evolves
  • Monitor Changes ๐Ÿ“Š: Check updates://recent periodically 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 ๐Ÿ†•
  • 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 ๐Ÿ”„

๐Ÿ”ง 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! ๐Ÿงช๐Ÿ”ฌ