OpenCode Memory is a persistent memory system for AI coding agents, providing long-term context retention across sessions using local vector database technology. The package, currently at version 2.13.0, receives frequent minor and patch releases, indicating active development. Key differentiators include its local-first approach using SQLite and USearch (with ExactScan fallback), automated user profile learning, a unified memory-prompt timeline, and a full-featured web UI for management. It supports multi-provider AI (OpenAI, Anthropic) and integrates with over 12 local embedding models, offering intelligent prompt-based memory extraction, smart deduplication, and built-in privacy protection. It acts as an OpenCode plugin, meaning its core functionality is exposed to the AI agent runtime, rather than being directly imported into typical application code.
npm install opencode-memVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to enable the opencode-mem plugin within OpenCode and provides examples of how an AI agent interacts with its memory functions.
Upgrade `opencode-mem` to version 2.13.0 or newer via `bun install opencode-mem@latest` or `npm install opencode-mem@latest`, and restart OpenCode.
Carefully review the `~/.config/opencode/opencode-mem.jsonc` configuration file. Ensure API keys are correctly formatted (e.g., `env://OPENAI_API_KEY`) and that the chosen provider/model combination is valid and has necessary authentication. Use OpenCode's internal providers when possible to simplify authentication.
Ensure your environment (especially if running on non-standard systems) supports `USearch` if optimal performance is desired. Check `bun install` or `npm install` logs for any native module compilation errors related to vector indexing libraries. SQLite always remains the source of truth, and indexes are rebuilt from it.
Understand the OpenCode plugin architecture. For agent interactions, use the `memory({...})` function as demonstrated in quickstart. For programmatic extension or testing, import specific types or the `memoryPlugin` object directly.Add `"opencode-mem"` to the `plugin` array in your `~/.config/opencode/opencode.json` file, then restart OpenCode.
Example: `{ "plugin": ["opencode-mem"] }`Verify network connectivity if using a remote model. Check that `Bun` (recommended runtime) is properly installed and configured. Try a different, well-tested embedding model. Ensure sufficient disk space and memory for local model caching.
Ensure your API key is correctly specified. Examples: `"sk-..."` for direct keys, `"file://~/.config/opencode/api-key.txt"` for a file path, or `"env://OPENAI_API_KEY"` to read from an environment variable.
While `ExactScan` functions, for optimal performance, investigate the `bun install` logs for any errors related to `USearch` during plugin installation or build. Ensure your system meets any potential native dependency requirements for `USearch` if the issue persists.