supermemory/apps/docs/integrations/opencode.mdx
MaheshtheDev 474c23a386 docs(opencode): document 2.3.0 session skips and prompt dedupe
opencode-supermemory 2.3.0 (supermemoryai/opencode-supermemory#125): src/services/session-scope.ts skips subagent and v1 headless sessions, src/services/local-dedupe.ts adds the opening-prompt (200 chars, 24h, legacy capture only) and recall-query (10 min) indexes; flags and env vars in src/config.ts.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
2026-11-26 16:33:13 +00:00

194 lines
8.2 KiB
Text

---
title: "OpenCode"
sidebarTitle: "OpenCode"
description: "Supermemory plugin for OpenCode. Keeps memory across coding sessions."
icon: "/images/opencode-logo.svg"
---
[OpenCode-Supermemory](https://github.com/supermemoryai/opencode-supermemory) is an OpenCode plugin that gives your AI persistent memory across sessions. Your agent remembers what you worked on — across sessions, across projects.
<Tip>
**Prefer to keep everything on your machine?** This plugin works with [self-hosted Supermemory](/self-hosting/overview) — run `npx supermemory local`, then set `apiKey` / base URL in `~/.config/opencode/supermemory.jsonc` and use the API key printed on first boot.
</Tip>
## Install the plugin
```bash
bunx opencode-supermemory@latest install
```
For LLM agents (non-interactive):
```bash
bunx opencode-supermemory@latest install --no-tui
```
## Authenticate
Browser login (recommended):
```bash
bunx opencode-supermemory@latest login
```
You can manage the plugin, change its access, or disconnect it from the [Agents page](https://console.supermemory.ai/agents) in the console.
Check the connection any time:
```bash
bunx opencode-supermemory@latest status
```
Or set an API key manually from the [API Keys](https://console.supermemory.ai/keys) page in the console:
<Tabs>
<Tab title="macOS / Linux (zsh)">
```bash
echo 'export SUPERMEMORY_API_KEY="sm_..."' >> ~/.zshrc
source ~/.zshrc
```
</Tab>
<Tab title="macOS / Linux (bash)">
```bash
echo 'export SUPERMEMORY_API_KEY="sm_..."' >> ~/.bashrc
source ~/.bashrc
```
</Tab>
<Tab title="Windows (PowerShell)">
```powershell
[System.Environment]::SetEnvironmentVariable("SUPERMEMORY_API_KEY", "sm_...", "User")
```
Restart your terminal after running this.
</Tab>
</Tabs>
The installer adds Supermemory to `~/.config/opencode/opencode.jsonc`. This one config works on both OpenCode v1 and v2:
```jsonc
{
"plugin": ["opencode-supermemory@latest"],
"plugins": ["opencode-supermemory"],
"permission": { "supermemory_recall": "allow" }
}
```
If OpenCode won't start after an older install, run the installer again to update your config.
## How it works
Once installed, the plugin runs automatically:
- **Context Injection** — On a session's first message, your profile facts are injected into the agent's context.
- **Direct Recall** — On every substantive prompt, the plugin searches the current project and injects up to five fresh matches. Set `recallMode` to `"advisory"` to let the agent decide when to search, or `"off"` to disable it.
- **Automatic Capture** — Completed turns are saved every `captureEveryNTurns` turns (fresh installs use `0`, which saves only at the end), and any remainder is flushed when the session ends or OpenCode shuts down.
- **Keyword Detection** — Phrases like "remember" or "save this" nudge the agent to save to memory.
- **Smart Compaction** — On OpenCode v1, sessions are summarized at 80% context capacity; on OpenCode v2, the plugin enriches native compaction. Both save the summary as a memory.
- **Privacy Protection** — Content within `<private>` tags never persists.
### Sessions without automatic memory
Automatic recall, capture and compaction memory run only for sessions you drive yourself. By default the plugin skips:
- **Subagent sessions** — child sessions spawned by the `task` tool (OpenCode v1) or the `subagent` tool (OpenCode v2). Set `captureSubagents: true` to include them.
- **Headless runs (OpenCode v1)** — `opencode run` and `opencode github run`. Set `captureHeadless: true` to include them. OpenCode v2 gives plugins no signal for `opencode run`, so v2 runs are treated as interactive.
Sessions started by Conductor or Vibe Kanban always count as interactive; set `captureOrchestrated: false` to skip them.
Two local indexes under `~/.supermemory-opencode/` keep repeated prompts from being re-sent:
- **Opening prompt** (`dedupeOpeningPrompt`) — an opening prompt of 200+ characters already captured from this machine for the same container in the last 24 hours is replaced by a one-line marker. This applies to the legacy API only; v5 uploads the transcript unchanged.
- **Recall query** (`dedupeRecallQueries`) — the same query against the same container within 10 minutes reuses the first result instead of searching again.
Each of these five options can also be set with an environment variable, `SUPERMEMORY_CAPTURE_SUBAGENTS`, `SUPERMEMORY_CAPTURE_HEADLESS`, `SUPERMEMORY_CAPTURE_ORCHESTRATED`, `SUPERMEMORY_DEDUPE_OPENING_PROMPT` or `SUPERMEMORY_DEDUPE_RECALL_QUERIES`. Set it to `true` or `false`; it takes priority over the config file.
### Memory scopes
Both scopes write to one repository container, `repo_{project-name}__{repository-hash}`, shared with the Claude Code, Codex, and Cursor plugins. `sm_scope` metadata keeps them apart.
| Scope | Description |
|-------|-------------|
| `user` | Personal memories for the current project |
| `project` | Project knowledge for the current project (default) |
### Memory types
| Type | Description |
|------|-------------|
| `project-config` | Project configuration and setup details |
| `architecture` | Codebase structure and design patterns |
| `error-solution` | Problems encountered and their fixes |
| `preference` | User preferences and coding style |
| `learned-pattern` | Patterns discovered during sessions |
| `conversation` | Important conversation context |
## Commands
The installer adds these in-chat commands:
| Command | Description |
|---------|-------------|
| `/supermemory-index` | Explore and index your codebase structure into memory (`/supermemory-init` is an alias) |
| `/supermemory-login` | Authenticate with Supermemory in the browser |
| `/supermemory-logout` | Clear stored credentials |
| `/supermemory-status` | Show the Supermemory connection status |
## Tools
The agent has access to a `supermemory` tool with these modes:
| Mode | Parameters | Function |
|------|------------|----------|
| `add` | content, type?, scope? | Store information |
| `search` | query, scope? | Find relevant memories |
| `profile` | query? | View user preferences |
| `list` | scope?, limit? | Display stored items |
| `forget` | memoryId, scope? | Remove memory |
| `help` | none | List available modes |
## Configuration
Create `~/.config/opencode/supermemory.jsonc`:
```jsonc
{
"apiKey": "sm_...", // Or use SUPERMEMORY_API_KEY / browser login
"baseUrl": "https://api.supermemory.ai", // Or SUPERMEMORY_API_URL (self-hosted)
"apiVersion": "v5", // "v5" or "legacy"; custom baseUrl values default to "legacy"
"similarityThreshold": 0.55, // Minimum match score (0-1)
"maxMemories": 5, // Memories per injection
"maxProjectMemories": 10, // Project memory listings
"maxProfileItems": 5, // Profile facts injected
"injectProfile": true, // Include user preferences in context
"projectContainerTag": "my-project-tag", // Optional: override the repository container
"keywordPatterns": ["log\\s+this"], // Extra auto-save triggers
"recallMode": "direct", // "direct", "advisory", or "off"
"captureEveryNTurns": 3, // Save completed turns every N turns (0 = session end only)
"captureSubagents": false, // Recall and capture in subagent sessions
"captureHeadless": false, // OpenCode v1: recall and capture in opencode run
"captureOrchestrated": true, // Recall and capture in Conductor and Vibe Kanban sessions
"dedupeOpeningPrompt": true, // Legacy API: replace a repeated opening prompt with a marker
"dedupeRecallQueries": true, // Reuse a recall result for the same query within 10 minutes
"compactionThreshold": 0.80, // OpenCode v1: context usage ratio for summarization
"compactionEnabled": true // OpenCode v2: enrich native compaction and save summaries
}
```
## Logging
View plugin activity:
```bash
tail -f ~/.opencode-supermemory.log
```
## Next steps
<CardGroup cols={2}>
<Card title="GitHub repository" icon="/images/github-icon.svg" href="https://github.com/supermemoryai/opencode-supermemory">
Source code, issues, and detailed README.
</Card>
<Card title="Claude Code plugin" icon="/icons/hugeicons/source-code.svg" href="/integrations/claude-code">
Memory plugin for Claude Code.
</Card>
</CardGroup>