# Write strategy comparison

Mechanisms: [Memory subsystem illustrated](https://fzkuji.github.io/OpenProgram/docs/reference/design/memory/architecture.html). Authoritative text: [Overview](https://fzkuji.github.io/OpenProgram/docs/reference/design/memory/overview.html). Missing features stay listed, because not building one is a choice.

**Where the claims come from**

| Framework | Source |
| --- | --- |
| claude-code | [Public documentation](https://code.claude.com/docs/en/memory); what it leaves unsaid reads Undocumented |
| Other third parties | Code snapshots in `references/`, with recorded lines |
| codex-cli | Its snapshot is an internal build larger than the public version, so some capabilities are absent from public releases |

## Where our design fits

| Dimension | OpenProgram | Same as | Differs |
| --- | --- | --- | --- |
| Storage | Files only | claude-code | openclaw adds an index, hermes external services |
| Who writes | An agent outside the conversation | codex, openclaw | hermes relies on the main model remembering |
| What is written | Originals and distilled facts | claude-code, codex, pi-mono | Only ours footnotes each statement to its source |
| Retrieval | BM25 by default | hermes, codex | — |
| Resident block | `topics/core.md` rendered into `MEMORY.md` within 2000 tokens | Separates canonical content from budget, as claude-code, codex, openclaw | Deletes nothing |
| Nightly organization | Yes | codex, openclaw | Writing without organizing grows without end |
| Session structure | DAG inside one session | pi-mono | The others are linear or fork into new files |
| Cursor | A workspace marker on each node | None | Follows from the session structure, see [Branches](#branch) |

Marker placement, fork traversal and recovery: [Written marker](https://fzkuji.github.io/OpenProgram/docs/reference/design/memory/written-marker.html), with diagrams in [architecture section 04](https://fzkuji.github.io/OpenProgram/docs/reference/design/memory/architecture.html).

## Is there long-term memory

| Framework | Memory | Form |
| --- | --- | --- |
| claude-code | Yes | Files only: `MEMORY.md` index, topic files |
| codex-cli | Yes, off by default | `~/.codex/memories/`: `MEMORY.md`, summary pages, skill directory, session summaries; SQLite only schedules two-stage distillation |
| openclaw | Yes | `MEMORY.md` is canonical; SQLite is a rebuildable index of vector nearest neighbours and full-text ranking |
| hermes-agent | Yes | `MEMORY.md` and `USER.md`; eight optional hosted services, one at a time |
| OpenProgram | Yes | Markdown workspace: `topics/` and `MEMORY.md`; footnotes link chat messages |
| opencode | No | User-written `AGENTS.md` or `CLAUDE.md`; no memory tool |
| pi-mono | No | JSONL session tree for replay and branching; only `AGENTS.md` crosses sessions |
| pi-ai | No | Provider SDK, 12 files, no session concept; the caller owns the message array |
| weclaw | No | WeChat bridge storing an opaque session id; the launched process owns memory |

Classify by whether content returns to context. weclaw saves pasted URLs as Markdown, but no prompt reads them back. codex, opencode and pi-mono keep full transcripts that nobody distills or reads across sessions: storing originals is not memory.

**Verified locations**

| Framework | Location |
| --- | --- |
| codex-cli | `memories/write/src/lib.rs:116-118` `state/memory_migrations/0001_memories.sql:1-35` Default off: `features/src/lib.rs:996-999` |
| openclaw | `src/memory/root-memory-files.ts:4,8` `extensions/memory-core/src/memory/manager-db.ts:10` `.../manager-search.ts:148` |
| opencode | `packages/opencode/src/session/instruction.ts:60-68` Entire tool/ directory listed |
| hermes-agent | `tools/memory_tool.py:56-60,138-173` `agent/memory_manager.py:258-280` |
| pi-ai | No repository-wide grep matches; only OAuth credentials persist |
| pi-mono | `packages/coding-agent/src/core/session-manager.ts:428-436` |
| weclaw | `agent/cli_agent.go:25,226-231` |
| OpenProgram | `openprogram/state/memory/store.py` |

## When writes happen

| Framework | Timing |
| --- | --- |
| claude-code | Claude writes during the session; when is undocumented |
| codex-cli | Fire-and-forget task at turn start; exits on low quota, handles only sessions idle over six hours, deduplicated by a database lease that records the watermark on completion |
| openclaw | Cron, default daily 03:00; short-term entries promoted by six weighted criteria; no in-session writes |
| hermes-agent | The model calls a tool whenever it chooses; a background agent reminds it every ten turns |
| OpenProgram | Checked each turn; writes at 16k tokens (8k, 16k or 32k by setting), writes the rest after 30 idle minutes, reorganizes at 03:00 |
| pi-mono | No memory writes; original events persist synchronously |
| opencode, pi-ai, weclaw | No writes |

Three of four writers work outside the conversation, because memory edits add a call and distract the model from the task.

**Verified locations**

| Framework | Location |
| --- | --- |
| codex-cli | `app-server/src/request_processors/turn_processor.rs:578-591` `memories/write/src/start.rs:23-81` `memories/write/src/phase1.rs:149-187` |
| openclaw | `src/memory-host-sdk/dreaming.ts:17,36-39` `extensions/memory-core/src/dreaming.ts:163-187` |
| opencode | No memory tools under tool/ |
| hermes-agent | `tools/memory_tool.py:619-686` `agent/conversation_loop.py:429-439` `agent/background_review.py:34-43` |
| pi-mono | `packages/coding-agent/src/core/agent-session.ts:515` |
| OpenProgram | `openprogram/state/memory/local_backend.py` `openprogram/state/memory/session_watcher.py` `openprogram/state/memory/scheduler.py` |

## What is written

| Stored | Who | Effect |
| --- | --- | --- |
| Originals only | opencode, weclaw | Kept to resume a conversation. In a new one they are effectively absent. |
| Distilled facts only | hermes-agent | Small and fast. Tool text says: "Do not store logs; search past sessions for those." A wrong fact has no source to check. |
| Both | claude-code, codex-cli, pi-mono, OpenProgram | Originals are append-only, facts may be rewritten. Only ours footnotes each statement to `/s/<session>#<msg>`. |

codex distills twice: per-session into raw memories and a summary, then an agent without network or approval prompts rewrites `MEMORY.md`, summary pages and skill directories from those and a workspace diff. Writing and organizing are separate roles, like ours, but split by pipeline stage rather than time.

## How unwritten content is identified

| Framework | Form | Stored in |
| --- | --- | --- |
| hermes-agent | None; the model writes when it chooses. Persistence uses an integer index, compaction scans body markers. | — |
| weclaw, pi-ai | None; weclaw has only a hard message-count cutoff | — |
| codex-cli | Integer timestamp watermark per session file | SQLite task table with lease and retry count |
| claude-code | Undocumented | — |
| pi-mono | One entry id, `firstKeptEntryId`, scan backward | Compaction records in the transcript |
| opencode | Message-level `summary: true` and a `tail_start_id` | On the messages |
| openclaw | Entry `promotedAt` timestamp plus an HTML deduplication comment, cross-checking | On entries and in the `MEMORY.md` body |
| OpenProgram | Workspace marker `memory_written_scriptorium` on each node; inspect back from the branch tip to the first marked node | Session node metadata |

**Verified locations**

| Framework | Location |
| --- | --- |
| codex-cli | `state/memory_migrations/0001_memories.sql:3,7,17-31` `memories/write/src/phase1.rs:149-187` |
| openclaw | `extensions/memory-core/src/short-term-promotion.ts:84,1602-1612,1666-1669,1737` |
| opencode | `packages/opencode/src/session/message-v2.ts:535-586` `.../compaction.ts:386,437-442` |
| hermes-agent | `agent/agent_init.py:1026` `agent/context_compressor.py:37-51,1215-1226` |
| pi-mono | `packages/coding-agent/src/core/session-manager.ts:67-77,315-422` |
| weclaw | `agent/http_agent.go:151-154` |
| OpenProgram | `openprogram/state/memory/writing.py` |

## Branches and restarts

1. **Shared prefix** m1 m2 m3, one session id
2. **Main branch, written** m4 m5 m6
3. **New branch from m3, pending** b4 b5 b6

| Cursor on that DAG | Result for the new branch |
| --- | --- |
| Position: written through 6 | b4, b5, b6 have indices 4, 5, 6 and are skipped |
| One id: written through m6 | m6 never appears on this branch |
| Per-node marker | b4, b5, b6 are unmarked: pending. m1 to m3 carry markers, so inspection stops there. |

### Session structure

| Framework | Branching | Implementation |
| --- | --- | --- |
| claude-code | Yes, most complete | `/branch` copies the session; `/rewind` rewinds conversation, files or both; subagents write separate files |
| codex-cli | Yes | `codex fork` and TUI edits of earlier prompts create threads, source unchanged |
| openclaw | Subagents only | Dispatch can inherit the parent transcript or start clean; no old-message edit found |
| opencode | Copy; rewind deletes | `fork` deep-copies. `revert` sets a marker, and the next prompt permanently deletes later messages, so editing an old message is irreversible unless forked first. |
| hermes-agent | Yes | `/branch` copies into a session linked by parent id; compaction also makes child sessions, and `/resume` follows the chain to the latest |
| pi-mono | Trees | Editing an old message creates a sibling branch; leaving one can keep a generated summary |
| OpenProgram | DAGs | Reasking, retrying and spawning agents branch from intermediate points; branches under one session id share prefixes |
| weclaw | No | One session per WeChat contact; `/new` deletes the old one |
| pi-ai | No sessions | — |

**Verified locations**

| Framework | Location |
| --- | --- |
| codex-cli | `thread-store/src/types.rs:183-190` `tui/src/app_backtrack.rs:7-8` `rollout/src/recorder.rs:97-98` |
| openclaw | `src/agents/tools/sessions-spawn-tool.ts:190,307,343-344` Message editing: no grep matches |
| opencode | `packages/opencode/src/session/session.ts:733-774` `.../revert.ts:100-134` `.../prompt.ts:1155-1159` |
| hermes-agent | `cli.py:6682-6809` `agent/conversation_compression.py:381-397` `hermes_state.py:1851-1869` |
| pi-mono | `packages/agent/src/harness/agent-harness.ts:788-812` `.../branch-summarization.ts:200-262` |
| weclaw | `messaging/handler.go:340-345` |
| OpenProgram | `openprogram/state/store/session/session_store/branches.py` |

### The cursor after a fork

| Framework | Cursor scope after a fork | Prefix extracted again |
| --- | --- | --- |
| codex-cli | New `thread_id`, the cursor table's primary key | Yes, all of it; only Phase 2 consolidation merges semantically |
| claude-code | Undocumented | — |
| openclaw | New session, flush markers cleared on purpose | Yes; comments prefer repetition to omission from equal hashes |
| opencode | New ids; `tail_start_id` translated through a lookup table | No |
| hermes-agent | New session; index advanced by hand to the copied length | No. Compaction-created sessions reset to 0 because they start empty. |
| pi-mono | No cursor needed: walk leaf to nearest common ancestor | No; traversal excludes it |
| OpenProgram | Unchanged; markers read back from the current tip | No |
| pi-ai, weclaw | No forks; weclaw's `/new` clears the session | — |

Index and timestamp cursors need one line per scope, so they change scope at a fork, and that works because their forks copy content. Our forks copy nothing, so we record identities. pi-mono's alternative needs a comparison branch for every traversal; memory asks what is unwritten in the session and has no second branch to compare.

**Verified locations**

| Framework | Location |
| --- | --- |
| codex-cli | `thread-store/src/types.rs:78-79,97` `state/memory_migrations/0001_memories.sql:1-12` `state/src/runtime/memories.rs:104-108` `memories/write/src/phase1.rs:290` |
| openclaw | `src/auto-reply/reply/session.ts:756-767,793-799` `src/config/sessions/types.ts:370-371` `src/auto-reply/reply/memory-flush.ts:117-123` |
| opencode | `packages/opencode/src/session/session.ts:748-758,767-769` `.../compaction.ts:244-248` |
| hermes-agent | `cli.py:6701-6705,6744-6756,6776-6777` `agent/agent_init.py:1026` `agent/conversation_compression.py:379-380,407-408` |
| pi-mono | `packages/agent/src/harness/compaction/branch-summarization.ts:87-97` `packages/agent/src/harness/agent-harness.ts:737-834` |
| weclaw | `agent/http_agent.go:76-78` |
| OpenProgram | `openprogram/state/memory/writing.py` |

## Retrieval

| Path | Who | How | Cost |
| --- | --- | --- | --- |
| Inject everything | opencode, pi-mono | All of `AGENTS.md` enters the system prompt; the model greps for finer detail | No infrastructure; large files exhaust the budget |
| Keyword | OpenProgram, hermes, codex | Ours: BM25, five results each turn, no model call (1 to 10 by setting; embedding, hybrid and agent are options). hermes: SQLite full-text session search. codex: line-by-line substring. | Fast and explainable; paraphrases may miss |
| Vector | openclaw | Nearest neighbours combined with full-text ranking; a subagent also searches before the user turn and inserts conclusions | Embeddings, indexes, rebuilds: over half of 20,000-plus lines |

## Resident content when full

| Block | Limit | When full | Disclosure |
| --- | --- | --- | --- |
| claude-code `MEMORY.md` | 200 lines or 25KB | The rest does not load at session start | Error telling Claude to rewrite the index |
| claude-code `CLAUDE.md` | 4 MiB; under 200 lines advised | A file over 4 MiB is skipped | — |
| codex-cli | Project `AGENTS.md` 32 KiB shared; summary 2500 tokens; global unlimited | Cut at the remaining-byte boundary | Log entry only |
| openclaw `MEMORY.md` | 10000 characters | Removes only automatically promoted paragraphs, oldest first; handwritten text stays | Returns removed dates |
| openclaw startup layer | 12000 per file, 60000 total characters | 75% head, 25% tail. `AGENTS.md`: 45% head, 35% regex-selected key lines, 15% tail. | System-prompt warning, by default every time |
| hermes-agent | 2200 and 1375 characters | Rejects the write; the model frees space with replace or remove | Usage and limit returned to the model |
| OpenProgram | 2000 tokens, counted with tiktoken | Renders paragraphs in file order until the next does not fit. `topics/core.md` is not changed. | Reports what was left out; it stays searchable |
| opencode, pi-mono | `AGENTS.md` unlimited, confirmed | — | — |
| pi-ai, weclaw | No block; weclaw has a fixed configured prompt | — | — |

**Verified locations**

| Framework | Location |
| --- | --- |
| codex-cli | `core/src/config/mod.rs:211` `core/src/agents_md.rs:94,116-124` `ext/memories/src/lib.rs:16` |
| openclaw MEMORY.md | `extensions/memory-core/src/memory-budget.ts:25,100-164` `short-term-promotion.ts:1719,1762` |
| openclaw startup | `src/agents/pi-embedded-helpers/bootstrap.ts:88-89,96-102,158-165` |
| opencode | `packages/opencode/src/session/instruction.ts:91-93,155-169` |
| hermes-agent | `tools/memory_tool.py:149,295-306,359-366` |
| pi-mono | `packages/coding-agent/src/core/system-prompt.ts:61-68` |
| weclaw | `config/config.go:28` |
| OpenProgram | `openprogram/state/memory/management/config.py` `openprogram/state/memory/runtime/derived_views.py` `openprogram/state/memory/management/block_views.py` |

### Maintenance and new facts after saturation

| Framework | Canonical source | Maintenance | After saturation |
| --- | --- | --- | --- |
| claude-code | Topic files; `MEMORY.md` is only an index | Claude is reminded to shorten the index near a limit | The write succeeds; Claude is told to rewrite the index |
| codex-cli | SQLite, then raw-memory file, then `memory_summary.md` | Full rewrite at session start with six-hour cooldown; prunes entries unused for 30 days | Rewritten each round; 2500-token cut at injection |
| openclaw | `MEMORY.md`, hence ownership-based trimming | Daily 03:00 cron after the dream pipeline | Oldest automatic text trimmed first; writes continue |
| hermes-agent | The file itself | None, the only one | The main model must first make room |
| OpenProgram | `topics/core.md`; the block in `MEMORY.md` is derived | Rebuilt with other derived views after every installed transaction; nightly organization edits Topics only | Topics still accept writes; over-budget content stays retrievable |
| opencode, pi-mono | Handwritten file | Not applicable | No limit |

**Lessons on trimming**

| Lesson | For us |
| --- | --- |
| Line counts cannot limit long lines | Not adopted: another write-path gate would still exclude stable facts. Ours counts tokens at rendering. |
| Trim by ownership, not age | Not adopted: it matters when the file is the sole copy. Our block is derived, so omission destroys nothing. |
| Limit all relevant content | codex omits global `AGENTS.md`; claude-code stops a `CLAUDE.md` only at 4 MiB |
| Disclose truncation | codex only logs it, so user and model never know. Ours reports it. |

The decision and rationale: [What to adopt after comparison](https://fzkuji.github.io/OpenProgram/docs/reference/design/memory/adoption.html), section 02.

**Verified locations**

| Framework | Location |
| --- | --- |
| codex-cli | `state/src/runtime/memories.rs:21` `memories/write/src/phase2.rs:139-166` `memories/write/src/phase1.rs:110-133` `ext/memories/src/lib.rs:16` |
| openclaw | `src/memory-host-sdk/dreaming.ts:17` `extensions/memory-core/src/memory-budget.ts:25,100-164` `.../short-term-promotion.ts:1706-1727` |
| hermes-agent | `tools/memory_tool.py:149,295-306` No matches: consolidate, distill, prune, compact, dream |
| opencode, pi-mono | `packages/opencode/src/session/instruction.ts:60-93` `packages/coding-agent/src/core/resource-loader.ts:57-100` |

## Implementation size

| Framework | Lines, no tests | Covers |
| --- | --- | --- |
| openclaw | 34,000 | Vectors, full-text, dream pipeline, promotion ranking. Two alternative backends add 12,000, excluded. |
| OpenProgram | 11,600 | All of `openprogram/state/memory/`: writing, transactions, retrieval, topic format, nightly organization. None is compaction. |
| codex-cli | 8,900 + 3,700 | Two-stage distillation and read path. About 60,000 transcript and fork lines are not memory. |
| hermes-agent | 2,800 + 2,400 | Eight optional service plugins total 11,600, all off by default |
| pi-mono | 5,000 | Session tree and compaction, the same logic twice; 0 long-term memory |
| opencode | 1,550 | Compaction and storage; 0 long-term memory |
| weclaw | 200 | Session-id bookkeeping |
| pi-ai | 0 | — |

Vectors, embedding caches, index rebuilds and hybrid ranking dominate openclaw. Maintaining an index, not having memory, is the divide.

## Practices worth borrowing

| From | Practice | Ours |
| --- | --- | --- |
| codex-cli | Writer lease from a SQLite table with retry counts and last watermark; checks quota first | Cross-process write lock, one-second timeout; the idle watcher keeps failures by the scope of their cause (conversation, memory, sign-in) in `ingest-state.json`; failures reach writer status and a `memory_writer_failed` frame |
| codex-cli | The model embeds a hidden marker naming memory it used; the server counts it and strips it. Counts rank content at organization. | Not built; nightly organization merges by content |
| openclaw | Deduplication in two copies that check each other | Node marks alone; Topic footnotes name the same messages without cross-checking |
| pi-mono | A generated summary on leaving a branch | Not built |

## Implementation status

| Status | Items |
| --- | --- |
| Implemented | `topics/core.md` as canonical resident source, per-node workspace markers, live-branch enumeration at session boundaries, Topic footnotes preserving Source references |
| Not yet | Index-free selection from Topic self-descriptions, retrieval usage as organization input, direct writer notification on head changes instead of post-turn thresholds or the idle watcher |
