Skip to content

bug: plugins are loaded twice #3179

Closed
Closed

Description

@AndrewBarba

Problem

Plugins are loaded twice and event handlers are fired twice.

OpenCode 0.15.2

Steps

Create a basic plugin:

import type { Plugin } from "@opencode-ai/plugin"

export const PreAcceptPlugin: Plugin = async ({ client }) => {
  return {
    async event({ event }) {
      switch (event.type) {
        case "session.idle": {
          await client.tui.showToast({
            body: { title: "[debug] event", message: event.type, variant: "info" },
          })
          break
        }
        default: {
          break
        }
      }
    },
  }
}

Send any message and when done processing you will see the toast show up two times.

Here is a simple working fix:

import type { Plugin } from "@opencode-ai/plugin"

let loaded = false

export const PreAcceptPlugin: Plugin = async ({ client }) => {
  if (loaded) return {}
  loaded = true

  return {
    async event({ event }) {
      switch (event.type) {
        case "session.idle": {
          await client.tui.showToast({
            body: { title: "[debug] event", message: event.type, variant: "info" },
          })
          break
        }
        default: {
          break
        }
      }
    },
  }
}

Activity

  1. self-assigned this
    on Oct 14, 2025
  2. rekram1-node commented on Oct 14, 2025

    @rekram1-node
    Contributor

    @AndrewBarba I can't replicate your issue, can you run opencode debug config and show me the output?

    Maybe there are global plugins also firing?

  3. AndrewBarba commented on Oct 14, 2025

    @AndrewBarba
    Author

    Ah interesting, listed twice even though my opencode.json only has it once:

    {
      "$schema": "https://opencode.ai/config.json",
      "theme": "opencode",
      "autoshare": false,
      "autoupdate": true,
      "model": "vercel/openai/gpt-5",
      "plugin": [
        "file:///Users/andrewbarba/Code/Lunara/bot/.opencode/plugin/preaccept.ts",
        "file:///Users/andrewbarba/Code/Lunara/bot/.opencode/plugin/preaccept.ts"
      ],
      "mcp": {
        "mcp-server": {
          "type": "local",
          "command": [
            "bun",
            "run",                                                                                                                                                                                      "./src/process/mcp.ts"
          ],
          "environment": {},
          "enabled": true
        }
      },
      "agent": {},                                                                                                                                                                                "mode": {},
      "command": {},
      "username": "andrewbarba"
    }
    

    opencode.json:

    {
      "$schema": "https://opencode.ai/config.json",
      "model": "vercel/openai/gpt-5",
      "autoupdate": true,
      "plugin": ["./.opencode/plugin/preaccept.ts"],
      "mcp": {
        "mcp-server": {
          "type": "local",
          "command": ["bun", "run", "./src/process/mcp.ts"],
          "enabled": true,
          "environment": {}
        }
      }
    }
    

    I guess plugins dir loaded automatically?

  4. rekram1-node commented on Oct 14, 2025

    @rekram1-node
    Contributor

    @AndrewBarba yes plugins dir is loaded automatically

  5. rekram1-node commented on Oct 14, 2025

    @rekram1-node
    Contributor

    we can add a check to not double it though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions