-
Notifications
You must be signed in to change notification settings - Fork 14.5k
Feature: Add sessionID to experimental.chat.system.transform hook for tracing integration #6142
Description
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:
- Capture the full system prompt (including environment context, file tree, custom instructions)
- Associate it with the correct Langfuse trace or OpenTelemetry span
- 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.