Skip to content

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

Closed

Description

@taxilian

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.

Activity

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

    @github-actions
    Contributor

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

    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.

  3. github-actions commented on Mar 30, 2026

    @github-actions
    Contributor

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

  4. taxilian commented on Apr 9, 2026

    @taxilian
    Author

    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

  5. Mart-Bogdan commented on Sep 13, 2026

    @Mart-Bogdan

    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

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