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 — feat(bash): add env parameter for setting environment variables · Issue #11065 · anomalyco/opencode

feat(bash): add env parameter for setting environment variables #11065

New issue
Copy link
New issue
Copy link
Closed
Closed
feat(bash): add env parameter for setting environment variables#11065
Copy link
Assignees
thdxr
Labels
discussionUsed for feature requests, proposals, ideas, etc. Open discussion

Description

@taxilian
taxilian
opened on Jan 29, 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

Issue Description

Problem

Plugins cannot inject environment variables into bash commands. There are a number of current feature requests which could be done with plugins if that was allowed, and it's a cheap / low risk fix.

Use Case

I want to build a plugin that sets AGENT_MODE=primary|secondary and AGENT_ID=<session_id> on all bash commands. This allows tracking whether commands run in the main agent or subagent sessions, as well as letting me keep track of some state in an external tool.

Currently, the only workaround is prepending VAR=value to commands, which is hacky and unreliable.

Proposed Solution

Add an optional env parameter to the bash tool that accepts a record of environment variables to set for the spawned process.

Example Usage

"tool.execute.before": async (input, output) => {
  if (input.tool !== "bash") return

  const session = await ctx.client.getSession(input.sessionID)
  const isSubagent = session?.parentID != null

  output.args.env = {
    AGENT_MODE: isSubagent ? "secondary" : "primary",
    AGENT_ID: input.sessionID,
  }
}

Implementation

  • Add env: z.record(z.string(), z.string()).optional() to bash tool schema
  • Merge env vars with process.env in spawn call
  • Add tests for single and multiple environment variables

This would also allow issues like #10247 to be done in a plugin, thus reducing the need for specialized niche things in opencode.

Reacted by Kelvin Rosado, Santiago M. Mola, Kornel and Aurélien Franky

Activity

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

    @github-actions
    github-actionsBot
    on Jan 29, 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 - requests exposing OPENCODE_SESSION_ID and session metadata via env vars
    • [FEATURE]: Pass agents bash env variables OR pass agents bashrc files #6936: [FEATURE]: Pass agents bash env variables OR pass agents bashrc files - requests ability to pass environment variables or bashrc to bash commands
    • [FEATURE]: create and expose model-id environment variables for bash from CLI #10453: [FEATURE]: create and expose model-id environment variables for bash from CLI - requests exposing model information via environment variables

    While these issues have different specific use cases, they all request the ability to set/inject environment variables for bash commands. Your proposal for an env parameter in the bash tool schema would be a general solution that could address all of these needs.

    Feel free to ignore if your specific implementation is sufficiently different from these existing requests.

  4. github-actions commented on Mar 30, 2026

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

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

  5. github-actions
    closed this as completedon Mar 30, 2026
  6. taxilian commented on Apr 9, 2026

    @taxilian
    taxilian
    on Apr 9, 2026
    Author
    More actions

    I love it how this closes it but when you open a new one you have to promise it hasn't been suggested before... but it has been, it was just automatically closed

    Reacted by Jerome Flesch and Roman Kováč
  7. Mart-Bogdan commented on Sep 13, 2026

    @Mart-Bogdan
    Mart-Bogdan
    on Sep 13, 2026
    More actions

    DAMN! This is really needed feature!

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.