> For the complete documentation index, see [llms.txt](https://www.openclawbook.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.openclawbook.xyz/en/ch10-advanced-techniques/10.1-memory-and-knowledge-management.md). Agents can also search and read this documentation through its [MCP server](https://www.openclawbook.xyz/~gitbook/mcp).

# 10.1 Memory and Knowledge Management

> **Generated by**: Claude Opus 5 (claude-opus-5\[1m]) **Token usage**: Input \~174,000 tokens, Output \~9,000 tokens (this section) **Source baseline**: `v2026.3.9` (`v2026.3.8-170-g665f67726`)

***

## 10.1.1 How Memory Actually Works

Memory in OpenClaw is **Markdown files in your workspace**. Not a vector store, not a database — files (§28.5.1).

```
<workspace>/
  MEMORY.md              ← curated long-term memory, injected at session start
  memory/
    2026-08-01.md        ← one file per day, appended to as things happen
    2026-08-02.md
```

The SQLite index is a **derivable cache**, not the source of truth. Delete it and it rebuilds from the files.

**This choice is the most consequential design decision in the memory system** (§44.2). Because the source of truth is files:

* you can `git log` your agent's memory and see how it changed;
* you can fix a bad memory in an editor;
* a corrupted index is a non-event — `openclaw memory reindex` and it's gone;
* migrating machines is `rsync`.

Compare a vector-store-first design where the embeddings *are* the memory: you can't read it, can't diff it, can't fix it, and corruption is data loss.

### Reading it directly

```bash
cat ~/openclaw-workspace/MEMORY.md
ls ~/openclaw-workspace/memory/
git -C ~/openclaw-workspace log --oneline -- MEMORY.md
```

**Putting the workspace under git is the single highest-value thing you can do here.** Personality, memory, and skills all become versioned, and a bad edit is `git checkout` away from fixed.

## 10.1.2 Writing Good Memories

The agent decides what to remember, but you can direct it:

```
Remember that I prefer TypeScript over Python for new projects
```

```
Remember: the staging deploy script is at ops/deploy-staging.sh and needs the
VPN connected
```

### What's worth remembering

| Worth it                                                   | Not worth it                           |
| ---------------------------------------------------------- | -------------------------------------- |
| Stable preferences                                         | Anything that changes weekly           |
| Non-obvious project facts (why something is the way it is) | What's already in the code             |
| Recurring pitfalls                                         | One-off details from this conversation |
| Names, relationships, context you'd otherwise re-explain   | Conversation transcripts               |

**The last "not worth it" row matters most.** `MEMORY.md` is injected into every session (§28.5.2), so every line costs tokens on every request, forever. A bloated `MEMORY.md` is a permanent tax.

### Curation

```
Review MEMORY.md and remove anything stale or redundant
```

Worth doing occasionally. Or just edit the file — it's Markdown.

### What subagents see

**Subagents don't get `MEMORY.md`** (§9.2.1). If you're delegating work that needs context, put it in the task description.

## 10.1.3 Search and Retrieval

Two tools, and the distinction matters:

| Tool            | What it does                             |
| --------------- | ---------------------------------------- |
| `memory_search` | Finds relevant memory entries            |
| `memory_get`    | Retrieves a specific entry by identifier |

Search-then-get is the normal pattern: search returns candidates cheaply, get pulls the full content of the one that matters. Loading everything found would defeat the point.

### Using it

```
What did I decide about the auth refactor?
```

The agent searches memory and answers. You don't invoke the tools directly.

### Configuring the index

```json5
{
  memory: {
    enabled: true,
    index: {
      enabled: true,
      embeddings: false,       // keyword search only — no embedding API calls
    },
  },
}
```

**Turn embeddings off unless you have a lot of memory and semantic search is genuinely helping.** Every indexed chunk costs an embedding call, and for the amount of memory a personal agent accumulates, keyword search usually finds it.

### Maintenance

```bash
openclaw memory reindex        # rebuild the index from the files
openclaw memory status         # index health
```

Reindex is always safe — that's the point of files being the source of truth.

## 10.1.4 Workspace Knowledge Files

Beyond memory, three files shape the agent, all Markdown in the workspace:

| File        | Role                                                     |
| ----------- | -------------------------------------------------------- |
| `SOUL.md`   | Personality and voice                                    |
| `AGENTS.md` | Operating instructions — how to work, what to prioritize |
| `MEMORY.md` | Long-term facts                                          |

### `AGENTS.md` is worth investing in

This is where you encode how you want the agent to work:

```markdown
# Operating Instructions

## Style
- Answer directly. No preamble.
- When showing code, show the code, not a description of it.

## Tools
- Prefer ripgrep over find.
- Always read a file before editing it.

## This project
- Tests are `npm test`. Run them before saying something works.
- Never commit to main.
```

OpenClaw's own repository does exactly this at scale (§43.3) — its `AGENTS.md` encodes conventions that would otherwise be re-explained every session. The pattern transfers directly to your own projects.

### `SOUL.md` and the trust position

`SOUL.md` is loaded as **trusted bootstrap content**, at the same level as the system prompt. Anything in it can shape behavior without restriction.

That's fine — it's your file. But it means: **treat `SOUL.md` as code, not content** (§32.5.2). Don't paste one you found online without reading it, and don't let a tool write to it unreviewed.

> **There's history here.** A bundled hook that injected extra bootstrap files was removed in `v2026.2.12` as a security fix (§32.5.1), precisely because anything reaching the bootstrap layer inherits full trust. The lesson generalizes: **audit every path that can write to a trusted file**, because the trust is in the position, not the content.

***

## Section Summary

1. **Memory is Markdown files; the SQLite index is a derivable cache** — delete it and it rebuilds. This makes memory readable, diffable, editable, and `rsync`-migratable.
2. **Put the workspace under git** — the single highest-value action here; personality, memory, and skills become versioned, and a bad edit is one `git checkout` from fixed.
3. **`MEMORY.md` is injected into every session, so every line is a permanent per-request token tax** — remember stable preferences and non-obvious facts, not transcripts or things already in the code.
4. **Subagents don't receive `MEMORY.md`** — delegated work needs its context in the task description.
5. **Search-then-get is the retrieval pattern**: `memory_search` returns candidates cheaply, `memory_get` pulls the one that matters.
6. **Leave embeddings off unless semantic search is genuinely helping** — keyword search usually finds what a personal agent accumulates, at no API cost.
7. **`AGENTS.md` is worth investing in** — OpenClaw's own repo does this at scale, encoding conventions that would otherwise be re-explained every session.
8. **Treat `SOUL.md` as code, not content** — it's loaded as trusted bootstrap, and a bundled hook that wrote to that layer was removed as a security fix. **Audit every path that can write to a trusted file; the trust is in the position, not the content.**
