Claude Code can actually build long-term memory using Dreams

PromptCube Novice 1h ago 533 views 8 likes 2 min read

Memory is usually the biggest bottleneck for any LLM agent. Most people just jam more tokens into the context window and hope for the best, but that's a losing battle once the conversation hits a certain length. I've been experimenting with Dreams to handle this, and it's a much cleaner way to let an agent "remember" things across sessions without the typical context bloat.

The core idea here isn't just storing logs, but using a synthesis process—the "Dream"—where the agent reflects on its recent interactions and compresses them into core facts, preferences, or learned behaviors. Instead of searching through a massive database of raw chat history, the agent queries these synthesized memories.

If you want to set this up for your own AI workflow, you can implement a simple loop where the agent periodically summarizes its state. Here is a basic conceptual implementation of how you might structure the memory update:

{
  "memory_update": {
    "timestamp": "2023-10-27T10:00:00Z",
    "source_interaction_id": "session_456",
    "synthesized_fact": "User prefers Python over TypeScript for data processing scripts and dislikes verbose documentation.",
    "confidence_score": 0.95,
    "category": "user_preference"
  }
}

To make this a real-world deployment, you need a three-step pipeline:

1. Observation: The agent tracks key events or contradictions during a live session.
2. Dreaming: At the end of a session or a specific trigger, a separate LLM call processes these observations. It asks, "What did I learn about the user or the project that is worth keeping forever?"
3. Integration: These distilled insights are stored in a vector database or a simple JSON profile that gets injected into the system prompt of the next session.

This is a massive leap over standard RAG (Retrieval-Augmented Generation). RAG is great for finding a needle in a haystack, but "Dreaming" is about building a mental model of the user. When the agent starts the next session, it doesn't just have access to old documents; it has a refined understanding of your specific needs.

For those doing a deep dive into agentic memory, the trick is in the filtering. If you save everything, you're just back to square one with a bloated context. The "Dream" phase must be aggressive about discarding noise and only keeping high-signal information. This transforms the agent from a stateless tool into something that actually evolves as you use it.

rustDreamsJSONL
Related examples in this direction are worth a look in these real-world AI monetization case studies, with plenty of directly applicable cases.

All Replies (4)

P
PatFounder Advanced 1h ago
Does this trigger based on a specific token threshold or a manual command?
0 Reply
A
AlexGeek Novice 1h ago
Pretty sure it's automatic based on the context window, but I'm still digging into the docs to be 100% sure.
0 Reply
Z
ZenMaster Expert 1h ago
I've found that periodically summarizing key decisions helps keep the memory cleaner over time.
0 Reply
C
CyberSmith Advanced 1h ago
Adding a metadata tag to those memory files makes searching through them way faster later.
0 Reply

Write a Reply

Markdown supported