Skip to content

Add OpenCode plugin to match Claude Code hooks behavior#5

Draft
madisonbullard wants to merge 27 commits intoglommer:mainfrom
madisonbullard:oc-plugin
Draft

Add OpenCode plugin to match Claude Code hooks behavior#5
madisonbullard wants to merge 27 commits intoglommer:mainfrom
madisonbullard:oc-plugin

Conversation

@madisonbullard
Copy link

@madisonbullard madisonbullard commented Feb 26, 2026

This PR adds an OpenCode plugin to memelord that replicates the behavior of the existing Claude Code hooks, implemented as a standalone integration that shares no runtime code with the CC side. (Sharing code could happen in a future PR). The plugin is authored as a TypeScript file (packages/cli/src/opencode/plugin-template.ts) and installed by memelord init.

The four Claude Code hook behaviors are mapped to OpenCode primitives: memory injection on session.created, tool failure recording on tool.execute.after, per-turn transcript analysis on session.idle, and embed/decay/cleanup in a detached background process spawned from session.idle (ADR 0003). Because OpenCode exposes no reliable session-end event (akin to CC's Stop hook), the embed/decay work runs in a detached Node process with a 90-second delay and a latest-wins schedule token to avoid redundant or concurrent work (ADR 0004).

Tool failure detection uses the canonical ToolPart.state discriminated union — looking up the tool part by callID after each tool.execute.after call — rather than heuristic string scanning, handling both status: "error" (read, webfetch) and status: "completed" with non-zero metadata.exit (bash) (ADR 0008). Transcript analysis on session.idle runs fresh on every turn with no idempotency guard, mirroring CC's Stop hook behavior (ADR 0007).

The createEmbedder function is extracted into a dedicated memelord-embedder package so the SDK remains free of the @huggingface/transformers dependency, and the plugin imports it directly (ADR 0005). memelord init is updated to write the generated plugin file and a corresponding .opencode/package.json alongside the existing Claude Code and MCP setup steps.

Merging this will close #2.

Replaces the short-lived ADR 0005 optional-SDK-dep approach.
createEmbedder now lives exclusively in packages/embedder
(memelord-embedder), which has @huggingface/transformers as its sole
hard dependency. The SDK (memelord) no longer knows about or depends on
transformers. The CLI re-exports createEmbedder from memelord-embedder;
the OpenCode plugin template imports it from memelord-embedder directly.

ADR 0005 and OPENCODE_PLUGIN_PLAN.md updated to reflect the new layout.
Copy the OpenCode plugin template into dist during build so the bundled CLI can generate .opencode/plugins/memelord.ts. Add an init regression test and mark Phase 6.5 complete in the plan.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenCode plugins (hooks)

1 participant