M
MeshWorld.
OpenClaw Privacy Memory Self-Hosted AI Data Ownership Tutorial 8 min read

How OpenClaw Memory Works (And Why Your Data Never Leaves Your Machine)

By Vishnu Damwala

Six months after setting up my OpenClaw agent, I asked it a question on a whim:

“What did I tell you about the Henderson project?”

It knew. Not a vague recollection — it pulled specific details I’d mentioned in passing during a Telegram conversation in September. The project name, the client’s concern about the timeline, the workaround we’d discussed.

I hadn’t asked it to remember that. It just did. And when I went looking, I found a Markdown file on my hard drive with the exact context it had used.

That’s OpenClaw’s memory system. Let’s look at how it actually works.


The Fundamental Difference

Before diving in, it’s worth understanding what makes OpenClaw’s approach different.

ChatGPT Memory stores your preferences and past conversations on OpenAI’s servers. You can view and delete them, but the data is under their control and subject to their retention policies.

Claude Projects stores your documents and context on Anthropic’s servers. Same situation.

OpenClaw memory stores everything in Markdown files in a directory on your machine. The files exist where you can see them, edit them, back them up, search them, and delete them. When OpenClaw is off, the files just sit there like any other text files — because that’s what they are.

No sync. No cloud backup. No third-party access. The tradeoff: if your machine dies and you haven’t backed up, the memory is gone. More on that shortly.


The Directory Structure

Every OpenClaw agent has its own memory directory:

~/.openclaw/agents/yourname/
  ├── config.yaml           ← agent config
  ├── memory/               ← everything the agent remembers
  │   ├── preferences.md
  │   ├── 2026-01-15-project-notes.md
  │   ├── 2026-02-03-meeting-summary.md
  │   └── 2026-03-12-morning-digest.md
  ├── prompts/
  │   └── system.md
  └── logs/

Open any of these files in your text editor. They’re plain Markdown — readable without any special tool.


What Gets Stored and When

OpenClaw writes to memory in three situations:

1. Explicit Instructions

You tell the agent to remember something:

“Remember that I prefer bullet points over long paragraphs.”

The agent writes this to preferences.md (or creates a new file if appropriate). Next conversation, it reads that file and applies the preference.

2. Heartbeat Task Output

When your agent runs a scheduled task, it saves its output to memory. This is how the morning digest works — after summarizing your overnight messages, the agent writes the summary to a date-stamped file:

2026-03-12-morning-digest.md

You can read this file any time. Your agent can reference it in later conversations.

3. Agent Judgment

During longer conversations, the agent may write notes to memory unprompted — things it decides are worth keeping. Meeting details, project context, user preferences it inferred.

Whether this happens depends on your system prompt. If your system prompt says “maintain context across sessions,” the agent will be more aggressive about writing to memory. If you want a clean-slate agent that doesn’t accumulate context, omit memory instructions from your system prompt.


Reading a Real Memory File

Here’s what a typical preferences.md looks like after a few weeks of use:

# User Preferences

## Communication Style
- Prefers bullet points over long paragraphs
- Doesn't want filler phrases ("Great question!", "Certainly!")
- Wants direct answers first, explanation second

## Schedule
- In meetings most mornings 9am-11am
- Doesn't want non-urgent pings during that window
- Checks messages more reliably after 2pm

## Active Projects
- Henderson account: timeline concerns, check in weekly
- New site redesign: using Astro v5, launching Q2
- Running experiment with DeepSeek R1 for code tasks

## Things to Remember
- Prefers dark roast coffee (mentioned during setup)
- Time zone: IST (UTC+5:30)

The agent didn’t ask you to fill this in. It built it up from your conversations. And because it’s a plain text file, you can edit it directly — add context the agent missed, remove things that are no longer true, restructure it however you like.


Editing Memory Manually

This is something most people don’t realize they can do.

Say your agent has outdated context in its memory files — it still thinks you’re working on a project you wrapped up three months ago. Open the file, delete the outdated section, save. Done. The agent will read the updated file next time.

You can also seed your agent’s memory before it learns anything organically. Create a preferences.md yourself with your preferences, schedule, and current projects. The agent will read it on startup and behave accordingly from day one.

