█

AI/TLDR

Buy me a coffee
Buy me a coffee

OpenCode Memory

Persistent local vector memory for OpenCode coding agents

Agent MemoryOpen source
Latest
v2.31.2
Updated
13 Oct 2026
Language
TypeScript
License
MIT

What's new

v2.31.213 Oct 2026

Patch release that re-raises SIGINT/SIGTERM after the plugin's cleanup runs.

IN SHORT

What is OpenCode Memory?

OpenCode Memory (`opencode-mem`) is a plugin for the OpenCode coding agent that keeps long-term context across sessions. It sits in the Agent Memory category of the Agents & Automation tools and is open-source, written in TypeScript and licensed MIT. To get started: add the plugin to OpenCode.

Updated Markdown version ↗

Overview

OpenCode Memory (`opencode-mem`) is a plugin for the OpenCode coding agent that keeps long-term context across sessions. Instead of starting every chat from a blank slate, the agent gets relevant memories from earlier work injected into its context: project decisions, bug patterns, "we tried X and it failed" notes, and a learned profile of how you like to work. The README is explicit that you do not need to ask the agent to remember anything; with the defaults, memory builds up as you work.

Capture is automatic. When a session goes idle, the plugin runs a background AI request that summarizes the technical work and saves it as a memory. It can reuse a provider already authenticated in OpenCode (`opencodeProvider` + `opencodeModel`, or `"inherit"` to follow the session model) or a manual fallback such as an OpenAI-compatible, OpenAI Responses or Anthropic API. A separate, cross-project user profile is refreshed on an interval (every 10 analyzed prompts by default). Auto-capture and profile learning need a provider that returns structured or tool-call output; manual add, search and list work without one.

Everything is stored locally. The plugin embeds Turso (`@tursodatabase/database`) and keeps `F32_BLOB` vectors in it, ranked by exact cosine distance with optional keyword hybrid ranking, so no separate vector database is required. Embeddings run on CPU by default with `Xenova/nomic-embed-text-v1` via Hugging Face transformers and ONNX (no GPU needed), or through any OpenAI-compatible embeddings endpoint. Memories are sharded per project, identified by the enclosing git repository or by a `.opencode-mem-project` marker file, and a local web UI at `http://127.0.0.1:4747` shows the memory-prompt timeline, captures, profile and a shared Skills library.

What it does

  • Automatic capture: an AI summary of each idle session's technical work is stored as a memory, with no prompting required
  • Relevant memories injected into the model's system context on the first message of a session (or on every turn with `injectOn: "always"`)
  • A `memory` tool with `add`, `search`, `list`, `profile`, `forget`, `list-shards`, `migrate`, `export` and `import` modes
  • Embedded Turso/libSQL storage with native vectors and exact cosine search; no separate vector database
  • Local CPU embeddings (default `Xenova/nomic-embed-text-v1`, other Hugging Face models selectable) or a remote OpenAI-compatible embeddings API
  • Automatically learned cross-project user profile of your preferences and habits
  • Local web UI for browsing the memory-prompt timeline, editing captures, managing the profile and authoring shared Skills
  • Optional AES-256-GCM encryption at rest for the local database shards, plus Basic Auth or an API token when the web UI is bound beyond loopback
  • Project-scoped memories by default, with an `all-projects` search scope and a marker file to share one memory store across nested repos

Getting started

opencode-mem is installed by listing it in your OpenCode configuration; OpenCode downloads the package on next startup. The README lists Bun and a standard OpenCode plugin environment as the recommended runtime, and the default local embedding model is downloaded from Hugging Face on first use. CI-tested platforms are Linux, Windows and Apple Silicon macOS; Intel Macs (`darwin/x64`) are not supported.

Add the plugin to OpenCode

On OpenCode v2, add the package to the `plugins` list. On OpenCode v1, use the `plugin` key in `~/.config/opencode/opencode.json` instead. Restart OpenCode and the plugin downloads automatically.

jsoncjsonc
{
  "plugins": ["opencode-mem@latest"],
}

Point auto-capture at a provider

Settings live in `~/.config/opencode/opencode-mem.jsonc`, which the plugin creates as a commented template on first startup. The recommended setup reuses a provider already authenticated in OpenCode; the name must match an entry from `opencode providers list` and the model must support structured output.

jsoncjsonc
"opencodeProvider": "anthropic",
"opencodeModel": "claude-haiku-4-5-20251001",

Optionally switch to remote embeddings

Local CPU embeddings are the default. To use an OpenAI-compatible endpoint instead, set both the URL and the key in the same config file. Changing the embedding model later can require re-embedding stored memories.

jsoncjsonc
{
  "embeddingApiUrl": "https://api.openai.com/v1",
  "embeddingApiKey": "env://OPENAI_API_KEY",
  "embeddingModel": "text-embedding-3-small",
}

Work normally, or use the memory tool directly

Memories accumulate as sessions go idle. When you want something stored or retrieved immediately, the agent can call the `memory` tool. Browse and edit everything in the web UI at `http://127.0.0.1:4747`.

tsts
memory({ mode: "add", content: "Project uses microservices architecture" });
memory({ mode: "search", query: "architecture decisions" });
memory({ mode: "search", query: "architecture decisions", scope: "all-projects" });
memory({ mode: "profile" });

Move or back up project memories

Shards are keyed by a hash of the project identity, so moving a repository can orphan them. Preview a migration with `dryRun`, or export to JSON and import on another machine (embeddings are recomputed with the configured model).

tsts
memory({ mode: "migrate", fromPath: "/old/path/to/project", dryRun: true });
memory({ mode: "export", outputPath: "./memories.json" });
memory({ mode: "import", inputPath: "./memories.json" });

Commands and code are distilled from the project's own documentation — always check the official repo for the latest.

When to use it

  • Give an OpenCode agent memory of past decisions and failed approaches on a long-running project, without maintaining notes by hand
  • Keep coding-agent memory fully local, with on-device CPU embeddings and optional encryption at rest
  • Share one memory store across a multi-repo workspace or monorepo using a `.opencode-mem-project` marker file
  • Carry project memories across machines or relocated checkouts with export/import and path or hash migration

How OpenCode Memory compares

OpenCode Memory alongside other open-source agent memory tools AI/TLDR tracks, ranked by GitHub stars.

ToolStarsWhat it does
Claude-Mem★ 121kPersistent memory layer for coding agents: it captures what an agent does during a session, compresses it into semantic summaries, and injects the relevant parts back into later sessions.
Mem0★ 69.7kA memory layer that you add to existing LLM agents to extract, store, and recall user facts and preferences across sessions using vector, graph, and key-value backends.
Hindsight★ 64.3kAn agent memory server that stores facts and experiences, consolidates them into observations and mental models, and serves them back through retain, recall, and reflect operations.
MemPalace★ 60.8kLocal-first agent memory that stores conversations verbatim instead of summarising them, with a structured palace index, pluggable vector backends and an MCP server.
OpenViking★ 43.1kA context database that stores an agent's memories, resources, and skills as one browsable viking:// filesystem with three-tier (abstract/overview/details) on-demand loading.
Cognee★ 33.7kA graph-native memory engine that turns raw documents and conversations into a queryable knowledge graph for agents that need to build lasting knowledge.
Graphiti★ 33.2kA library that builds a temporal knowledge graph from an agent's conversations and data so facts can be tracked and queried as they change over time.
OpenCode Memory★ 1.9kPersistent local vector memory for OpenCode coding agents