Skip to content

About

OpenCode plugin implementing Mastra-inspired observational memory. Who doesn't love limitless context windows?

Resources

Stars

5 stars

Watchers

0 watching

Forks

Repository files navigation

opencode-observational-memory

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.

Install OM

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.

  1. 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
  2. Add OM to plugins in opencode.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 from sbd-install.

  3. Set compaction.background to false. Otherwise, OpenCode can reuse an earlier checkpoint preparation without observing messages that arrived afterward.

  4. For recall before the last compaction, set experimental.sqlite_fts to true. It lets om_recall direct the model to OpenCode's opencode.session.read tool 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 }
}

Configure the memory models and time zone

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:

  1. openai/gpt-6.1-terra#medium
  2. openai/gpt-6-luna#medium
  3. openai/gpt-5.6-luna
  4. claude-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"
	}
}

Use OM

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.

Disable or trace OM

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.

Known limits in v1

  • 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.

Development

pnpm install
pnpm lint
pnpm typecheck
pnpm test

OpenCode 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.mjs runs the smoke test with OpenCode's simulated provider.
  • node test/live/real/run.mjs runs live checks with configured providers and archives its test sessions.
  • Phase 7 adds node test/eval/run.mjs --full to 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.

About

OpenCode plugin implementing Mastra-inspired observational memory. Who doesn't love limitless context windows?

Resources

Stars

5 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages