Skip to content

Feature: Add sessionID to experimental.chat.system.transform hook for tracing integration #6142

Closed as not planned

Description

@ramarivera

Summary

When building observability plugins (e.g., Langfuse, OpenTelemetry exporters), it's valuable to capture the full system prompt for each LLM request and associate it with the correct trace/session. The experimental.chat.system.transform hook provides access to the system prompt, but currently lacks the sessionID needed to correlate it with a specific session.

Current Behavior

In packages/opencode/src/session/llm.ts line ~65:

await Plugin.trigger("experimental.chat.system.transform", {}, { system })

The input object is empty {}, so plugins cannot determine which session the system prompt belongs to.

Proposed Change

Pass the sessionID in the input:

await Plugin.trigger("experimental.chat.system.transform", { sessionID: input.sessionID }, { system })

And update the type definition in packages/plugin/src/index.ts:

"experimental.chat.system.transform"?: (
  input: { sessionID: string },
  output: { system: string[] },
) => Promise<void>

Use Case

This enables tracing plugins to:

  1. Capture the full system prompt (including environment context, file tree, custom instructions)
  2. Associate it with the correct Langfuse trace or OpenTelemetry span
  3. Provide complete observability into what context the LLM received

Additional Context

I'm building a Langfuse exporter plugin for OpenCode. Currently I can capture:

  • Session events
  • User messages with content
  • Assistant responses with token usage
  • Tool calls with input/output

But the system prompt is missing from traces, which makes debugging and analysis incomplete.


Note: Similar issues were searched before filing. This report was created with AI assistance.

Activity

  1. github-actions commented on Dec 25, 2025

    @github-actions
    Contributor

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

    • Feature Request: Add Langfuse Tracing #219: Feature Request: Add Langfuse Tracing - This issue is about integrating Langfuse for tracing/observability in OpenCode, which is directly related to your use case of building a Langfuse exporter plugin.

    Feel free to ignore if this doesn't address your specific case.

  2. rekram1-node commented on Dec 25, 2025

    @rekram1-node
    Contributor

    sure pr welcome!

  3. thdxr commented on Mar 25, 2026

    @thdxr
    Member

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

  4. ngbrown commented on Apr 14, 2026

    @ngbrown

    Session ID is present in the following (at least with Opencode 1.4.3):

    import type { Plugin } from "@opencode-ai/plugin";
    
    const serviceName = "log-session";
    
    export const LogSession: Plugin = async ({ project, client }) => {
      return {
        "experimental.chat.system.transform": async (input, output) => {
          console.log("system messages", input.sessionID, output.system);
        },
      };
    };
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