Lossless Claw: The Complete Guide to Never Losing Context in OpenClaw
Lossless Claw: The Complete Guide to Never Losing Context in OpenClaw
Have you ever had a long conversation with an AI assistant, only to watch it completely forget what you discussed earlier? That frustrating moment when your agent can't recall the decisions you made or the files you modified? This is the context loss problem that plagues most AI systems, and it's exactly what Lossless Claw was built to solve.
Lossless Claw is a game-changing plugin for OpenClaw that replaces traditional context management with a system that literally never forgets. Instead of discarding old messages when conversations get too long, it stores everything in a database and uses smart summarization to keep your agent's memory intact. The result? Your AI assistant can reference details from hours ago as easily as it recalls what you said two minutes ago.
Quick Answer: Lossless Claw is a Lossless Context Management (LCM) plugin for OpenClaw that uses a DAG-based summarization system to preserve every message in your conversation while staying within model token limits. It stores all messages in a SQLite database, creates hierarchical summaries, and provides retrieval tools so agents can search and recall any detail from your conversation history.
What is Lossless Claw and How Does It Work?
Lossless Claw is an open source context management plugin developed by Martian Engineering specifically for OpenClaw. At its core, it solves a fundamental problem with how AI agents handle long conversations.
Most AI systems use something called "sliding-window compaction." When a conversation gets too long and approaches the model's token limit, the system simply throws away the oldest messages. It's like having a notepad where you erase the first page every time you add a new one. Sure, you stay within space limits, but you lose valuable information.
Lossless Claw takes a completely different approach. Instead of discarding messages, it:
- Saves everything to a SQLite database organized by conversation
- Creates summaries of older message chunks using your configured language model
- Builds a hierarchy where summaries get condensed into higher-level summaries, forming a directed acyclic graph (DAG)
- Assembles context for each turn by combining recent raw messages with compressed summaries
- Provides search tools so the agent can retrieve specific details from any point in the conversation
Think of it like a filing system with an index. The original documents never disappear—they're stored safely in the database. But instead of reading every document every time, the system maintains organized summaries that help you quickly find and access what you need.
The DAG structure is particularly clever. As your conversation grows, older summaries get condensed into even more compact summaries, creating layers of abstraction. Each summary links back to its source messages, so the agent can always drill down to the original details when needed.
The Technical Architecture
Lossless Claw is built primarily in TypeScript (71.8% of the codebase) with Go components (27.7%) for the interactive terminal UI. It integrates directly with OpenClaw's ContextEngine plugin system, which was introduced in version 2026.3.7 specifically to enable plugins like this.
The plugin implements seven lifecycle hooks that give it complete control over how context is managed:
- bootstrap: Initializes the database and loads configuration
- ingest: Processes each new message as it comes in
- assemble: Builds the context window before each model request
- compact: Triggers summarization when approaching token limits
- afterTurn: Cleans up after each interaction
- prepareSubagentSpawn: Handles context for spawned sub-agents
- onSubagentEnded: Manages cleanup when sub-agents complete
This architecture means Lossless Claw has full visibility into every stage of the conversation, allowing it to make intelligent decisions about what to keep in active memory versus what to compress.
How Do You Install Lossless Claw in OpenClaw?
Getting Lossless Claw up and running is straightforward, but there are a few prerequisites and steps you need to follow carefully.
Prerequisites
Before installing Lossless Claw, make sure you have:
- OpenClaw 2026.3.7 or later (this version introduced the ContextEngine plugin system)
- Node.js 22 or newer (required for the plugin to run)
- A configured LLM provider (the plugin needs a language model to generate summaries)
Installation Steps
The easiest way to install Lossless Claw is through OpenClaw's built-in plugin installer:
openclaw plugins install @martian-engineering/lossless-claw
This command downloads the plugin from npm, registers it in your OpenClaw configuration, and sets it up as your context engine. In most cases, no manual configuration edits are needed—the installer handles everything automatically.
If you want to install from a local checkout (useful for development or testing), use:
openclaw plugins install --link /path/to/lossless-claw
After installation, restart your OpenClaw gateway to activate the plugin:
openclaw restart
Verifying Installation
You can check that Lossless Claw is properly installed and active using:
openclaw doctor
This command shows your current configuration, including which context engine plugin is active. You should see lossless-claw listed as your active context engine.
What Happens Behind the Scenes
When you install Lossless Claw, OpenClaw updates your configuration file to include the plugin in two places:
- Plugin registration: Adds an entry under
plugins.entriesthat enables the plugin - Slot assignment: Sets
plugins.slots.contextEngineto point tolossless-claw
If you ever want to switch back to OpenClaw's built-in context management, simply change the slot assignment to legacy (or remove it entirely, since legacy is the default).
What's the Difference Between Lossless Claw and Traditional Context Compaction?
Understanding the difference between Lossless Claw and traditional compaction helps you appreciate why this plugin is such a significant improvement.
Traditional Sliding-Window Compaction
OpenClaw's built-in context management (now called LegacyContextEngine) uses a sliding-window approach. Here's how it works:
When your conversation approaches the model's token limit, the system:
- Identifies the oldest messages in the conversation
- Generates a rough summary of those messages
- Replaces the original messages with the summary
- Discards the original messages permanently
The key problem is that last step. Once messages are summarized and discarded, the original details are gone forever. If the summary missed an important detail or didn't capture the nuance of your instructions, there's no way to recover that information.
Additionally, traditional compaction tends to lose:
- Temporal ordering: When events happened relative to each other
- Specific decisions: Exact parameters or choices you specified
- File modification history: Which changes were made when and why
- Context for debugging: The full conversation trail when troubleshooting
Lossless Claw's Approach
Lossless Claw flips this model completely. Instead of discarding anything, it:
- Preserves original messages in a SQLite database forever
- Creates summaries but keeps them linked to their source messages
- Builds hierarchical layers of summaries as the DAG grows deeper
- Provides retrieval tools so agents can access any level of detail
Here's why this matters in practice: imagine you're working on a complex coding project with your AI agent. Over several hours, you make dozens of decisions about architecture, naming conventions, error handling, and specific implementation details.
With traditional compaction, after an hour or two, most of those details would be gone—replaced by vague summaries like "discussed error handling strategy." Your agent might remember that you talked about error handling, but not the specific approach you agreed on.
With Lossless Claw, every detail remains accessible. When the agent needs to recall your error handling decisions, it can use the lcm_grep tool to search for "error handling" in the full conversation history and retrieve the exact discussion with all context intact.
Performance Comparison
The difference shows up in benchmarks. On the OOLONG benchmark (which tests long-context performance), Lossless Claw scored 74.8 compared to Claude Code's 70.3 using the same underlying model. Even more importantly, the performance gap widens as conversations get longer—exactly when you need reliable context management most.
How Do You Configure Lossless Claw for Optimal Performance?
Lossless Claw ships with sensible defaults, but understanding the configuration options helps you tune it for your specific needs.
Key Configuration Parameters
The plugin's behavior is controlled by environment variables that you can set in your OpenClaw configuration or shell environment:
LCM_FRESH_TAIL_COUNT (default: 32) This setting controls how many recent messages are protected from summarization. The "fresh tail" always stays as raw messages in the context window, ensuring your agent has immediate access to the most recent conversation without needing to search through summaries.
If you find your agent forgetting very recent context, increase this number. If you want more aggressive compression to save on token costs, decrease it (but don't go below 16, or you'll lose too much immediate context).
LCM_CONTEXT_THRESHOLD (default: 0.75) This determines when compaction triggers, expressed as a percentage of your model's context window. At 0.75, compaction starts when you've used 75% of available tokens.
Lower values (like 0.6) trigger compression earlier, keeping more headroom but potentially summarizing unnecessarily. Higher values (like 0.85) wait longer, keeping more raw messages but risking hitting the token limit.
LCM_LEAF_CHUNK_TOKENS (default: 20,000) When creating the first level of summaries (leaf nodes in the DAG), this setting controls how many tokens of conversation get grouped together for summarization.
Larger chunks mean fewer summaries but potentially less granular recall. Smaller chunks mean more summaries but better ability to pinpoint specific details.
LCM_LEAF_TARGET_TOKENS (default: 1,200) The target size for each leaf summary. The system asks the LLM to condense each chunk down to approximately this many tokens.
LCM_CONDENSED_TARGET_TOKENS (default: 2,000) When summaries themselves get summarized (creating higher levels in the DAG), this sets the target size for those meta-summaries.
LCM_INCREMENTAL_MAX_DEPTH (default: 0) This controls how many layers deep the DAG can grow:
0: Only create leaf summaries (one layer)1: Allow summaries of summaries (two layers)-1: Unlimited depth (let the DAG grow as deep as needed)
For most use cases, -1 (unlimited) works best, letting the system automatically scale to whatever depth your conversation requires.
Model Selection for Summaries
Lossless Claw needs to call an LLM to generate summaries. By default, it uses whatever model OpenClaw is configured to use, but you can override this with specific environment variables:
LCM_SUMMARY_MODEL=openai/gpt-4
LCM_SUMMARY_PROVIDER=openai
This is useful if you're using a smaller or local model for your main agent but want a more capable model for generating high-quality summaries.
The system follows this priority order for model selection:
- Plugin config
summaryModel - Environment variable
LCM_SUMMARY_MODEL - OpenClaw's compaction model setting
- Active session model
- System default model
Recommended Starting Configuration
If you're setting up Lossless Claw for the first time, start with these values:
LCM_FRESH_TAIL_COUNT=32
LCM_CONTEXT_THRESHOLD=0.75
LCM_INCREMENTAL_MAX_DEPTH=-1
This provides a good balance of immediate context, timely compression, and unlimited depth for long conversations. Monitor your agent's performance over a few sessions, then adjust based on your specific needs.
What Are the Retrieval Tools in Lossless Claw and How Do You Use Them?
One of Lossless Claw's most powerful features is the set of retrieval tools it provides to agents. These tools let your agent actively search and recall information from the compressed conversation history.
lcm_grep: Search Your Conversation History
The lcm_grep tool works like the Unix grep command but for your conversation. Your agent can search through all stored messages and summaries to find specific information.
For example, if you're working with an agent on building a QA checklist assistant and later need to recall specific testing criteria you discussed earlier, the agent can use lcm_grep to search for "testing" or "checklist criteria" in the full history.
The tool returns matches from both raw messages and summaries, so the agent gets a comprehensive view of every time the topic came up in your conversation.
lcm_describe: Understand Summary Nodes
The lcm_describe tool helps agents understand what's in a particular summary node without expanding it fully. This is useful for quickly surveying what information exists without spending tokens on full expansion.
Think of it as reading the chapter titles in a book before deciding which chapter to read in detail. The agent can browse through summary nodes, see what each one covers, and then decide which ones to expand for more information.
lcm_expand: Retrieve Detailed Context
When the agent identifies a relevant summary node using lcm_describe, it can use lcm_expand to retrieve the full content. This drills down from the compressed summary to the underlying raw messages or more detailed sub-summaries.
This is where the DAG structure really shines. The agent can navigate through layers of abstraction, going as deep as needed to find the exact context required for the current task.
lcm_expand_query: Multi-Agent Expansion
This is a wrapper around lcm_expand designed for multi-agent scenarios where one agent needs to expand context on behalf of another.
How Agents Use These Tools
You don't need to manually invoke these tools—your agent learns to use them automatically when needed. When working on tasks that reference earlier parts of the conversation, the agent will naturally:
- Use
lcm_grepto search for relevant keywords - Use
lcm_describeto survey what it found - Use
lcm_expandto retrieve the full details - Incorporate that context into its current work
This creates the experience of working with an agent that genuinely remembers everything, because it effectively does.
When Should You Use Lossless Claw vs Other Context Management Solutions?
Lossless Claw isn't the only option for managing long conversations in AI systems. Understanding when it makes sense helps you choose the right tool for your needs.
Use Lossless Claw When:
You have genuinely long conversations If your typical sessions stretch over hours or involve hundreds of messages, Lossless Claw's benefits become clear. The longer the conversation, the more valuable complete history preservation becomes.
Context loss causes real problems If you've experienced your agent forgetting critical decisions, losing track of file changes, or being unable to reference earlier discussions, Lossless Claw directly solves these issues.
You're working on complex, evolving projects Software development, research, planning, or any task that builds over time benefits from being able to reference any earlier detail.
You want your agent to learn patterns With full conversation history, agents can identify patterns in your preferences, working style, or common requests that would be lost with traditional compaction.
Consider Alternatives When:
You have short, independent sessions If each conversation is brief and self-contained (like quick questions or simple tasks), the overhead of maintaining a full history database might not be worthwhile. Standard compaction works fine for short sessions.
Storage is a concern Lossless Claw stores every message in SQLite databases, which grow over time. If you're extremely storage-constrained (like running on embedded devices), this might be an issue. For most users, storage is cheap enough that this isn't a real concern.
You're using OpenClaw before version 2026.3.7 The ContextEngine plugin system that Lossless Claw requires was introduced in OpenClaw 2026.3.7. If you're on an older version, you'd need to upgrade first.
You need absolute minimum latency Generating summaries and maintaining the DAG adds some computational overhead compared to simple truncation. The difference is typically negligible, but for latency-critical applications, it's worth measuring.
Comparison with Other Approaches
| Approach | Pros | Cons | Best For |
|---|---|---|---|
| Lossless Claw | Complete history preservation, searchable archive, hierarchical summaries, proven performance gains | Requires storage, some computational overhead, needs OpenClaw 2026.3.7+ | Long conversations, complex projects, when context matters |
| Traditional Compaction | Simple, minimal overhead, works everywhere | Loses information permanently, performance degrades over time, can't recover lost context | Short sessions, simple tasks, resource-constrained environments |
| Vector Retrieval | Fast semantic search, works well for factual recall | Requires vector database, doesn't preserve full context, can miss nuance | Knowledge base queries, document search, when semantics matter more than full context |
| Manual Session Management | Complete control, no automatic loss | Requires user intervention, breaks conversation flow, loses agent continuity | When you want explicit session boundaries |
Many users find that combining approaches works best. You might use Lossless Claw for your main agent sessions while using vector retrieval for separate knowledge bases or documentation.
How Does the DAG-Based Summarization System Work in Lossless Claw?
The DAG (directed acyclic graph) is the secret sauce that makes Lossless Claw's approach scalable. Understanding how it works helps you appreciate the elegance of the system.
What is a DAG?
A directed acyclic graph is a data structure made up of nodes connected by one-way arrows (edges), with the constraint that you can never follow the arrows in a loop back to where you started.
In Lossless Claw, each node is either:
- A raw message from your conversation
- A summary of several messages
- A meta-summary of several summaries
The arrows point from summaries to the content they summarize, creating a tree-like structure that can grow arbitrarily deep.
How the DAG Grows
Let's walk through a concrete example. You start a new conversation:
Messages 1-8: These are stored as raw messages in the database. They're recent enough that they stay in your context window without compression.
Messages 9-16: You continue the conversation. Now messages 1-8 are getting old, so Lossless Claw creates a summary node (Summary A) that condenses messages 1-8 into a compact representation.
Messages 17-32: The conversation continues. Now messages 9-16 get summarized into Summary B. Messages 17-32 remain raw.
Messages 33-48: Messages 17-24 become Summary C, messages 25-32 become Summary D. Now you have four summary nodes (A, B, C, D) representing 32 messages.
Here's where it gets clever: those four summaries start to take up space themselves. So Lossless Claw can create a meta-summary (Summary E) that condenses Summaries A and B together. Then another meta-summary (Summary F) that condenses Summaries C and D.
This creates layers:
- Layer 0: Raw messages (most recent)
- Layer 1: Leaf summaries (Summary A, B, C, D)
- Layer 2: Meta-summaries (Summary E, F)
- Layer 3: Meta-meta-summaries... and so on
Why This Scales
The beautiful thing about this structure is that it scales logarithmically. If you have 1,000 messages and each summary condenses 8 messages, you need:
- Layer 1: 125 summaries (1,000 ÷ 8)
- Layer 2: 16 meta-summaries (125 ÷ 8)
- Layer 3: 2 meta-meta-summaries (16 ÷ 8)
A 1,000-message conversation gets represented by about 143 summary nodes total—a huge compression while maintaining perfect fidelity through the links back to raw messages.
Navigating the DAG
When your agent needs to recall something specific, it can efficiently navigate this structure:
- Use
lcm_grepto search across all summaries for keywords - Identify which summary node(s) contain relevant information
- Use
lcm_expandto drill down from high-level summaries to more detailed summaries - Continue expanding until reaching the raw messages
- Read the exact original context
This is much faster than reading through hundreds of raw messages and much more accurate than relying on a single compressed summary that might have lost details.
The Research Foundation
Lossless Claw's approach is based on the LCM paper from Voltropy, which established the theoretical foundations for lossless context management in language models. The implementation proves that these concepts work in practice, delivering measurable performance improvements on real-world benchmarks.
If you're interested in how OpenClaw's event-driven automation works through hooks, understanding the DAG structure gives you insight into how complex state can be managed efficiently over time.
What Are the Common Problems with Lossless Claw and How Do You Troubleshoot Them?
Even well-designed systems have edge cases and potential issues. Here are the most common problems users encounter with Lossless Claw and how to solve them.
Database Growth Over Time
Problem: Your SQLite databases grow large over weeks of conversations, taking up disk space.
Solution: This is expected behavior—Lossless Claw literally never forgets, which means it stores everything. However, you have options:
- Periodically archive old conversation databases that you no longer actively reference
- Use the Go-based TUI tool to inspect databases and selectively remove conversations you don't need
- Accept that storage is relatively cheap; a year of heavy use typically results in databases under a few GB
Most users find that the benefits of complete history far outweigh the minimal storage costs.
Summarization Quality Issues
Problem: Summaries lose important nuance or miss critical details.
Solution: The quality of summaries depends heavily on the model you're using to generate them. If you're seeing poor summaries:
- Check which model is being used:
openclaw doctorshows your configuration - Consider using a more capable model for summarization by setting
LCM_SUMMARY_MODEL - Adjust
LCM_LEAF_TARGET_TOKENSto allow longer, more detailed summaries - Remember that raw messages are always preserved, so agents can always expand to the source if a summary is insufficient
Performance Concerns
Problem: Conversations seem slower or there's noticeable latency.
Solution: Summarization and database operations add some overhead. If performance becomes an issue:
- Increase
LCM_CONTEXT_THRESHOLDto compress less aggressively (reducing summarization frequency) - Ensure your database is on a fast local drive (not a network volume)
- Check that you're not running into rate limits with your LLM provider for summary generation
- Consider using a faster model for summarization even if it's slightly less capable
In practice, most users don't notice performance impacts because the overhead is minimal compared to the benefits.
Compatibility with Older OpenClaw Versions
Problem: Trying to install Lossless Claw on OpenClaw versions before 2026.3.7 fails.
Solution: The ContextEngine plugin system that Lossless Claw requires was introduced in OpenClaw 2026.3.7. You need to upgrade:
# Backup your config first
openclaw config export > backup-config.json
# Upgrade OpenClaw
npm install -g openclaw@latest
# Verify the version
openclaw --version
After upgrading, install Lossless Claw as normal.
Configuration Not Taking Effect
Problem: You've set environment variables for Lossless Claw but the behavior hasn't changed.
Solution: Environment variables need to be set before OpenClaw starts. If you're setting them in your shell but running OpenClaw as a service, the service won't see them. Instead:
- Set them in your OpenClaw configuration file under the plugin's config section
- Or set them system-wide in your shell profile and restart the OpenClaw service
- Verify settings took effect with:
openclaw doctor
Agent Not Using Retrieval Tools
Problem: Your agent doesn't seem to be using lcm_grep or lcm_expand even when context would help.
Solution: The agent's use of retrieval tools depends on the underlying model's capabilities and training. Some models are better at tool use than others. Try:
- Using a more capable model (like Claude Opus or GPT-4) that has strong tool-use capabilities
- Explicitly mentioning in your instructions that the agent should search history when needed
- Checking that the tools are actually available: they should appear in the agent's tool list
Most modern capable models will naturally learn to use these tools effectively within a few turns.
FAQ
Is Lossless Claw free and open source?
Yes, Lossless Claw is open source software released under the MIT license. You can view the source code on GitHub, contribute to development, or fork it for your own needs. It's completely free to use.
Does Lossless Claw work with any language model?
Lossless Claw works with any LLM that OpenClaw supports. However, the summarization quality depends on the model you choose for summary generation. More capable models (like GPT-4, Claude Opus, or similar) generally produce better summaries, but you can use smaller or local models too.
How much storage does Lossless Claw require?
Storage requirements depend on how much you use it, but they're generally modest. A typical conversation might be a few hundred KB to a few MB. Even power users with hundreds of hours of conversations rarely exceed a few GB of total storage. For reference, a single HD photo is often larger than an entire conversation database.
Can I use Lossless Claw with multiple OpenClaw agents?
Yes, Lossless Claw is configured at the OpenClaw level, so it works with all agents running through that OpenClaw instance. Each conversation gets its own database entry, so different agents or different sessions remain isolated from each other.
What happens if I switch back to traditional compaction?
If you switch your context engine back to legacy, OpenClaw will revert to traditional sliding-window compaction. Your existing Lossless Claw databases remain intact, so you can switch back anytime without losing data. However, new conversations won't benefit from lossless management unless you re-enable the plugin.
Does Lossless Claw send my conversation data anywhere?
No. All conversation data stays local in SQLite databases on your machine. The only external calls are to your configured LLM provider when generating summaries, and those calls only contain the content being summarized (just like any other LLM interaction). Lossless Claw doesn't send data to any third-party service.
Conclusion
Lossless Claw represents a fundamental shift in how AI agents handle long conversations. By preserving complete history while maintaining performance through intelligent hierarchical summarization, it eliminates the context loss problem that has plagued AI systems since their inception.
For anyone working on extended projects, complex tasks, or simply wanting an AI assistant that genuinely remembers everything you've discussed, Lossless Claw is worth trying. The installation is straightforward, the defaults work well for most users, and the performance benefits show up immediately in longer sessions.
The open source nature means you can inspect exactly how it works, contribute improvements, or adapt it to your specific needs. And with active development from Martian Engineering and the broader community, it continues to improve over time.
If you're tired of your AI agent forgetting important context, give Lossless Claw a try. The difference between working with an agent that remembers everything versus one that constantly loses track is remarkable—and once you experience it, it's hard to go back.