# OpenCode Memory

> Persistent local vector memory for OpenCode coding agents

- Category: Agents & Automation / Agent Memory
- Language: TypeScript
- Licence: MIT
- Repository: https://github.com/tickernelz/opencode-mem
- Canonical page: https://ai-tldr.dev/tools/opencode-mem/
- Updated: 2026-10-13

## In short

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.

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

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

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

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

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

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

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

4. 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`.

```ts
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" });
```

5. 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).

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

## 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

## Version history

- 2026-10-13 v2.31.2: Patch release that re-raises SIGINT/SIGTERM after the plugin's cleanup runs.
