anomalyco / anomalyco/opencode
[FEATURE]: Propagate session ID to tool subprocesses via environment variable
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- Avg merge
- 7h 2m
- Merged PRs (30d)
- 384
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.