Skip to content

Plugin event listener for "session.created" not firing #14808

Closed

Description

@M4NZEN

Description

Plugins that subscribe to the event bus are not receiving the session.created event. The event is published but plugins don't respond.

Plugins

Custom plugin in ~/.config/opencode/plugins/engram.ts (Engram memory system)

OpenCode version

1.2.10

Steps to reproduce

  1. Create a plugin that listens to session.created via the event property
  2. Start a new OpenCode session
  3. Plugin doesn't receive the event

Screenshot and/or share link

Evidence: Engram does not activate automatically

Problem

According to AGENTS.md, mem_session_start should execute automatically at the start of each session.
But it doesn't happen - the user had to call it manually.

Log Evidence (opencode_session_created_bug.log)

Line 15 - Plugin loads:
INFO service=plugin path=...engram.ts loading plugin

Line 55 - MCP detected:
INFO service=mcp key=engram type=local found

Line 78 - MCP created:
INFO service=mcp key=engram toolCount=14 create() successfully created client

Lines 89-90 - ERRORS (here's the problem):
ERROR service=mcp clientName=engram error=MCP error -32601: prompts not supported
ERROR service=mcp clientName=engram error=MCP error -32601: resources not supported

Line 96 - OpenCode session created (without Engram):
INFO service=session id=ses_... created

Line 329 - ONLY HERE mem_session_start is called (manual):
INFO service=permission permission=engram_mem_session_start pattern=* ... evaluated

Conclusion

  1. Engram plugin loads
  2. There are MCP errors (prompts/resources not supported)
  3. OpenCode session is created
  4. mem_session_start is NEVER executed automatically
  5. It only executes when the user calls it manually (line 329)

Possible Cause

The -32601 errors on lines 89-90 suggest that the Engram plugin does not support
some MCP methods that OpenCode expects, wh

Operating System

ubuntu 22

Terminal

Alacritty

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Feb 23, 2026
  2. fidelix commented on Mar 8, 2026

    @fidelix
  3. zjjott commented on Mar 11, 2026

    @zjjott

    +1

  4. added 2 commits that reference this issue on Mar 13, 2026
    9b8acb3
    b6e67fe
  5. zahidinho commented on Mar 23, 2026

    @zahidinho

    +1

  6. mikij commented on Mar 28, 2026

    @mikij

    +1 cmon, we need this ASAP

  7. onedaxter commented on Mar 28, 2026

    @onedaxter

    +1

  8. CODLOP commented on Mar 28, 2026

    @CODLOP

    +1

  9. debanjanbasu commented on Mar 29, 2026

    @debanjanbasu

    +1

  10. TheOrdinaryWow commented on Apr 2, 2026

    @TheOrdinaryWow

    +1

  11. Drumpy commented on Apr 8, 2026

    @Drumpy

    +1

  12. kazablock commented on Apr 15, 2026

    @kazablock

    +1

  13. tarurar commented on Apr 18, 2026

    @tarurar

    +1

  14. jfortez commented on Apr 20, 2026

    @jfortez

    +1

  15. pratikthapw commented on Apr 21, 2026

    @pratikthapw

    +1

  16. lbzepoqo commented on Apr 23, 2026

    @lbzepoqo

    +1

  17. pumicestone commented on Apr 23, 2026

    @pumicestone

    +1

  18. AbdelrhmanUZaki commented on Apr 24, 2026

    @AbdelrhmanUZaki

    Hey everyone! 👋 While we wait for the official fix to get merged, I built a workaround plugin opencode-enforce-context-mode so you can still use context-mode properly despite the session.created bug.

    It solves the problem using two steps:

    1. Proactive Guidance: It bypasses the broken hook by using experimental.chat.messages.transform to inject the environment constraints directly into the first user message, so the AI knows to use ctx_* tools immediately.

    2. Aggressive Enforcement: If the AI still attempts to run a forbidden native command (like grep or curl), it gets blocked by a fatal system directive that forces immediate compliance and redirects it to the correct context-mode alternative.

  19. markg85 commented on Apr 25, 2026

    @markg85

    Just a friendly ping. Is #17517 ready to merge and fix this? Or is there something that still needs to be fixed beyond that?

    Just asking because I'd like to play with that context-mode plugin but i kinda feel it becomes a messy situation if i need another plugin just to workaround a bug.

  20. assigned and unassigned on Apr 26, 2026
  21. removed
    bugSomething isn't working
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  22. techieanant commented on May 3, 2026

    @techieanant

    +1

  23. rekram1-node commented on May 4, 2026

    @rekram1-node
    Collaborator
    import type { PluginModule } from "@opencode-ai/plugin"
    
    export default {
      id: "local.session-created-toast",
      async server(input) {
        return {
          async event({ event }) {
            if (event.type !== "session.created") return
    
            await input.client.tui.showToast({
              body: {
                title: "My message",
                message: "My body",
                variant: "success",
                duration: 5000,
              },
              throwOnError: true,
            })
          },
        }
      },
    } satisfies PluginModule
    
    

    I cannot replicate this issue, here is an example plugin, the toast does fire when new sessions are created.


    If someone can send me minimal repro or show how this doesnt work for them ill reopen

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