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]: Expose session context to child processes via environment variables · Issue #9292 · anomalyco/opencode

[FEATURE]: Expose session context to child processes via environment variables #9292

New issue
Copy link
New issue
Copy link
Closed as not planned
Closed as not planned
[FEATURE]: Expose session context to child processes via environment variables#9292
Copy link
Assignees
thdxr
Labels
discussionUsed for feature requests, proposals, ideas, etc. Open discussion

Description

@klimkin
klimkin
opened on Jan 18, 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

Problem

User scripts and tools that are executed via opencode (bash tool, shell commands) have no way to identify which opencode session they're running in. This makes it difficult to correlate logs, metrics, and outputs when running multiple opencode sessions, such as in iterative workflows (e.g., Ralph loops).

Use Case

A user running a Ralph loop that spawns a new opencode session per iteration needs to log which session each iteration corresponds to. Currently, child processes spawned by opencode have no access to session metadata.

Solution

Expose session context to child processes via environment variables:

  • OPENCODE_SESSION_ID: The unique identifier of the current session (e.g., ses_xyz123)
  • OPENCODE_SESSION_TITLE: The human-readable title of the current session (e.g., "Fix bug in auth flow")
    These variables are set in two user-facing command execution contexts:
  1. Bash tool: When users execute commands via the bash tool
  2. Prompt shell: When commands are executed via direct shell invocation

Implementation Details

  • Environment variables are set dynamically per spawn (not globally at startup like AGENT and OPENCODE)
  • This is necessary because users can switch between sessions during interactive work
  • Session lookup includes graceful error handling to avoid breaking existing tests and mock contexts

Example Usage

#!/bin/bash
# User script can now access session context
echo "Running in session: $OPENCODE_SESSION_TITLE ($OPENCODE_SESSION_ID)" >> /var/log/opencode-iterations.log

This enables proper tracking and correlation of work across multiple concurrent or sequential opencode sessions.

Reacted by Santiago M. Mola, Jakub Sieczczyński, Shrey Sudhir and Sridhar Ratnakumar

Activity

  1. klimkin
    added
    discussionUsed for feature requests, proposals, ideas, etc. Open discussion
    on Jan 18, 2026
  2. github-actions
    assigned
    thdxr
    on Jan 18, 2026
  3. github-actions commented on Jan 18, 2026

    @github-actions
    github-actionsBot
    on Jan 18, 2026 – with GitHub Actions
    Contributor
    More actions

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

    • Feature: Pass session identifier to MCP servers #6279: Pass session identifier to MCP servers - Similar request to expose session context, but specifically for MCP servers rather than all child processes
    • [FEATURE]: Export actual server URL as environment variable #9099: Export actual server URL as environment variable - Related feature request for exposing server context via environment variables to child processes
    • [FEATURE]: Pass agents bash env variables OR pass agents bashrc files #6936: Pass agents bash env variables OR pass agents bashrc files - Addresses the related need for agents to access environment context from the parent shell

    Feel free to ignore if this specific feature request (session context for bash tool and shell commands) addresses a different use case than these existing issues.

  4. smola commented on Jan 31, 2026

    @smola
    smola
    on Jan 31, 2026
    More actions

    👍 I also have 2 strong use cases for OPENCODE_SESSION_ID:

    1. Improve telemetry of some tooling used by agents, by attaching the session ID to events.
    2. Commands whose output is optimized for use within agents, and can present more efficient output if they know what they have returned in previous invocations within the same session.
  5. tesdal commented on Feb 15, 2026

    @tesdal
    tesdal
    on Feb 15, 2026
    Contributor
    More actions

    With #13661 I guess it would be possible to enable this with your own plugin that populates env, if populating env is more controversial.

  6. jrswab commented on Feb 27, 2026

    @jrswab
    jrswab
    on Feb 27, 2026
    More actions

    +1 on this. I'm hitting the same limitation in practice.

    I regularly run multiple concurrent OpenCode sessions in the same project directory. My use case is linking work artifacts (commits, branches, logs) back to the specific session that produced them. Today, the only option from within a session is opencode session list -n 1, which returns the most recently updated session for the working directory. That's unreliable when multiple sessions are active simultaneously.

    Having OPENCODE_SESSION_ID (and OPENCODE_SESSION_TITLE) injected into Bash tool subprocesses would make this deterministic. It would also let the LLM itself programmatically interact with its own session via the server API (sharing, exporting, or renaming the session) without guessing which session it belongs to.

    Reacted by Santiago M. Mola and Aurélien Franky
  7. github-actions commented on Apr 29, 2026

    @github-actions
    github-actionsBot
    on Apr 29, 2026 – with GitHub Actions
    Contributor
    More actions

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

  8. github-actions
    closed this as not plannedon Apr 29, 2026
  9. wylswz commented on May 25, 2026

    @wylswz
    wylswz
    on May 25, 2026
    More actions

    +1. I'm working on an agent that creates pr to my repo and respond to discussions in the same session. I'm trying to wrap the gh cli that builds mapping between pr id and session id, however, it is impossible to do this currently. Having session id propagated would be really helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @thdxr
    thdxr

Labels

discussionUsed for feature requests, proposals, ideas, etc. Open discussion

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.