nano ~/.openclaw/agents/myagent/memory/preferences.md

Write in plain Markdown. The agent will incorporate whatever you write.


Shared Memory Between Agents

When you run multiple agents, you can point them at a shared memory directory:

# In agent's config.yaml
memory:
  enabled: true
  directory: ./memory
  shared:
    - path: ~/.openclaw/shared/context
      access: read         # this agent reads but doesn't write

This is how multi-agent pipelines pass context — Agent A writes a brief to the shared directory, Agent B reads it when it wakes up. The files are the same plain Markdown. There’s no message queue or database involved.


Backup and Restore (v2026.3.8)

Before v2026.3.8, backing up your memory meant cp -r ~/.openclaw/agents/myagent/memory/ ~/backup/. That still works. But v2026.3.8 adds proper backup tooling:

Creating a Backup

openclaw backup create --agent myagent

This creates a compressed, timestamped archive of your entire agent directory — config, memory, prompts, and logs:

~/.openclaw/backups/myagent-2026-03-12-143022.tar.gz

To back up all agents at once:

openclaw backup create --all

Verifying a Backup

openclaw backup verify --file ~/.openclaw/backups/myagent-2026-03-12-143022.tar.gz

This checks the archive integrity and confirms all expected files are present. Run this after creating a backup to confirm it’s not corrupted before you need it.

Restoring

openclaw backup restore --file ~/.openclaw/backups/myagent-2026-03-12-143022.tar.gz

The restore command extracts to the agent directory, preserving the original structure. If the directory already exists, it will ask before overwriting.


A Practical Backup Routine

A few patterns that work well:

Before upgrading OpenClaw:

openclaw backup create --all
openclaw backup verify --file ~/.openclaw/backups/myagent-2026-03-12-*.tar.gz
npm update -g openclaw

Upgrade, confirm it works, then you have a rollback point if something breaks.

Weekly automated backup via cron:

# crontab -e
0 3 * * 0   openclaw backup create --all   # every Sunday at 3am

Migrating to a new machine:

# On old machine
openclaw backup create --all
scp ~/.openclaw/backups/*.tar.gz newmachine:~/

# On new machine
npm install -g openclaw
openclaw backup restore --file ~/myagent-2026-03-12-143022.tar.gz

Your agent wakes up on the new machine with full memory intact.


What Happens When You Delete Memory Files

If you delete a memory file, the agent loses whatever was in it. The next conversation starts without that context.

This is sometimes intentional. Maybe you want a fresh start with a particular agent. Maybe the memory files have accumulated so much stale context that the agent is confused. Deleting and starting clean is a valid option.

For a complete reset:

rm -rf ~/.openclaw/agents/myagent/memory/
mkdir ~/.openclaw/agents/myagent/memory/

The agent restarts with empty memory. It will begin accumulating context again from your next conversation.


What the LLM Provider Sees

There’s one privacy point worth being precise about.

When your agent processes a message, it sends your message text (plus relevant memory context) to the LLM API — Claude, GPT-4o, whatever you’ve configured. The LLM provider sees:

  • Your message
  • The memory context the agent included in the prompt
  • The conversation history the agent included

What the LLM provider does not see:

  • Your raw memory files (only excerpts the agent chose to include)
  • Your agent config (API keys, messaging tokens)
  • Your conversation history that wasn’t included in the current context window

This is the same situation as using Claude directly — Anthropic sees what you send in API calls. The difference with OpenClaw is that you control what gets sent. Your memory files stay on your machine. Only what the agent actively pulls into a prompt goes over the wire.

If you have memory files containing highly sensitive data and you don’t want that data sent to any LLM, you can configure memory selectively:

memory:
  enabled: true
  directory: ./memory
  excludeFromContext:
    - "financial-records.md"
    - "credentials.md"

The agent can still write to and read these files manually, but won’t automatically include them in LLM prompts.


What’s Next

Start from the beginning: How to Install OpenClaw on Ubuntu, macOS, and Windows

Build your first agent: OpenClaw Tutorial: Build Your First AI Agent in 15 Minutes

See how OpenClaw compares to other AI tools: OpenClaw vs ChatGPT vs Claude: Which AI Setup Is Right for You?