anomalyco / anomalyco/opencode

Plugin events miss session.created for sessions resumed via --session flag

Open
#39,711 2 comments 1 reaction 1 assignee View on GitHub

@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

  1. 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)"}`);
        },
      };
    };
    
  2. Start a fresh session:

    rm /tmp/opencode-session-debug.log
    opencode
    

    Send one message, then quit. cat /tmp/opencode-session-debug.log shows session.created with the session id.

  3. 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.log shows no session.created. A session.updated eventually fires but only after the first user message — it does not fire at startup.

Expected

Either:

  • session.created should fire at startup when a session is loaded from disk via -s/--session, OR
  • a new event like session.attached should 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.