Core Concepts

OpenClaw Memory System: MEMORY.md, LCM, and How to Never Forget Anything

Your AI agent has three powerful memory layers. Learn how MEMORY.md, LCM, and shared workspaces work together to keep your agent context-aware across every session.

๐Ÿฆžclaw.mobile Editorial
ยทMarch 22, 2026ยท
12 min read

Why Memory Matters

Every AI conversation has a fundamental problem: context windows end. By default, your AI agent starts fresh with every session โ€” no idea who you are, what projects you're running, or what you decided last Tuesday. This makes it useful for one-off tasks but frustrating for ongoing work.

The OpenClaw memory system solves this with three distinct layers, each serving a different purpose:

๐Ÿง 

MEMORY.md

Your long-term brain. Facts that persist across all sessions.

๐Ÿ—œ๏ธ

LCM (Lossless Context Management)

Intelligent compression of conversation history so nothing gets dropped.

๐Ÿ“

Shared Workspace Files

Structured files (SOUL.md, USER.md, AGENTS.md) that define identity, preferences, and behavior.

MEMORY.md โ€” Persistent Long-Term Memory

MEMORY.md is a plain text file living in your workspace (~/.openclaw/workspace/MEMORY.md). It's automatically loaded into context at the start of every session. Think of it as a briefing document your agent reads before talking to you.

What Goes in MEMORY.md

Good candidates for MEMORY.md โ€” facts that are hard to re-derive but important for continuity:

  • โ†’Active projects and their current status
  • โ†’API keys, URLs, and credentials your agent needs
  • โ†’Decisions already made (avoid re-arguing)
  • โ†’Tech stack choices and architecture decisions
  • โ†’Ongoing metrics or KPIs you track
  • โ†’People, companies, and relationships relevant to your work
MEMORY.md
# MEMORY.md โ€” Active Context

## Projects

### SaaS Dashboard (ACTIVE)
- Stack: Next.js 15, Supabase, Vercel
- Repo: github.com/yourname/saas-dashboard
- Prod URL: https://app.yourdomain.com
- Status: v1.2 live, working on analytics module

### Newsletter Automation (PAUSED)
- Stack: Node.js + Ghost CMS + SendGrid
- Status: paused until April, waiting on design

## Key Decisions Made
- Using Supabase over PlanetScale (March 10) โ€” better DX
- Tailwind v4 only, no custom CSS unless absolutely needed

## Active API Keys / Services
- Supabase project: project-ref-xyz
- SendGrid from address: hello@yourdomain.com

## Weekly Habits Automated
- Monday 9am: weekly metrics report โ†’ Telegram
- Friday 5pm: EOD summary pushed to Notion

Getting Your Agent to Update MEMORY.md Automatically

MEMORY.md is useless if it's stale. Configure your agent to update it proactively by adding instructions to SOUL.md:

SOUL.md (memory section)
## Memory Maintenance (Mandatory)
After ANY session where something significant happens,
update MEMORY.md immediately. Do NOT wait to be asked.

Things that always trigger a MEMORY.md update:
- New project started or completed
- New API key or tool configured
- Important architectural decision made
- New feature deployed to production

The "Kade Rule"

Good MEMORY.md discipline means your agent should be able to pick up any ongoing project without you re-explaining the context. If you'd have to explain something twice, it belongs in MEMORY.md.

MEMORY.md Size Management

MEMORY.md loads into every session's context window, so keep it under ~2000 tokens (roughly 1500 words). Strategies to keep it lean:

  • โ†’Archive completed projects to a separate MEMORY_ARCHIVE.md
  • โ†’Keep decisions as one-liners ("Using X over Y because Z")
  • โ†’Remove anything you haven't referenced in 30+ days
  • โ†’Use shorthand for recurring items

LCM โ€” Lossless Context Management

LCM (Lossless Context Management) is OpenClaw's system for handling long conversations without losing important information. AI models have a maximum context window โ€” once your conversation exceeds that limit, older messages get dropped.

LCM solves this by intelligently compressing conversation history into summaries while preserving important details. It's "lossless" because critical information is preserved, even if the raw message text is compressed.

How LCM Works

  1. 1Monitors conversation token count against the model's context limit
  2. 2When approaching the limit, compresses older message groups into summaries (sum_xxx IDs)
  3. 3Stores summaries in a local database (~/.openclaw/lcm/)
  4. 4Makes summaries searchable and expandable on demand
