@dragonwize/opencode-event-shell-execOpenCode plugin that executes shell commands when configured events are triggered.
0
11
近 7 天 1
18.8
生态多维模型
4 个月前
2026-03-26
快速安装与配置
opencode.json写入当前项目的 opencode.json,只对这个仓库生效。
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["@dragonwize/opencode-event-shell-exec@0.1.0"]
}写入 ~/.config/opencode/opencode.json,对所有项目生效。
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["@dragonwize/opencode-event-shell-exec@0.1.0"]
}若你要在本地改造这个插件,先装到项目里再从本地路径引用。
shell
pnpm add -D @dragonwize/opencode-event-shell-execopencode 启动时会通过内嵌运行时自动加载 npm 依赖并缓存至本地目录,无需手动在全局环境执行安装。
OpenCode plugin that executes shell commands when configured events are triggered.
Installation
Add the plugin to your opencode.json:
{
"plugin": ["@dragonwize/opencode-event-shell-exec"]
}
Configuration
Create an opencode-event-shell-exec.json file in either (or both) of these locations:
| Location | Path | Scope |
|---|---|---|
| Global | ~/.config/opencode/opencode-event-shell-exec.json |
All projects |
| Project | <project-root>/opencode-event-shell-exec.json |
Single project |
Both files are optional. When both exist, command arrays for the same event pattern are concatenated (global first, project second).
Config format
The config file is a JSON object mapping event patterns to arrays of commands:
{
"session.idle": [
"notify-send 'OpenCode session completed!'"
],
"session.*": [
"echo '[{event.type}] at $(date)' >> /tmp/opencode-sessions.log"
],
"*": [
"echo '{event.type}' >> /tmp/opencode-all-events.log"
]
}
Event patterns
| Pattern | Matches |
|---|---|
session.idle |
Only the session.idle event |
session.* |
Any event starting with session. (session.idle, session.created, etc.) |
* |
Every event |
When multiple patterns match an event, all matching groups run in parallel. Commands within each group run sequentially.
Available events
command.executedfile.edited,file.watcher.updatedinstallation.updatedlsp.client.diagnostics,lsp.updatedmessage.created,message.updated,message.part.updatedpermission.requested,permission.repliedserver.session.updatedsession.created,session.idle,session.compacted,session.deleted,session.error,session.updatedtodo.updatedtool.execute.before,tool.execute.aftertui.file.open
Command entries
Each command in the array can be either a string or an object:
String (simple):
"echo 'hello world'"
Object (advanced):
{
"command": "echo 'hello world'",
"cwd": "/tmp",
"env": { "LOG_LEVEL": "debug" },
"timeout": 5000
}
| Field | Type | Required | Description |
|---|---|---|---|
command |
string |
Yes | The shell command to execute |
cwd |
string |
No | Working directory for the command |
env |
object |
No | Extra environment variables (merged with process.env) |
timeout |
number |
No | Timeout in milliseconds; command is killed if exceeded |
Interpolation
Environment variables are substituted at config-load time:
{
"session.idle": ["{env:NOTIFY_COMMAND} 'Session done!'"]
}
Event data is substituted at execution time:
{
"*": ["echo 'Event: {event.type}' >> /tmp/events.log"]
}
| Token | Replaced with |
|---|---|
{env:VAR_NAME} |
Value of environment variable (empty string if unset) |
{event.type} |
The event type string (e.g. session.idle) |
{event.properties.xxx} |
Dot-path into the event object |
{event} |
JSON-stringified entire event object |
Execution
Commands run via Bun's shell API, which is cross-platform and prevents shell injection by default. Commands are run with .nothrow().quiet() so failures are logged (via client.app.log) rather than thrown.
Example config
See opencode-event-shell-exec.example.json for a full example.
Development
bun install
bun test
bun run typecheck
License
MIT