The Engram plugin is a thin adapter layer that bridges OpenCode’s internal event system to theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/lnardev/opencode-config-agent/llms.txt
Use this file to discover all available pages before exploring further.
engram Go binary — a local HTTP server backed by a SQLite database. Every user prompt, tool call, and session summary is silently captured and persisted, making it available to future sessions and surviving context compaction. The plugin handles binary auto-start, project name extraction, session lifecycle management, and system prompt injection, so there is nothing for you to configure manually beyond having the engram binary installed.
Architecture
null and continues without disrupting the agent session.
Configuration
The plugin reads two environment variables at startup:| Variable | Default | Purpose |
|---|---|---|
ENGRAM_PORT | 7437 | HTTP port the engram binary listens on |
ENGRAM_BIN | Resolved in order: ENGRAM_BIN env var → Bun.which("engram") → /opt/homebrew/Cellar/engram/1.10.10/bin/engram | Path to the engram binary |
What the Plugin Does
1. Auto-Starts the Engram Binary
At plugin initialization, the plugin checks whetherengram serve is already running by hitting the /health endpoint with a 500ms timeout. If the binary is not running, it spawns it automatically:
engram serve manually — the plugin handles it.
2. Project Name Extraction
The plugin derives the project name using a three-step fallback chain:Git remote origin URL
Runs
git -C {directory} remote get-url origin and extracts the repository name from the URL (stripping .git suffix and taking the last path segment).Git root directory name
Runs
git -C {directory} rev-parse --show-toplevel and uses the basename. This handles worktrees correctly.3. Session Management
Sessions are created in engram on-demand viaensureSession(). This function is idempotent — it calls POST /sessions which uses INSERT OR IGNORE internally, so calling it multiple times for the same session ID is safe.
Sub-agent session suppression: Sessions created by the
task tool (or delegate) have a parentID set, or their title ends with " subagent)". These sessions are tracked in a subAgentSessions set and never registered in engram. This prevents the session-inflation bug (issue #116) where 170 engram sessions were created for a single conversation.4. Prompt Capture
Every user message longer than 10 characters is sent to the/prompts endpoint before the LLM sees it:
chat.message hook handles this. Content is truncated to 2000 characters and has private tags stripped before transmission.
5. Tool Call Counting
Thetool.execute.after hook fires after every tool execution. The plugin increments a per-session counter for all tools except Engram’s own tools (listed in ENGRAM_TOOLS). This gives meaningful session statistics without inflating counts with memory operations.
6. Passive Learning from Task Tool
When theTask tool completes and produces output longer than 50 characters, the plugin automatically sends that output to the /observations/passive endpoint:
mem_save call required.
7. System Prompt Injection
On every message,MEMORY_INSTRUCTIONS are appended to the last entry of output.system. This is intentionally an append — not a push — to avoid creating multiple system blocks:
- When to call
mem_save(mandatory after bug fixes, decisions, discoveries, etc.) - When and how to search memory (
mem_contextfirst, thenmem_search) - The session close protocol: always call
mem_session_summarybefore ending - What to do after compaction: save the compacted summary to engram first, then recover context
8. Compaction Hook
When OpenCode compacts a session, theexperimental.session.compacting hook fires. The plugin:
- Ensures the session exists in engram
- Fetches recent context from
/context?project={project}and injects it intooutput.context - Appends a critical instruction telling the compressor to embed a
FIRST ACTION REQUIREDdirective in the compacted summary — instructing the new agent to callmem_session_summaryimmediately on startup
9. Auto-Import from Git
If a.engram/manifest.json file exists in the project directory, the plugin runs engram sync --import at startup. This loads any git-synced memory chunks into the local SQLite database — useful when cloning a repository that includes shared team memories.
10. Project Migration
If the project name derived at startup differs from the previous basename (e.g., after the git remote detection fix correctly identifies the repo name), the plugin calls/projects/migrate to move all stored data to the new project name:
Private Tag Stripping
Any content wrapped in<private>...</private> tags is stripped before being sent to engram. The replacement text is [REDACTED].
This stripping happens in the plugin (TypeScript) before the HTTP call, so sensitive content never hits the wire. As a second layer of safety, the engram Go binary also strips private tags on its end.
Engram Tools
The following tools are provided by the engram MCP server and are excluded from tool-call counting:Sub-Agent Session Suppression
subAgentSessions at session.created time. All subsequent hooks (chat.message, tool.execute.after, ensureSession) check this set and silently skip sub-agent sessions.
Dependency
The Engram plugin is distributed as part of this config. The@opencode-ai/plugin package (used for the Plugin type) is declared in package.json:
engram binary must be installed separately — see the MCP Servers page for installation details.