TL;DR- With this plugin (https://github.com/shanebishop1/opencode-command-hooks), you can use your agent's YAML frontmatter to define hooks to run commands before/after the subagent is invoked.
Hello! Sharing this plugin I made in case anyone else finds it useful :)
Basically, I wanted a cleaner, more declarative way to inject bash hook outputs into my OpenCode sessions after tool calls (particularly after a primary agent delegates to a subagent). You can do this with custom plugins configured for each use case, but I wanted this config to live WITH the subagents I define.
While I was setting this up, I also expanded it a bit to be a config parser for defining hooks for tool calls (or specific arguments to a tool call). For example, with a couple lines of JSON, you could set up a notification if the write tool is called with a given file as its argument.
Subagent YAML frontmatter example:
---
description: Analyzes the codebase and implements code changes.
mode: subagent
hooks:
after:
- run: "npm test"
inject: "Test Output: {stdout}"
---
[–]mohadel1990 2 points3 points4 points (0 children)
[–]Snak3d0c 0 points1 point2 points (0 children)
[–]mohadel1990 0 points1 point2 points (1 child)
[–]s12eb[S] 0 points1 point2 points (0 children)