Persistent shared memory for OpenCode agents, powered by mnemoria.
If this project has been helpful to you, you are welcome to sponsor it. Sponsorship helps me spend more time maintaining it, fixing bugs, and building new features.
No pressure at all - starring the repo, sharing it, or giving feedback also means a lot.
Every time you start a new OpenCode session, your AI assistant loses all context from previous conversations. oc-mnemoria fixes this by giving all agents a shared "hive mind" — a single persistent memory store where every agent can read and write.
Each memory entry is tagged with the agent that created it (plan, build, ask, review, ...) so any agent can tell who recorded what. The build agent can see what the plan agent decided; the review agent can recall bugs the build agent fixed. No context is lost between roles.
Memories are stored locally in an append-only binary file using mnemoria — a Rust engine with hybrid BM25 + semantic search, CRC32 checksum chains, and corruption recovery.
- Rust toolchain (to install the mnemoria CLI)
- OpenCode (v0.1+)
- Node.js >= 18
Run the install script in your project directory:
curl -fsSL https://raw.githubusercontent.com/one-bit/oc-mnemoria/main/install.sh | shThe script:
- Installs the
mnemoriaCLI (viacargo installif needed) - Adds
"oc-mnemoria"to the plugin array inopencode.json - Installs
/mn-*slash commands to.opencode/commands/
After installation, restart OpenCode and run:
/mn-statsYou should see memory store statistics (entry count, file size, timestamps).
All agents share a single memory store:
.opencode/mnemoria/
log.bin # append-only binary log
manifest.json # metadata and checksums
mnemoria.lock # advisory file lock
You can interact with the store directly using the mnemoria CLI:
mnemoria --path .opencode stats
mnemoria --path .opencode search "authentication"
mnemoria --path .opencode export memories.jsonEvery memory entry is tagged with the agent that created it via mnemoria's
native --agent flag. The agent name is a first-class field on each entry,
visible in search results, timeline output, and JSON exports.
# Search only the build agent's memories
mnemoria --path .opencode search -a build "authentication"
# Show only the plan agent's timeline
mnemoria --path .opencode timeline -a planThe plugin automatically extracts user intents from chat messages via the
chat.message hook. When a user describes a goal or task, the plugin
categorizes it (e.g. fix, refactor, feature) and stores it in the shared
memory, tagged with the current agent. Duplicate intents within the same
session are deduplicated.
Agents can also store memories explicitly using the remember tool for
discoveries, decisions, solutions, and other observations worth preserving.
At the start of each session, the plugin injects cross-agent context into
the system prompt via the experimental.chat.system.transform hook:
- Memory guidance — instructions for when to use
search_memory,ask_memory, andremember - Recent context — the latest memories from the shared store, each showing which agent created it
- Relevant memories — search results matched against the current user intent (if one exists)
- Past user goals — intents from previous sessions so the agent understands prior work
| Tool | Description |
|---|---|
remember |
Store a categorized observation in shared memory |
search_memory |
Search by keyword/semantic similarity |
ask_memory |
Ask a natural language question |
memory_stats |
View statistics for the shared store |
timeline |
Browse memories chronologically (all agents) |
forget |
Mark a memory as obsolete (append-only tombstone) |
compact |
Remove forgotten entries/markers and optionally prune old data |
Observations are categorized when stored:
intent discovery decision problem solution pattern warning
success refactor bugfix feature
| Command | Description |
|---|---|
/mn-ask <q> |
Ask about past decisions |
/mn-search <q> |
Search memories |
/mn-stats |
Show memory statistics |
/mn-recent |
Show recent memories |
/mn-timeline |
Chronological view |
/mn-forget ... |
Mark a memory as forgotten/obsolete |
/mn-compact |
Compact store by removing forgotten data |
You can use the mnemoria CLI directly to browse, search, and manage the
memory store outside of OpenCode. All commands use --path .opencode to
point at your project's store (mnemoria auto-appends mnemoria/ to resolve
the actual data directory).
# Most recent 20 entries (newest first)
mnemoria --path .opencode timeline -r
# Last 5 entries
mnemoria --path .opencode timeline -r -l 5
# Only entries from the build agent
mnemoria --path .opencode timeline -a build
# Entries from a specific time range (Unix ms timestamps)
mnemoria --path .opencode timeline -s 1700000000000 -u 1700100000000Output looks like:
Timeline (3 entries):
1. [discovery] (build) Found async pattern in auth module - 1700000100000
2. [decision] (plan) Use JWT for session tokens - 1700000050000
3. [intent] (plan) Fix authentication flow - 1700000000000
# Keyword + semantic hybrid search
mnemoria --path .opencode search "authentication"
# Limit results
mnemoria --path .opencode search "error handling" -l 5
# Search only one agent's memories
mnemoria --path .opencode search -a review "security"# Ask a natural language question against the memory store
mnemoria --path .opencode ask "What decisions were made about the database schema?"
# Scoped to a single agent
mnemoria --path .opencode ask -a plan "What was the original plan for auth?"mnemoria --path .opencode statsMemory Statistics:
Total entries: 42
File size: 4096 bytes
Oldest entry: 1700000000000
Newest entry: 1700001000000
mnemoria --path .opencode export memories.jsonThis produces a JSON array with full entry data including agent_name,
entry_type, summary, content, timestamp, and checksum fields.
Useful for scripting, analysis, or migrating data.
mnemoria --path .opencode add \
-a build \
-t decision \
-s "Switched from REST to GraphQL" \
"After benchmarking, GraphQL reduced payload size by 60%"The -t flag accepts any entry type: intent, discovery, decision,
problem, solution, pattern, warning, success, refactor,
bugfix, feature. Defaults to discovery if omitted.
mnemoria --path .opencode verifyChecks the CRC32 checksum chain across all entries. Returns a non-zero exit code on corruption, making it suitable for CI or pre-commit hooks.
Over time, some memories become outdated. oc-mnemoria supports a two-step maintenance flow:
- Mark obsolete entries with
forget(append-only marker) - Run
compactto physically rebuild the store without forgotten entries
Use slash commands:
/mn-search flaky test timeout
/mn-forget id=8d9f... reason="Superseded by retry policy"
/mn-compactOptionally prune old entries during compaction:
/mn-compact 90(90 means maxAgeDays=90)
forgetkeeps history intact by writing a tombstone markercompactremoves forgotten markers/entries and optionally old data- This keeps the memory store accurate while preserving auditability between runs
Mnemoria's append-only binary format is designed for version control. You can commit the memory store to track history alongside your code:
git add .opencode/
git commit -m "update agent memories"Or ignore it:
echo ".opencode/mnemoria/" >> .gitignore # ignore just the memory storeHow much disk space does this use? The store starts empty. A typical entry is ~100-500 bytes. Active daily use produces roughly 2-10 MB per year.
Is my data sent anywhere? No. Everything stays on your local filesystem. The mnemoria engine runs entirely offline.
How fast is it? The mnemoria Rust engine delivers sub-millisecond search latency for typical store sizes (<10k entries). The plugin shells out to the CLI, so there's ~50ms overhead per operation from process spawning.
Can I reset the memory? Delete the store directory:
rm -rf .opencode/mnemoria/Can I search only one agent's memories?
Yes. Pass the agent parameter to search_memory, ask_memory, or
timeline. From the CLI: mnemoria --path .opencode search -a build "auth".
MIT