Skip to content

[FEATURE]: Expose prompt/output message bodies to plugin chat.message hook #22831

Closed as not planned

Description

@michael-schienbein-fhr

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request hasn't been suggested before.

Note on #17637: That issue requests user message text in experimental.chat.system.transform for targeted context injection. This issue is related but distinct — it requests that the already-firing chat.message hook populate its parts array with actual prompt/output text, enabling telemetry and observability use cases (not system prompt manipulation). #17637 was closed as not planned, but the underlying need remains: plugins currently cannot access message bodies through any hook.

Describe the enhancement you want to request

Summary

The chat.message plugin hook fires correctly, but the runtime delivers an empty parts array in the payload. This prevents plugins from capturing prompt or assistant response text for telemetry, observability, and audit use cases — even though the hook itself is invoked and tool args/results flow through fine.

What we observed

We built a telemetry plugin that instruments all available hooks (chat.message, experimental.chat.messages.transform, experimental.text.complete) and added diagnostic shadow logging for chat.message payloads.

Across 4 systematic test passes:

  • chat.message does fire — 3 shadow log entries confirmed
  • Payload shape: { sessionID, agent, model, messageID, variant } — metadata only
  • parts is always an empty array (partsPreview: [])
  • promptsCaptured and outputsCaptured counters stayed at 0 until we added fallback capture via assistant event metadata
  • No hook failures occurred — the plumbing works, but the content is withheld
  • Tool args/results are available and rich via tool event hooks, confirming the plugin system itself is functional

What we want changed

Populate parts in the chat.message hook payload with the actual message content (user prompt text for user messages, assistant response text for assistant messages). This would allow plugins to:

  1. Capture prompt/output text for enterprise telemetry and audit trails
  2. Build observability dashboards that include conversation content (with plugin-side redaction)
  3. Implement content-aware plugin behaviors (summarization, compliance scanning, etc.)

Why this is different from #17637

#17637 This issue
Hook experimental.chat.system.transform chat.message
Goal Inject context into system prompt based on user message Capture message bodies for telemetry/audit
Timing Needs content before LLM call Content after hook fires is fine
Use case Memory/RAG injection Observability/telemetry

Environment

  • OpenCode version: 1.4.3
  • Plugin API: @opencode-ai/[email protected]
  • Tested in a real workspace session with a custom telemetry plugin across 4 diagnostic passes

Evidence available

We have sanitized shadow log payloads, collector metrics showing the empty-parts pattern, and a full diagnostic writeup. Happy to share if helpful.

Activity

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

    @github-actions
    Contributor

    This issue doesn't fully meet our contributing guidelines.

    What needs to be fixed:

    • No issue template was used. Please resubmit using one of the three required templates: Bug Report, Feature Request (title must start with [FEATURE]:), or Question. This issue appears to be a bug report or feature request — pick the most appropriate template and fill in the required fields.

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


    This issue might be a duplicate of or closely related to existing issues. Please check:

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

  3. changed the title [-]Plugin chat.message hook fires with empty parts, blocking prompt/output capture[/-] [+][FEATURE]: Expose prompt/output message bodies to plugin chat.message hook[/+] on Apr 16, 2026
  4. github-actions commented on Apr 16, 2026

    @github-actions
    Contributor

    Thanks for updating the issue! It now follows the contributing guidelines — the Feature Request template is properly filled out with a clear description, environment details, and evidence of testing. The needs:compliance label has been removed.

  5. removed
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  6. doobidoo commented on May 23, 2026

    @doobidoo

    We can confirm the empty-parts pattern from the plugin side. While building the MCP Memory Service plugin for OpenCode, we traced through the plugin loader source (packages/opencode/src/plugin/index.ts) and found that chat.message is not triggered at all in some builds — the trigger("chat.message", ...) call site doesn't exist in the session processor.

    Workaround: use the event hook with bus subscription to listen for message.part.updated bus events. These carry the full text content in event.properties.part.text for TextPart and ReasoningPart objects.

    Working plugin (820 lines, zero external deps): https://github.com/doobidoo/mcp-memory-service/blob/main/opencode/memory-plugin.js

    Hooks we use:

    • event — catches message.part.updated, session.created, session.deleted
    • experimental.chat.system.transform — memory injection into system prompt
    • experimental.session.compacting — memory preservation

    Also opened #29022 with more context.

  7. github-actions commented on Jul 23, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

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