feat(plugin): add shell.env hook for manipulating environment in tools and shell #12012
+32
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.envplugin 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:
How did you verify your code works?
shell.envand ranbun dev .The screenshot below confirms that LLM tool calls contain the injected variable and so do
!commandcommandsCloses #12018