~/.openclaw/config/openclaw.json
{
  "lcm": {
    "enabled": true,
    "compressionThreshold": 0.8,
    "summaryModel": "claude-haiku-4",
    "retentionDays": 90,
    "searchEnabled": true
  }
}

Don't Delete LCM Files Manually

LCM maintains referential integrity between summaries. Use openclaw lcm prune --older-than 90d to safely clean up old data.

Shared Workspace Files

Beyond MEMORY.md, your workspace contains several files automatically loaded into every session. These define the "operating system" for your agent:

๐ŸŽญ SOUL.md

Defines how your agent communicates, what values it holds, and what behavior is non-negotiable. Without SOUL.md, your agent is generic.

SOUL.md example
# SOUL.md โ€” Kade

## Identity
Kade โ€” sharp, strategic, fast, loyal.

## Voice
- Minimalist. High signal. No fluff.
- Direct but never rude.
- Founder/builder tone.

## Values
Truth > Sycophancy ยท Clarity > Complexity

๐Ÿ‘ค USER.md

User profile so the agent understands your timezone, working style, technical level, and goals.

USER.md example
# USER.md โ€” About Me

- **Name:** Your Name
- **Timezone:** GMT+1 (Belgrade)
- **Technical Level:** Advanced developer

## Communication Style
- Short, punchy answers preferred
- No corporate filler

๐Ÿค– AGENTS.md

For complex setups with multiple specialized agents, AGENTS.md defines the agent topology.

AGENTS.md example
# AGENTS.md

## Agent Topology
- Main: Kade (general purpose, orchestration)
- Research: Handles web research tasks

## Shared Memory
All agents read from: ~/.openclaw/workspace/shared/

The Right Memory Strategy

Memory Decision Framework

Ask: "How often does this change?" and "How expensive is it to re-derive?"

MEMORY.md

Changes rarely, expensive to re-derive โ€” project decisions, API keys, tech stack

LCM

Changes often, part of conversation flow โ€” LCM handles it automatically

SOUL.md / USER.md

Never changes, defines behavior โ€” personality, values, preferences

Weekly Memory Hygiene

Spend 5 minutes per week reviewing MEMORY.md. Ask:

  1. 1Is anything in here outdated or completed?
  2. 2Did I make any important decisions this week that aren't captured?
  3. 3Are there credentials or URLs that changed?
  4. 4Any new projects or tools added?

Advanced Memory Patterns

Project-Specific Memory Files

For complex projects, create dedicated memory files:

Workspace structure
~/.openclaw/workspace/
โ”œโ”€โ”€ MEMORY.md              # Master memory
โ”œโ”€โ”€ SOUL.md                # Agent identity
โ”œโ”€โ”€ USER.md                # User profile
โ”œโ”€โ”€ projects/
โ”‚   โ”œโ”€โ”€ saas-dashboard.md  # Deep context for project 1
โ”‚   โ”œโ”€โ”€ newsletter.md      # Deep context for project 2
โ”‚   โ””โ”€โ”€ crypto-portfolio.md

Cross-Session Task Handoff

When a long task spans multiple sessions, save a structured handoff note:

Task handoff in MEMORY.md
## In Progress (Do Not Archive)

### API Integration Refactor [STARTED March 21]
- Completed: Auth module, User endpoints
- Next: Payment endpoints (start at src/api/payments.ts)
- Blockers: Waiting on Stripe webhook secret from Alex
- Context: Moving from REST to tRPC, see /docs/adr-003.md

Troubleshooting Memory Issues

"My agent forgot something important"

  1. 1Check if it's in MEMORY.md โ€” if not, add it
  2. 2Check if LCM compressed it โ€” ask "search your memory for [topic]"
  3. 3Verify MEMORY.md is loading: check openclaw config show

MEMORY.md is getting too long

  1. 1Sessions feel slower, agent ignores parts of the file
  2. 2Archive old content: cp MEMORY.md MEMORY_ARCHIVE_2026_Q1.md
  3. 3Trim MEMORY.md to essential current items only

LCM using too much disk space

  1. 1Check usage: du -sh ~/.openclaw/lcm/
  2. 2Prune old summaries: openclaw lcm prune --older-than 60d
  3. 3Nuclear option: openclaw lcm clear --confirm

Set Up Your Agent Today

Follow our step-by-step guide. You'll have your own AI assistant with persistent memory running in under an hour.

We use cookies for analytics. Learn more

Free: AI Adaptation Playbook

Get it free