Skip to content

About

A OpenCode plugin that auto-starts the agentmemory backend with health-check supervision.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

2 stars

Watchers

0 watching

Forks

Agentmemory Launcher for OpenCode

OpenCode plugin that auto-starts the agentmemory backend with health-check supervision.

npm version License Node.js CI

English | 中文 | Français

Requirements

  • OpenCode V2 (opencode2)
  • Node.js ≥ 18.0.0
  • agentmemory backend (auto-installed via npx @agentmemory/agentmemory if not present)

V1 users: OpenCode V1 (opencode 1.x) is no longer supported as of v4.0.0 — pin opencode-agentmemory-launcher@^3 if 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.

What It Does

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.

Installation

From npm (recommended)

Add to your OpenCode config (plugins, plural):

{
  "plugins": ["opencode-agentmemory-launcher@latest"]
}

OpenCode will automatically install the package at startup. See the V2 plugins guide for more details.

From local file

Place the plugin file in .opencode/plugins/:

.opencode/plugins/
└── agentmemory-launcher.ts

Files in this directory are automatically loaded at startup.

Manual Installation (from GitHub Releases)

  1. Download agentmemory-launcher.ts from the latest GitHub Release
  2. Place it in .opencode/plugins/:
.opencode/plugins/
└── agentmemory-launcher.ts

OpenCode loads .ts files from .opencode/plugins/ automatically at startup.

Usage

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.

Updating

To update agentmemory to the latest version:

npx @agentmemory/agentmemory upgrade

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 -Force

Restart OpenCode to relaunch agentmemory with the updated version.

How It Works

  1. On load (setup()): the plugin starts a health-check interval (60s)
  2. Health check: Pings GET /agentmemory/livez on the backend (public, no auth)
  3. Auto-restart: If the health check fails, spawns the agentmemory CLI detached. On Windows the plugin bypasses npx/cmd entirely — it resolves dist/cli.mjs from the npx cache and spawns node directly on it, so the process tree (node → cli.mjs → iii.exe) never touches cmd.exe and never allocates a console: no terminal window/tab pops up and no focus is stolen (plain windowsHide is insufficient because every cmd.exe hop lets a grandchild allocate a new console). Falls back to an npx spawn when the cache is cold. Relaunches are throttled by a 90s boot grace window plus a cross-instance launch lock (multiple OpenCode servers share one backend)
  4. Debug mode: Set OPENCODE_AGENTMEMORY_DEBUG=1 for verbose logging

Environment Variables

Variable Default Description
AGENTMEMORY_URL http://localhost:3111 Backend API URL
OPENCODE_AGENTMEMORY_DEBUG unset Set to 1 for debug logging

API

The 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;

Development

# Install dependencies
npm install

# Type-check
npm run typecheck

# Build
npm run build

# Run tests
npm test

Community

License

GNU Affero General Public License v3.0

Copyright

Copyright (C) 2026 Cle2ment.

About

A OpenCode plugin that auto-starts the agentmemory backend with health-check supervision.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

2 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages