OpenCode plugin that auto-starts the agentmemory backend with health-check supervision.
- OpenCode V2 (
opencode2) - Node.js ≥ 18.0.0 for the plugin itself; the agentmemory 0.9.30 backend requires Node.js ≥ 20.0.0
- agentmemory backend (auto-installed via
npx @agentmemory/agentmemoryif not present)
V1 users: OpenCode V1 (
opencode1.x) is no longer supported as of v4.0.0 — pinopencode-agentmemory-launcher@^3if you still need V1.
Note: This plugin has only been tested on Windows 11. If you need support for other platforms, pull requests are welcome.
This plugin automatically starts the agentmemory backend (REST API + iii-engine) when OpenCode loads its configuration. It runs once per OpenCode process and health-checks the backend every 60 seconds, restarting it if the process dies.
Built for agentmemory 0.9.30 (2026-10-06) and backward compatible with earlier releases:
- Auth is on by default. agentmemory generates a secret into
~/.agentmemory/secreton first start. The launcher only calls the always-public/agentmemory/livez, so it needs no secret and is unaffected. Hand-written REST calls to:3111now needAuthorization: Bearer $(cat ~/.agentmemory/secret). - iii-engine 0.22.1. agentmemory 0.9.30 moved its engine pin from
0.11.2to0.22.1and enforces it. The launcher does not manage the engine (the agentmemory CLI does), but a mismatched pin now exits the CLI with code 1 — the launcher surfaces that as awarn. - Newest version wins. On Windows the launcher starts the newest agentmemory it can find in the npx cache or a global install on
PATH, sonpm i -g @agentmemory/agentmemory@latesttakes effect without clearing the npx cache.
Add to your OpenCode config (plugins, plural):
OpenCode will automatically install the package at startup. See the V2 plugins guide for more details.
Place the plugin file in .opencode/plugins/:
.opencode/plugins/
└── agentmemory-launcher.ts
Files in this directory are automatically loaded at startup.
- Download
agentmemory-launcher.tsfrom the latest GitHub Release - Place it in
.opencode/plugins/:
.opencode/plugins/
└── agentmemory-launcher.ts
OpenCode loads .ts files from .opencode/plugins/ automatically at startup.
This launcher starts the agentmemory backend. To use agentmemory with OpenCode, also install the agentmemory plugin and refer to the OpenCode agentmemory plugin usage guide for setup instructions, available tools, and configuration options.
To update agentmemory to the latest version:
npx @agentmemory/agentmemory upgradeIf you installed agentmemory globally, update that copy instead with npm i -g @agentmemory/agentmemory@latest — the launcher picks the newest version across the npx cache and global installs.
After updating, stop the running agentmemory process and clear the npx cache:
Windows (PowerShell):
# Stop the agentmemory process
Get-Process -Name "node" | Where-Object {
(Get-CimInstance Win32_Process -Filter "ProcessId = $($_.Id)").CommandLine -match 'agentmemory'
} | Stop-Process -Force
# Clear the npx cache
Get-ChildItem "$env:LOCALAPPDATA\npm-cache\_npx" -Directory | Where-Object {
Test-Path "$($_.FullName)\node_modules\@agentmemory"
} | Remove-Item -Recurse -ForceRestart OpenCode to relaunch agentmemory with the updated version.
- On load (
setup()): the plugin starts a health-check interval (60s) - Health check: Pings
GET /agentmemory/livezon the backend (always public, no auth — even with agentmemory 0.9.30's auth-by-default) - Auto-restart (two-mode): If the health check fails, the backend is launched.
- Startup (backend down when the plugin loads): opens a visible Windows Terminal tab titled
agentmemory(wt -w 0 nt --title agentmemory --suppressApplicationTitle node <cli>) — Windows Terminal launchesnodeitself, so no cmd/pwsh shell is involved. The backend coming up is visible; focus is taken once here — acceptable at startup, and never on the recovery path. Falls back to the silent path whenwt.exeis unavailable. - Recovery (every later (re)launch from the 60s loop): fully silent. On Windows the plugin bypasses npx/cmd entirely — it resolves the newest
dist/cli.mjsit can find in the npm/npx cache or a global install onPATH, and spawnsnodedirectly on it, so the process tree (node → cli.mjs → iii.exe) never touches cmd.exe and never allocates a console: no window/tab and no focus steal, mid-session or while idle (plainwindowsHideis insufficient because every cmd.exe hop lets a grandchild allocate a new console). Falls back to an npx spawn when no local copy is found. Relaunches are throttled by a 90s boot grace window plus a cross-instance launch lock (multiple OpenCode servers share one backend)
- Startup (backend down when the plugin loads): opens a visible Windows Terminal tab titled
- Debug mode: Set
OPENCODE_AGENTMEMORY_DEBUG=1for verbose logging - Failure diagnostics: A backend launch that exits with a non-zero code is logged at
warnwith the likely causes — a daemon already answering on the port (agentmemory 0.9.30 refuses to start a second instance) or the enforced iii-engine pin mismatch. A visible startup tab whose process exits with a non-zero code stays open (Windows Terminal'scloseOnExit: graceful) so the error text remains readable
| Variable | Default | Description |
|---|---|---|
AGENTMEMORY_URL |
http://localhost:3111 |
Backend API URL |
OPENCODE_AGENTMEMORY_DEBUG |
unset | Set to 1 for debug logging |
The backend never comes up and the log shows a non-zero launch exit.
Two common causes: agentmemory 0.9.30 enforces its iii-engine pin (v0.22.1), so a different engine on PATH makes the CLI exit with code 1; or a stale instance still owns the port. Run it manually to see the actual error:
npx @agentmemory/agentmemory doctorA visible startup tab shows agentmemory worker did not become ready within 15s and exits with code 1.
A stale instance from an earlier session is still holding the REST port, so the fresh CLI starts its engine but its worker registration never becomes ready — a healthy fresh start completes in ~2s. Diagnose and restart the whole chain (never kill a single worker process: it may be the active route handler, and killing it makes /agentmemory/livez return 404):
Get-NetTCPConnection -LocalPort 3111 -State Listen # who owns the port
npx @agentmemory/agentmemory stop # stop the instance it belongs to
# if that leaves the port held, stop the engine + worker pair together and
# let the launcher's supervision loop relaunch them (~60s, silently)A newer agentmemory is installed but the launcher keeps running an older one. The launcher prefers the newest version across the npx cache and global installs; if a stale copy still wins, clear the cache:
npx clear-npx-cacheThe plugin targets the OpenCode V2 plugin API (@opencode/plugin >= 2.0.18). Supervision starts in setup() when the plugin loads, and the returned cleanup function stops the health-check loop on unload.
import type { Plugin } from "@opencode/plugin";
const plugin: Plugin = {
id: "agentmemory-launcher",
setup: async (ctx) => {
// start supervision; return cleanup
},
};
export default plugin;# Install dependencies
npm install
# Type-check
npm run typecheck
# Build
npm run build
# Run tests
npm testGNU Affero General Public License v3.0
Copyright (C) 2026 Cle2ment.
{ "plugins": ["opencode-agentmemory-launcher@latest"] }