Skip to content

Feature: Include user message text in experimental.chat.system.transform input #17637

Closed as not planned

Description

@ttimbrook2018

Problem

The experimental.chat.system.transform hook currently receives { sessionID, model } in its input, but does not include the user's message text. This makes it impossible for plugins to do targeted context injection based on the user's current prompt.

Use Case

I've built a memory recall plugin that automatically injects relevant context from a persistent knowledge base into the system prompt. The ideal flow:

  1. User types a message about topic X
  2. system.transform hook reads the message
  3. Plugin queries the knowledge base for topic X
  4. Plugin pushes relevant context into output.system
  5. The LLM sees the context on the same turn the user asked about it

Currently, the user's message text is only available in chat.message which fires after system.transform, so the targeted context can only be injected on the next turn.

Current Workaround

Two-phase approach:

  • Phase 1 (session.created): Broad recall using project name
  • Phase 2 (chat.message): Captures user text, does targeted recall, rewrites an instructions file that OpenCode re-reads on the next turn

This means turn 1 gets generic context and turn 2+ gets targeted context. Works but adds a one-turn delay.

Proposed Change

Include the user's message content in system.transform input:

await Plugin.trigger("experimental.chat.system.transform", {
  sessionID: input.sessionID,
  model: input.model,
  userMessage: currentUserMessage,  // add this
}, { system });

Or include the full messages array:

await Plugin.trigger("experimental.chat.system.transform", {
  sessionID: input.sessionID,
  model: input.model,
  messages: msgs,  // the messages being sent to the LLM
}, { system });

Verification

Confirmed via strings analysis of the OpenCode 1.2.26 binary that:

  • experimental.chat.system.transform exists and fires during prompt construction
  • chat.message exists and fires after system prompt is built
  • The user message is available in memory at system.transform time but isn't passed to the hook

Environment

  • OpenCode 1.2.26
  • Plugin: TypeScript, uses event + chat.message + experimental.chat.system.transform hooks
  • Use case: Persistent memory integration (cognitive-stack with vector store + knowledge graph)

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Mar 15, 2026
  2. github-actions commented on Mar 15, 2026

    @github-actions
    Contributor

    This issue doesn't fully meet our contributing guidelines.

    What needs to be fixed:

    • Feature requests must use the feature request template, which requires: a title starting with [FEATURE]:, and a verification checkbox confirming the feature hasn't been suggested before.

    Please edit this issue to address the above within 2 hours, or it will be automatically closed.


    This issue might be a duplicate of existing issues. Please check:

    If you believe this was flagged incorrectly, please let a maintainer know.

  3. github-actions commented on Mar 15, 2026

    @github-actions
    Contributor

    This issue has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

    Feel free to open a new issue that follows our issue templates.

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

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions