feat(plugin): add shell.env hook for manipulating environment in tools and shell (#12012)

This commit is contained in:
Tyler Gannon
2026-02-03 15:18:41 -06:00
committed by GitHub
parent 25bdd77b1d
commit a30696f9bf
5 changed files with 32 additions and 1 deletions

View File

@@ -192,6 +192,10 @@ Plugins can subscribe to events as seen below in the Examples section. Here is a
- `todo.updated`
#### Shell Events
- `shell.env`
#### Tool Events
- `tool.execute.after`
@@ -254,6 +258,23 @@ export const EnvProtection = async ({ project, client, $, directory, worktree })
---
### Inject environment variables
Inject environment variables into all shell execution (AI tools and user terminals):
```javascript title=".opencode/plugins/inject-env.js"
export const InjectEnvPlugin = async () => {
return {
"shell.env": async (input, output) => {
output.env.MY_API_KEY = "secret"
output.env.PROJECT_ROOT = input.cwd
},
}
}
```
---
### Custom tools
Plugins can also add custom tools to opencode: