GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [FEATURE]: Propagate session ID to tool subprocesses via environment variable · Issue #15739 · anomalyco/opencode

[FEATURE]: Propagate session ID to tool subprocesses via environment variable #15739

New issue
Copy link
New issue
Copy link
Closed
Closed
[FEATURE]: Propagate session ID to tool subprocesses via environment variable#15739
Copy link
Assignees
jlongster

Description

@jlguerreiro
jlguerreiro
opened on Mar 2, 2026
Issue body actions

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 call
  • OPENCODE_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.

Reacted by Santiago M. Mola, Shrey Sudhir and Thomas Decaux

Activity

  1. jlguerreiro
    added
    discussionUsed for feature requests, proposals, ideas, etc. Open discussion
    on Mar 2, 2026
  2. github-actions
    assigned
    thdxr
    on Mar 2, 2026
  3. github-actions
    added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Mar 2, 2026
  4. github-actions commented on Mar 2, 2026

    @github-actions
    github-actionsBot
    on Mar 2, 2026 – with GitHub Actions
    Contributor
    More actions

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

    • [FEATURE]: Expose session context to child processes via environment variables #9292: [FEATURE]: Expose session context to child processes via environment variables — same request to set OPENCODE_SESSION_ID on bash tool/shell subprocesses
    • [FEATURE]: Expose session context to MCP servers via environment variables #15117: [FEATURE]: Expose session context to MCP servers via environment variables — extends the same idea to MCP servers, and references [FEATURE]: Expose session context to child processes via environment variables #9292 as prior art

    If your request is distinct from those, please clarify how it differs.

  5. jlguerreiro
    added a commit that references this issue on Mar 2, 2026

    feat: propagate session ID to tool subprocesses

    This issue will close once commit f109a1c is merged into the 'dev' branch.
    f109a1c
  6. taxilian commented on Apr 9, 2026

    @taxilian
    taxilian
    on Apr 9, 2026
    More actions

    #21756 would make it possible to have a plugin do this

  7. thdxr
    assigned
    jlongster
    and unassigned
    thdxr
    on Apr 26, 2026
  8. thdxr
    removed
    discussionUsed for feature requests, proposals, ideas, etc. Open discussion
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  9. XJfyrh commented on Aug 3, 2026

    @XJfyrh
    XJfyrh
    on Aug 3, 2026
    More actions

    This request would also directly prevent a class of correctness bugs I hit with concurrent sessions. Posting here rather than opening a duplicate issue, since this is the same root cause.

    Real-world failure caused by the missing env var
    I ran two opencode sessions in parallel, one per project directory (proj-a/ and proj-b/). Both agents created a temporary helper script with the same generic name (gen_appendix.py) in the shared pre-approved temp directory (%TEMP%\opencode).

    Because there is no session identifier available in the subprocess environment, the agent could not name its scratch file uniquely. Session B overwrote the file while session A was still using it; session A then executed session B's script content (different paths, different logic) and wrote its output into the wrong project directory. The corruption was only caught because the script happened to print the output path.

    Why this matters beyond external-tool correlation
    The issue body frames OPENCODE_SESSION_ID as a need for external tooling (logging, orchestration). My case shows the env var is also needed for agent-internal correctness: an agent cannot isolate its own scratch files across concurrent sessions without it. That makes this a reliability/feature-availability gap, not just an observability nicety.

    Concrete benefit if implemented
    Agents could name temp files as ${OPENCODE_SESSION_ID} (or use a session-scoped dir such as %TEMP%\opencode<session-id>), eliminating last-writer-wins collisions entirely. This matches the project's own pattern of unique names in the tool-output store (e.g. tool).

    Happy to provide more details or test once implemented.

    Reacted by Thomas Decaux
  10. ebuildy commented on Sep 22, 2026

    @ebuildy
    ebuildy
    on Sep 22, 2026
    More actions

    I have just found this bug too, tmp files are shared across sessions !!! 1 session create a file, other session overrides it ..... this is so dangerous.

    Any news about it?

  11. rekram1-node commented on Sep 29, 2026

    @rekram1-node
    rekram1-node
    on Sep 29, 2026
    Member
    More actions

    Implemented for the shell-tool subprocesses in #51975: commands (including background commands) receive OPENCODE_SESSION_ID from the current tool session, replacing any stale inherited value. Child processes launched by those commands inherit it. This does not inject the ID into arbitrary plugin subprocesses or provide the optional OPENCODE_TOOL_PART_ID.

  12. rekram1-node
    closed this as completedon Sep 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @jlongster
    jlongster

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

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.