anomalyco / anomalyco/opencode
Plugin events miss session.created for sessions resumed via --session flag
@jlongster is already working on this.
Since Jul 30, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
When OpenCode is launched with --session <id> (or -s <id>) to resume an existing session from disk, the plugin lifecycle hooks never receive any event for that session. Plugins cannot detect the pane-to-session binding.
For sessions started fresh (opencode with no flags), session.created is emitted normally with the session id in the payload.
This is reproducible without any external dependencies — a 10-line plugin shows the issue.
Steps to reproduce
-
Save this plugin to
~/.config/opencode/plugins/debug-session-events.js:import fs from "node:fs"; const LOG = "/tmp/opencode-session-debug.log"; export const DebugSessionEvents = async () => { const append = (line) => { try { fs.appendFileSync(LOG, `[${new Date().toISOString()}] ${line}\n`); } catch {} }; fs.writeFileSync(LOG, ""); append("plugin loaded"); return { event: async ({ event }) => { append(`event: type=${event?.type} sessionID=${event?.properties?.sessionID ?? "(none)"}`); }, }; }; -
Start a fresh session:
rm /tmp/opencode-session-debug.log opencodeSend one message, then quit.
cat /tmp/opencode-session-debug.logshowssession.createdwith the session id. -
Resume the same session:
rm /tmp/opencode-session-debug.log opencode -s <id_from_step_2>Wait 5s, send one message, quit.
cat /tmp/opencode-session-debug.logshows nosession.created. Asession.updatedeventually fires but only after the first user message — it does not fire at startup.
Expected
Either:
session.createdshould fire at startup when a session is loaded from disk via-s/--session, OR- a new event like
session.attachedshould fire with the session id.
Actual
No event with the session id fires at startup for resumed sessions. The plugin only learns about the session after the first user message (and even then, the sessionID is sometimes missing from the payload — race condition between plugin init and OpenCode startup).
Environment
- OpenCode version: 1.18.10
- OS: Linux 6.14.0-37-generic
- Terminal: xterm-256color
Notes
Affected downstream: the herdr-agent-state integration plugin (v9) cannot detect resumed sessions because of this, leaving pane→session bindings missing in external tools. PR herdrdev/herdr#2062 attempted an argv-parsing workaround, but process.argv inside the bundled Bun runtime is ["bun", "/$bunfs/root/src/cli/tui/worker.js"] — the user-supplied -s <id> is not visible to the plugin.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.