Observational Memory (OM) keeps the model's context small in long OpenCode sessions. It replaces older conversation in the model's context with dated observations and leaves the original messages in OpenCode for recall.
Use OpenCode v2.4.3 or later. OpenCode bundles Bun and loads the plugin's TypeScript source directly. Use Node.js 24 or later and pnpm to install dependencies.
-
Clone the repository and install its production dependencies:
git clone https://github.com/bkono/opencode-observational-memory.git cd opencode-observational-memory pnpm install --prod --frozen-lockfile -
Add OM to
pluginsinopencode.json. See OpenCode config locations to choose a global or project config. Use the absolute path to your clone and keep any existing entries. OM installs separately fromsbd-install. -
Set
compaction.backgroundtofalse. Otherwise, OpenCode can reuse an earlier checkpoint preparation without observing messages that arrived afterward. -
For recall before the last compaction, set
experimental.sqlite_ftstotrue. It letsom_recalldirect the model to OpenCode'sopencode.session.readtool for that older history.
{
"$schema": "https://opencode.ai/config.json",
"plugins": [{ "package": "/absolute/path/to/opencode-observational-memory" }],
"compaction": { "background": false },
"experimental": { "sqlite_fts": true }
}To prefer a model for the observer and reflector, set options.model on the OM entry in plugins. Use a model reference in provider/model or provider/model#variant form, or a list of references in preference order. OM tries available overrides before the default chain:
openai/gpt-6.1-terra#mediumopenai/gpt-6-luna#mediumopenai/gpt-5.6-lunaclaude-agent/haiku
OM skips models and variants that OpenCode does not list as available. If none are available, OM pauses new work and keeps using any existing memory.
To override the server's local time zone for OM dates and timestamps, set options.timeZone to an IANA time zone such as Etc/UTC. For example, the OM plugin entry can be:
{
"package": "/absolute/path/to/opencode-observational-memory",
"options": {
"model": "claude-agent/haiku",
"timeZone": "Etc/UTC"
}
}OM runs automatically in primary sessions. The background observer records older messages as dated observations. At 30,000 pending tokens, OM can activate ready observations in place of the covered messages. At 40,000 observation tokens, OM can apply a buffered reflection that condenses older observations. When OM can safely handle compaction, including /compact, it updates memory and supplies a text checkpoint instead of running a second summarizer. Reverting restores earlier memory, and a fork inherits memory at its fork point. The model can call om_recall with an observation's range or a search query to look up details in the raw history.
The OpenCode terminal UI shows a footer like OM 12.0k/30.0k · mem 6.0k/40.0k · observing…. The counts show pending tokens and active memory against their thresholds. Run /om for status, model availability, and failures. Run /om observations to read the active observations. OM does not change subagent sessions and does not send toasts.
Set OPENCODE_OM_DISABLE=1 in the OpenCode server's environment before it starts. OM registers no hooks or tools, but its status RPC stays available and reports that OM is disabled. To stop loading OM altogether, remove its entry from plugins.
To debug OM, set OPENCODE_OM_TRACE=/path/to/trace.jsonl in the server's environment. OM appends events to that file.
- The model may re-read a source file instead of calling
om_recall, even when OM has the relevant observations. - Large attachments add about 2 ms per MiB to reads of message metadata in the synthetic latency test.
- On a compaction turn, OpenCode includes the newest user request as text inside the checkpoint rather than preserving it as a separate message.
- The desktop status pill is deferred. iOS has RPC access but no OM interface.
- Use one OpenCode server per data directory. Concurrent servers can conflict over OM writes or pause each other's active goals.
pnpm install
pnpm lint
pnpm typecheck
pnpm testOpenCode loads the TypeScript source directly (exports["./server"]); there is no build step.
pnpm upstream:diff checks the vendored OM code against the pinned Mastra source.
The live runners target OpenCode v2.4.3:
node test/live/smoke.mjsruns the smoke test with OpenCode's simulated provider.node test/live/real/run.mjsruns live checks with configured providers and archives its test sessions.- Phase 7 adds
node test/eval/run.mjs --fullto run the live behavior and latency evaluations.
See the rebuild plan for design decisions and the behavior lock for the behaviors carried over from Pi OM v2, itself a port of Mastra's Observational Memory. The history before the rebuild is under the tag legacy/v0.2.1.