Skip to content

OpenCode

Terminal window
agent-mem setup opencode --write

Copies the plugin to ~/.config/opencode/plugins/agent-mem.ts (with the absolute path of the command) and adds the MCP server to ~/.config/opencode/opencode.json:

{
"$schema": "https://opencode.ai/config.json",
"mcp": { "agent-mem": { "type": "local", "command": ["/Users/you/.local/share/uv/tools/agent-mem/bin/agent-mem", "mcp"], "enabled": true } }
}

XDG_CONFIG_HOME moves ~/.config.

OpenCode has no command hooks; it loads TypeScript plugins. agent-mem’s one file serves both OpenCode lines: OpenCode 2 calls its setup and streams events, OpenCode 1.x (the npm package) loads its default export and calls server(). Each event goes to agent-mem hook opencode <event> as JSON on stdin; the call is killed after 10 seconds, the same limit as the other agents’ hooks (on Windows one call took 2.3 to 3.2 s under virus scanning). Calls run one after another, so a session’s row exists before its first prompt is looked up.

EventSendsagent-mem does
first event of a sessionsession.startnew session
session.inbox.enqueued (a user item)chat.message with the promptnew turn
session.tool.success / session.tool.failedtool.after with name, input, output and exit code (0 or 1)record, recipes
session.text.ended—adds to the turn’s answer
session.execution.succeeded / failed / interruptedsession.idle with the answerclose the turn, start the observer

OpenCode 2’s plugin API has no hook before a tool and none that changes the system prompt, so there agent-mem records only: no briefing, no matches, no rule notes or deny. The search is still there through the MCP server. Each loaded location gets its own plugin instance; events of another location are skipped so a session is recorded once.

OpenCode hookSendsagent-mem does
event session.createdsession.startbriefing, held for the next model call
chat.messagechat.message with the prompt’s text parts (not synthetic ones)new turn, rules, matches
tool.execute.beforetool.beforerule note or deny (the plugin throws, which stops the tool), file history
tool.execute.aftertool.after with output and exit coderecord, recipes, fix hints
experimental.text.complete—remembers the turn’s last text
event session.idlesession.idle with that textclose the turn, start the observer
experimental.session.compactingsession.compactingthe compact block goes into the compaction prompt
experimental.chat.system.transform—adds held context to the system prompt of the next call

Any error resolves to “no context”; the only error the plugin throws on purpose is an enabled rule. Calls to agent-mem’s own tools are skipped.

OpenCode requests get facts from opencode run --standalone --agent plan --model opencode/big-pickle, a free model (observe.opencode_model). --standalone keeps the run off the shared OpenCode server, --agent plan keeps it read-only, and agent-mem’s own plugin skips it. See Providers and models.

  • No panel. OpenCode has no channel for a message to you.
  • No context in OpenCode 2 (see above); OpenCode 1.x gets it.
  • No token accounting. OpenCode’s work per request is not measured.

Tested with OpenCode 1.19 (npm, install script) and 2.2.