0
Fork 0
mirror of https://github.com/mastra-ai/mastra.git synced 2026-11-17 08:44:46 +00:00
mastra/integrations/opencode
dane-ai-mastra[bot] a5859ee2b9
chore: version packages (alpha) (#30430)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
History 2026-11-16 14:09:31 +01:00
..
src fix(memory): scope-aware Observational Memory preamble (#24889) 2026-09-23 18:22:41 -07:00
CHANGELOG.md chore: version packages (alpha) (#30430) 2026-11-16 14:09:31 +01:00
lint-staged.config.js refactor(lint): replace ESLint with type-aware oxlint (#27476) 2026-10-18 10:38:35 -07:00
package.json chore: version packages (alpha) (#30430) 2026-11-16 14:09:31 +01:00
README.md chore(*): Update/unify/add READMEs (#22858) 2026-09-02 14:36:59 +02:00
tsconfig.build.json feat(memory, opencode): add @mastra/opencode plugin and standalone observe() API (#12925) 2026-02-11 14:20:05 -08:00
tsconfig.json chore: migrate package builds to tsdown (#19829) 2026-07-28 12:32:21 +02:00
tsdown.config.ts chore: migrate package builds to tsdown (#19829) 2026-07-28 12:32:21 +02:00
turbo.json chore: migrate package builds to tsdown (#19829) 2026-07-28 12:32:21 +02:00

@mastra/opencode

@mastra/opencode brings Mastra Observational Memory to OpenCode sessions. It condenses long conversation histories into structured observations so coding sessions retain important context without repeatedly sending the entire transcript to the model.

Installation

npm install @mastra/opencode

Usage

Re-export the plugin from an OpenCode plugin file:

import { MastraPlugin } from '@mastra/opencode';

export default MastraPlugin;

Optionally add project-level configuration:

{
  "model": "google/gemini-2.5-flash",
  "observation": { "messageTokens": 20000 },
  "reflection": { "observationTokens": 90000 },
  "storagePath": ".opencode/memory/observations.db"
}

Documentation

The plugin converts OpenCode user and assistant messages, including text, tool calls, files, images, and reasoning, into Mastra's message format. Before each model request it observes new messages when the configured token threshold is reached, removes history already represented by observations, and injects the optimized observation context into the system prompt.

Configuration is read from .opencode/mastra.json. It accepts Mastra ObservationalMemoryOptions such as the observer model, observation and reflection thresholds, scope, and shared token budget. storagePath controls the local SQLite database and defaults to .opencode/memory/observations.db.

The plugin resolves model credentials lazily from OpenCode's provider store. Existing environment variables take precedence, so OpenCode credentials only fill missing provider keys. Observation data is stored with LibSQLStore inside the project and remains available when the OpenCode session is resumed.

OpenCode toast notifications report observation and reflection progress. The plugin also registers diagnostic tools for inspecting memory status and stored observations, which helps explain when the next compaction cycle will run and what context has already been retained.

Changelog

See the package changelog for version history and release notes.

Support

We have an open community Discord. Come and say hello and let us know if you have any questions or need any help getting things running.