Skip to content

Conversation

@tylergannon
Copy link
Contributor

@tylergannon tylergannon commented Feb 3, 2026

The motivation for this PR is the desire to run a single opencode server that can run against an arbitrary number of projects, and provide a different environment to tools run within each. At present this can be done by informing the agent that it should, e.g., load .env or wrap calls in a doppler utility, but this is error prone and adds more things for the LLM to think about.

FWIW I'm shy about proposing a change to your plugin system so not at all concerned if this should go through some design critique from you guys before it totally fits your expectations.

What does this PR do?

Introduces a shell.env plugin hook that allows a plugin to introduce environment variables that will be added to the env for (1) llm tool calls, (2) shell mode !command, and (3) PTY terminals.

I purposely avoided hooking into instance-level caching for three reasons:

  • Preference for not making secrets into part of opencode's application state
  • Preference for leaving whether or not to cache values up to the plugin implementation
  • Preference for minimizing LOC touched on this PR

How did you verify your code works?

  1. Ran the pre-commit hooks
  2. Created a temporary / bs tool that adds a single shell.env and ran bun dev .
export const TestShellEnvPlugin = async () => {
  return {
    "shell.env": async (input, output) => {
      output.env.PLUGIN_TEST_VAR = "it_works_456"
    },
  }
}

The screenshot below confirms that LLM tool calls contain the injected variable and so do !command commands

Screenshot 2026-02-03 at 2 40 26 PM

Closes #12018

@github-actions
Copy link
Contributor

github-actions bot commented Feb 3, 2026

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 3, 2026

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

@rekram1-node
Copy link
Collaborator

/review

@github-actions
Copy link
Contributor

github-actions bot commented Feb 3, 2026

lgtm

@rekram1-node rekram1-node merged commit a30696f into anomalyco:dev Feb 3, 2026
6 checks passed
@tylergannon
Copy link
Contributor Author

TY!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: shell.env plugin hook for environment variable injection

2 participants