-
Notifications
You must be signed in to change notification settings - Fork 11.7k
Description
Feature hasn't been suggested before.
- I have verified this feature I'm about to request hasn't been suggested before.
Describe the enhancement you want to request
Feature Request
Problem
When OpenCode executes a tool (e.g., a bash command), it spawns a subprocess. That subprocess has no way to discover which OpenCode session triggered it. This makes it impossible for external systems — or even
the tool itself — to correlate their work back to a specific session.
Use Case
If you build tooling that wraps or extends OpenCode's tool execution (e.g., logging, metrics, multi-session orchestration), you need to know which session a tool invocation belongs to. Today, the only way to
attempt this is fragile heuristics like FIFO matching or content-based comparison, because the subprocess environment contains no session context.
Proposed Solution
Set environment variables on tool subprocesses before they are spawned:
OPENCODE_SESSION_ID— the session that triggered the tool callOPENCODE_TOOL_PART_ID(optional) — the part ID of the tool invocation within the message, for finer-grained correlation
This is a minimal, non-breaking change. Tools that don't need the information simply ignore the env vars.
Precedent
PR #12932 already propagates session context (as HTTP headers) for LLM requests. This proposal extends the same pattern to tool subprocess execution.