opencode-subagent-tools 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,49 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## 0.2.0 - 2026-11-17
9
+
10
+ ### Added
11
+
12
+ - Background subagent activity tracking: the experimental idle hook, shell events, structured context probes, and a bounded background-job store. The hook is disposed on cleanup; `session.deleted` clears live and background state.
13
+ - `list`: `active`, `subtreeActive`, `activeDescendants`, `backgroundJob`, `activeCount`, `subtreeActiveCount`, and the `active`/`subtreeActive` filters. `status` remains execution-oriented; use `active` and `subtreeActive` for work that is still in progress.
14
+ - `usage`: `active`, optional `subtreeActive` with `includeDescendants`, `backgroundJob`, and background-aware lag flags.
15
+ - `cancel`: `active`, `backgroundJob`, an on-demand probe for idle/terminal targets, and `mayRemain`/`stateUnknown`.
16
+ - `cancel_descendants`: `activeCount`, `subtreeActiveCount`, `backgroundJobCount`, `backgroundJobMayRemain`, and per-target background jobs.
17
+ - `queue`: `queued`; `steer`, `queue`, and `context`: `active` and `backgroundJob`. `queue` waits for the current execution, not background jobs, which continue in parallel.
18
+
19
+ ### Changed
20
+
21
+ - Requires OpenCode 2.3.0+.
22
+ - `usageMayLag` covers active sessions with background work, not only running/unknown executions.
23
+
24
+ ### Fixed
25
+
26
+ - An idle event no longer overrides a known terminal status.
27
+ - `cancel` no longer prints only "no interrupt was needed" when an idle target owns background work.
28
+ - `cancel_descendants` reports idle background jobs instead of returning an unqualified "No running subagents".
29
+
30
+ ## 0.1.0 - 2026-11-07
31
+
32
+ ### Added
33
+
34
+ - Initial release of the `subagent-tools` OpenCode plugin.
35
+ - Seven tools under the default `subagent` namespace:
36
+ - `subagent_list` — list subagent sessions, filter by status, and page through results.
37
+ - `subagent_usage` — read cost, tokens, current context, and optional descendant totals for any session.
38
+ - `subagent_cancel` — stop one session with a soft interrupt.
39
+ - `subagent_cancel_descendants` — stop the caller's running descendants in batches.
40
+ - `subagent_steer` — send an instruction at the target session's next model request.
41
+ - `subagent_queue` — queue a message as the next independent turn.
42
+ - `subagent_context` — inject a synthetic context message without starting a turn.
43
+ - Options: `namespace`, `enforcePermissions`, `sessionControlPolicy`, `allowedOutputFormats`, `registerSkill`, and `limits` for discovery, list size, cancellation batch, and text length.
44
+ - Permission action `subagent.control` for mutations; `list` and `usage` are read-only. `cancel_descendants` checks the whole batch in one permission request.
45
+ - Per-call text or JSON output when both formats are allowed; `list`, `usage`, and `cancel_descendants` default to JSON. Set `allowedOutputFormats` to one format to omit the per-call choice.
46
+ - Discovery through `ctx.session.list`; requires OpenCode 2.2.5+. Tested against `@opencode/plugin` 2.2.5.
47
+ - Input validation for session IDs and text lengths.
48
+ - Bundled `SKILL.md` skill with operational guidance.
49
+ - Bun test suite, lint, typecheck, and CI scripts.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Maxim Matsiushonak
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,119 @@
1
- # Temporary Holding Version
1
+ # opencode-subagent-tools
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Seven tools for OpenCode V2 that let an agent inspect and control subagent
4
+ sessions: list children and usage, cancel one session or the caller's running
5
+ descendants, steer or queue messages, and inject context.
6
+
7
+ > Plugin ID: `subagent-tools`. Default tool namespace: `subagent`.
8
+
9
+ Requires OpenCode 2.3.0+.
10
+
11
+ ## Quick start
12
+
13
+ ```sh
14
+ opencode plugin add opencode-subagent-tools
15
+ ```
16
+
17
+ GitHub:
18
+
19
+ ```sh
20
+ opencode plugin add github:finnseefly/opencode-subagent-tools
21
+ ```
22
+
23
+ After install, run `opencode reload` and ask the agent to call `subagent_list`.
24
+ For manual/local installation, see [installation](docs/installation.md).
25
+
26
+ ## Tools
27
+
28
+ | Tool | What it does |
29
+ | ----------------------------- | ----------------------------------------------------------------------- |
30
+ | `subagent_list` | List child sessions with status, activity, age, cost, and token usage. |
31
+ | `subagent_usage` | Read cost, tokens, current context, status, and activity for a session. |
32
+ | `subagent_cancel` | Stop one session and report background work it cannot stop. |
33
+ | `subagent_cancel_descendants` | Stop running descendants and report idle background jobs. |
34
+ | `subagent_steer` | Send an instruction at the child's next model request. |
35
+ | `subagent_queue` | Queue a message as the next independent turn. |
36
+ | `subagent_context` | Inject a synthetic context message without starting a turn. |
37
+
38
+ The plugin also registers a `subagent-tools` skill with operational guidance.
39
+ See the [tool reference](docs/reference.md#text-vs-json) for output formats and
40
+ per-tool defaults. Set `allowedOutputFormats` to `["text"]` or `["json"]` to
41
+ allow only one format; the default `["text", "json"]` enables the per-call
42
+ `format` choice.
43
+
44
+ Tool names above use the default `subagent` namespace. Change the `namespace`
45
+ option to use a different prefix. Nested subagents require
46
+ `experimental.subagent_depth` to be at least `2` in OpenCode; this is an OpenCode
47
+ setting, not a plugin option.
48
+
49
+ ## Configuration
50
+
51
+ One power-user example; every option is optional. The values below are the
52
+ defaults. See [configuration](docs/configuration.md) for ranges and examples.
53
+
54
+ ```jsonc
55
+ {
56
+ "$schema": "https://opencode.ai/config.json",
57
+ "plugins": [
58
+ {
59
+ "package": "opencode-subagent-tools",
60
+ "options": {
61
+ "namespace": "subagent", // tool prefix
62
+ "enforcePermissions": true, // check mutations with subagent.control
63
+ "sessionControlPolicy": "descendants", // mutations only; reads are unrestricted
64
+ "allowedOutputFormats": ["text", "json"], // or ["text"] / ["json"]
65
+ "registerSkill": true, // register SKILL.md as a skill
66
+ "limits": {
67
+ "maxDiscoveryNodes": 200,
68
+ "maxDiscoveryDepth": 8,
69
+ "maxDiscoveryPages": 5,
70
+ "maxListRows": 20,
71
+ "maxCancelBatch": 20,
72
+ "maxTextLength": 16000,
73
+ },
74
+ },
75
+ },
76
+ ],
77
+ }
78
+ ```
79
+
80
+ Mutations call the `subagent.control` permission action. Setting
81
+ `enforcePermissions: true` by itself does not prompt; add an `ask` or `deny` rule
82
+ to be asked or blocked. See [security model](docs/security-model.md).
83
+
84
+ ## Pitfalls
85
+
86
+ - **`finished` is not task completion.** It means the last execution succeeded.
87
+ The child may still own a shell, image, or subagent job. Use `active` and
88
+ `subtreeActive` to find work that is still in progress.
89
+ - **`cancel` is a soft interrupt.** It does not cascade. A long tool call may
90
+ finish first, and jobs owned by an idle session keep running. The result
91
+ reports observed background work, but this tool cannot stop it.
92
+ - **`cancel_descendants` only targets running executions.** Idle descendants
93
+ that own background jobs are counted in `backgroundJobCount`, not interrupted.
94
+ It stops up to `maxCancelBatch` running descendants per call and only touches
95
+ the caller's subtree; use `cursor` to continue. Nested cancellation can wake an
96
+ intermediate parent.
97
+ - **Discovery stops at 200 nodes, 8 levels, or 5 pages by default.** Raise them
98
+ for large trees. An empty or partial list is not proof that no subagents
99
+ exist, and incomplete discovery can make `subtreeActive` false. See
100
+ [limitations](docs/limitations.md).
101
+ - **Usage can lag while a child is active.** Values are persisted at step
102
+ boundaries; `usageMayLag` means re-query after the step or after cancellation.
103
+ - **Permissions are not prompted by default.** Add an `ask` or `deny` rule for
104
+ `subagent.control` if you rely on approval.
105
+
106
+ ## Documentation
107
+
108
+ - [Installation](docs/installation.md)
109
+ - [Configuration](docs/configuration.md)
110
+ - [Tool reference](docs/reference.md)
111
+ - [Security model](docs/security-model.md)
112
+ - [Security policy](SECURITY.md)
113
+ - [Limitations](docs/limitations.md)
114
+ - [Development](docs/development.md)
115
+ - [Changelog](CHANGELOG.md)
116
+
117
+ ## License
118
+
119
+ MIT. See [LICENSE](./LICENSE).
package/SECURITY.md ADDED
@@ -0,0 +1,36 @@
1
+ # Security Policy
2
+
3
+ ## Supported versions
4
+
5
+ Security fixes are applied to the latest published minor release.
6
+
7
+ ## Reporting a vulnerability
8
+
9
+ Do not open a public issue for a security problem.
10
+
11
+ Use GitHub's private vulnerability reporting:
12
+
13
+ <https://github.com/finnseefly/opencode-subagent-tools/security/advisories/new>
14
+
15
+ Include:
16
+
17
+ - the affected version;
18
+ - the OpenCode version;
19
+ - a minimal reproduction or the relevant plugin configuration;
20
+ - the impact you observed;
21
+ - any suggested fix or mitigation.
22
+
23
+ If private reporting is unavailable, open a minimal public issue asking for a
24
+ private channel. Do not include exploit details in that issue.
25
+
26
+ ## Scope
27
+
28
+ This plugin exposes model-facing tools that can interrupt, steer, queue
29
+ messages for, and inject context into OpenCode sessions. Reports about
30
+ permission or ownership bypass, session-ID confusion, ancestor control under
31
+ `sessionControlPolicy`, prompt injection through session titles or metadata,
32
+ and denial of service are in scope.
33
+
34
+ Known limitations are documented in [docs/limitations.md](docs/limitations.md).
35
+ The default `sessionControlPolicy` is `"descendants"`; the `"all"` policy is
36
+ security-sensitive and should be enabled deliberately.
package/SKILL.md ADDED
@@ -0,0 +1,345 @@
1
+ ---
2
+ name: subagent-tools
3
+ description: Use the subagent tools to list, inspect usage, cancel, steer, queue, and inject context into OpenCode subagent sessions. Covers tool contracts, background work, delivery modes, soft interrupts, status-check lag, parent wake, nested depth, permissions, and budget handoffs.
4
+ ---
5
+
6
+ # Subagent Tools
7
+
8
+ Use these tools when you need to inspect or control OpenCode subagent sessions. They complement the built-in `subagent` launch tool; they do not replace it.
9
+
10
+ ## Names and namespace
11
+
12
+ Tool names below omit the default `subagent_` prefix. With the default namespace, call `subagent_list`, `subagent_usage`, `subagent_cancel`, `subagent_cancel_descendants`, `subagent_steer`, `subagent_queue`, and `subagent_context`. The prefix follows the plugin's `namespace` option and may be different in the user's config. In Code Mode, call the same tools as `tools.subagent.list`, `tools.subagent.usage`, and so on; the namespace separator is `.` instead of `_`.
13
+
14
+ ## Choose the tool
15
+
16
+ | Goal | Tool |
17
+ | --------------------------------------------- | -------------------- |
18
+ | See children, cost, and cumulative usage | `list` |
19
+ | Read current context, cost, and context limit | `usage` |
20
+ | Correct a running child at its next boundary | `steer` |
21
+ | Make a message the next independent turn | `queue` |
22
+ | Give a child a fact without waking it | `context` |
23
+ | Stop one target session | `cancel` |
24
+ | Stop the caller's running descendants | `cancel_descendants` |
25
+
26
+ ## Token and cost terms
27
+
28
+ - `tokens` — cumulative token breakdown for the session: `input`, `output`, `reasoning`, `cache.read`, `cache.write`. It includes every cache read and is not the current context.
29
+ - `tokensUsed` — `input + output + reasoning`; a cumulative non-cache budget.
30
+ - `contextTokens` — current context footprint: the last assistant step after the last completed compaction, `input + output + reasoning + cache.read + cache.write`. Only `usage` returns it.
31
+ - `costUSD` — the session's own cost. For a family total, use `usage` with `includeDescendants: true` and read `tree.costUSD`.
32
+
33
+ ## Status and activity
34
+
35
+ - `status` — the last or current execution: `running`, `finished`, `failed`,
36
+ `stopped`, or `unknown`. `finished` does not mean the delegated task is done.
37
+ - `active` — the session itself is running, unknown, or owns a background job.
38
+ Descendants are not included.
39
+ - `subtreeActive` — the session or any discovered descendant is active.
40
+ - `activeDescendants` — at least one discovered child is active in its subtree.
41
+ An idle parent with active descendants may wake.
42
+ - `backgroundJob` — the session's own observed background work. `kinds` can
43
+ contain `shell`, `image`, and `subagent`. `stateUnknown` means work may remain
44
+ but could not be verified.
45
+ - `usageMayLag` — usage may still grow because the session is active or unknown.
46
+
47
+ Use `active: true` for one session's own work and `subtreeActive: true` for the
48
+ whole delegated task. Do not use `statuses: ["running"]` for "still working".
49
+
50
+ ## Text vs JSON
51
+
52
+ When both formats are allowed (the default), every tool accepts `format`. If the user configured only one format, the `format` input is absent: `["text"]` returns text only, and `["json"]` always returns structured output.
53
+
54
+ - Use `text` for a quick read. Use `json` when you need fields such as `targets`, `pending`, `usage`, `tree`, or `lastRequest`.
55
+ - Choose by task; do not force JSON everywhere.
56
+
57
+ ## list
58
+
59
+ List child sessions discovered through the server's session tree, newest launch first.
60
+
61
+ ### Inputs
62
+
63
+ - `parentID?` — parent session ID. Defaults to the calling session. Any parent is accepted because reads are unrestricted.
64
+ - `statuses?` — execution statuses: `running`, `stopped`, `failed`, `finished`, or `unknown`. Omit it to include all five. An empty array is an error; unknown values are rejected.
65
+ - `active?` — filter on the session's own activity. Omit to include both.
66
+ - `subtreeActive?` — filter on the session or any discovered descendant. Omit to include both.
67
+ - `limit?` — maximum rows. Defaults to `maxListRows` (20); values outside 1 to `maxListRows` are rejected.
68
+ - `cursor?` — cursor from a previous `list` call. Pass it back unchanged.
69
+ - `format?` — default `json`.
70
+
71
+ ### Output
72
+
73
+ Text is a table-like summary. With `format: "json"`, the output contains:
74
+
75
+ - `root`, `statuses`, `discoveryComplete`, `warning?`
76
+ - `known` — all discovered sessions before the status and activity filters and cursor.
77
+ - `activeCount`, `subtreeActiveCount` — all discovered sessions with own activity or subtree activity, before filters.
78
+ - `matching` — all matches in the current discovery pass, before the cursor.
79
+ - `window` — matches after the cursor; `remaining` is the part not returned; `remainingPages` is pages left.
80
+ - `counts` — counts for all five execution statuses across all discovered sessions, before filter and cursor. It still sums to `known`.
81
+ - `rows[]` — `id`, `parentID?`, `agent?`, `title?`, `titleTruncated?`, `status`, `active`, `subtreeActive`, `activeDescendants?`, `backgroundJob?`, `ageSeconds?`, `launchedAt`, `usageMayLag?`, and optional `usage` with `costUSD?`, `tokens?`, and `tokensUsed?`.
82
+
83
+ ### Notes
84
+
85
+ - A cursor is bound to the status and activity filters. A cursor walk sees the sessions found when it started. New children can increase `known`/`matching` without appearing in `window`; re-run without a cursor to include them.
86
+ - Discovery can miss sessions. `discoveryComplete: false` and `warning` mean the result may be incomplete; an empty list is not proof that no subagents exist. Incomplete discovery can make `subtreeActive` false.
87
+ - `usageMayLag: true` means the row is active or unknown and its usage is as of the last persisted step. A `finished` row with a background job still sets it.
88
+ - `usage.tokens` and `usage.tokensUsed` are cumulative; neither is the current context. `list` does not return `contextTokens`; use `usage` for that.
89
+ - Text markers distinguish own activity (`active`), subtree-only activity (`subtree`), background kind (`background=shell`), and active descendants (`descendants=active`).
90
+ - Use `cursor` until `remaining` is 0.
91
+
92
+ ## usage
93
+
94
+ Read cost, tokens, and current context for a session. Read-only: any session ID is accepted, including the caller, its parents, and foreign sessions.
95
+
96
+ ### Inputs
97
+
98
+ - `sessionID` — required. Target session ID.
99
+ - `includeDescendants?` — when `true`, add `tree` totals for the target and its descendants.
100
+ - `format?` — default `json`.
101
+
102
+ ### Output
103
+
104
+ With `format: "json"`:
105
+
106
+ - `sessionID`, `parentID?`, `status`, `active`, `usageMayLag?`
107
+ - `subtreeActive?` — present only with `includeDescendants: true`; true when the target or any discovered descendant is active.
108
+ - `backgroundJob?` — the target's own observed background work.
109
+ - `costUSD?` — own cost, not a family total.
110
+ - `tokens?`, `tokensUsed?` — cumulative counts; `tokensUsed` is `input + output + reasoning`.
111
+ - `contextTokens?` — last assistant step after the last completed compaction: `input + output + reasoning + cache.read + cache.write`.
112
+ - `lastRequest?` — input/output/reasoning/cache read/cache write/total for that step.
113
+ - `contextLimit?`, `contextPercent?`, `model?`, `warning?`.
114
+ - `tree?` — with `includeDescendants: true`: `sessions` includes the target, `descendants` excludes it, and `costUSD`/`tokensUsed` include the target's own values when available. `tokensUsed` is omitted when no session in the tree reports token data. `discoveryComplete` covers the descendant walk; `descendantsMayLag?` flags active/unknown descendants; `warning?` marks incomplete discovery.
115
+
116
+ ### Notes
117
+
118
+ - `contextTokens: 0` is legitimate when no assistant step exists after the last completed compaction. If context is unavailable, the field is omitted and `warning` explains why.
119
+ - `contextTokens` is the current context; `tokens` and `tokensUsed` are cumulative.
120
+ - `costUSD` is the session's own cost. For a family total, use `includeDescendants: true` and read `tree.costUSD`.
121
+ - The caller's own status is reported as `running` while the tool executes.
122
+ - `subtreeActive` is omitted without the tree: descendant activity is unknown, not false.
123
+ - Re-query after the step completes or after cancellation when `usageMayLag` is true.
124
+
125
+ ## cancel
126
+
127
+ Stop one session with a soft interrupt.
128
+
129
+ ### Inputs
130
+
131
+ - `sessionID` — required. Target session ID; the policy may allow a session outside the caller's subtree.
132
+ - `reason?` — up to 500 characters. Recorded in the result; not delivered to the child.
133
+ - `format?` — default `text`.
134
+
135
+ ### Output
136
+
137
+ With `format: "json"`:
138
+
139
+ - `sessionID`, `accepted`, `interrupt`, `status`, `active`
140
+ - `backgroundJob?` — observed own work, with `mayRemain` and `stateUnknown` when relevant.
141
+ - `reason?`, `readBackMayLag`, `cancellationDoesNotCascade`
142
+ - `costUSD?`, `tokens?`, `tokensUsed?`
143
+
144
+ `interrupt` is `accepted`, `rejected`, or `unknown`:
145
+
146
+ - `accepted` — the server accepted the interrupt.
147
+ - `rejected` — the target was not running; this is not an error.
148
+ - `unknown` — the server returned no definitive boolean. An abort during the interrupt is a `Tool.Error`.
149
+
150
+ `accepted` is a convenience alias for `interrupt === "accepted"`. `cancellationDoesNotCascade` is always `true`.
151
+
152
+ ### Notes
153
+
154
+ - This is a soft interrupt: it does not cascade to the child's children, a long tool call may finish first, and jobs owned by an idle session keep running.
155
+ - If the target is idle or terminal and no live background job is known, the tool probes the target's structured context for running work. A failed probe, or a probe without an authoritative idle snapshot for the target, sets `backgroundJob.stateUnknown`; it does not claim there is no job.
156
+ - If `interrupt` is `rejected` and a background job exists, the execution was idle; the tool cannot stop that job. If `interrupt` is accepted and a background job exists, the job may continue. `backgroundJob.mayRemain` marks this.
157
+ - `active` is the target's own state after the call. It is true for running, unknown, or observed background work.
158
+ - OpenCode may wake the parent with a cancellation notice.
159
+ - The status check after cancellation can lag. If `status` is `running` or `unknown`, or `readBackMayLag` is true, re-run `list`.
160
+ - The target may settle as `stopped`, `failed`, or `finished`; `stopped` is not guaranteed.
161
+
162
+ ## cancel_descendants
163
+
164
+ Stop the running descendants of the calling session. It stops at most `maxCancelBatch` targets per call.
165
+
166
+ ### Inputs
167
+
168
+ - `reason?` — up to 500 characters. Recorded in the result.
169
+ - `cursor?` — cursor from a previous `cancel_descendants` call; pass it back unchanged.
170
+ - `format?` — default `json`.
171
+
172
+ There is no `sessionID`, `parentID`, `statuses`, or `limit` argument. The tool always works in the calling session's subtree, regardless of `sessionControlPolicy`.
173
+
174
+ ### Output
175
+
176
+ With `format: "json"`:
177
+
178
+ - `known` — all discovered descendants in the current pass, before the cursor is applied; `considered` — after the cursor; `running` — running among `considered`.
179
+ - `activeCount`, `subtreeActiveCount` — considered rows with own or subtree activity.
180
+ - `backgroundJobCount` — considered rows with `status !== "running"` that own a background job.
181
+ - `backgroundJobMayRemain?` — true when observed background work may still run.
182
+ - `beforeCursorRunning?` — running descendants before the cursor window.
183
+ - `targets[]` — `sessionID`, `interrupt` (`accepted`/`rejected`/`failed`/`unknown`), `readBack` (`ok`/`failed`/`not-read`), optional `status`, optional `backgroundJob`, optional `error`.
184
+ - `remaining` — running targets not attempted; `aborted` — the call stopped before the batch completed.
185
+ - `reason?`, `cursor?`, `warning?`.
186
+
187
+ ### Notes
188
+
189
+ - Only `running` rows are targeted. `unknown` rows need an individual `cancel`.
190
+ - Idle rows that own background jobs are reported in `backgroundJobCount`; this tool cannot stop those jobs. If no execution is running but background jobs exist, the result is normal, not an unqualified "no running subagents".
191
+ - Idle parents with active descendants are counted in `subtreeActiveCount` and reported in the summary; they may wake. The running descendant is the target, not the parent.
192
+ - The whole batch is checked in one permission request.
193
+ - `maxCancelBatch` limits targets per call. Use `cursor` to continue; `remaining` counts what is left.
194
+ - Failed, unknown, rejected, and not-read targets are reported in `targets` and are not retried by the cursor. Inspect them manually.
195
+ - `aborted: true` means the call stopped before the batch completed; inspect `targets` and `remaining`.
196
+ - Nested cancellation can wake an intermediate parent inside the subtree. Re-run `list` after the batch and cancel that parent again if it resumed.
197
+ - Discovery can be incomplete; the output warns when some running descendants may be missing.
198
+ - It stops all running descendants of the calling session, not one selected branch. From a parent, it also stops the target child's siblings and their descendants.
199
+ - To stop one child and its descendants without touching siblings, `steer` that child to run `cancel_descendants` itself, then `cancel` it. Alternatively, list its descendants with `list(parentID: childID)` and cancel them individually. `cancel` does not cascade.
200
+ - JSON is the default because `targets[]` is the main result; use `format: "text"` for a short summary.
201
+
202
+ ## steer
203
+
204
+ Send an instruction into a session at its next model request.
205
+
206
+ ### Inputs
207
+
208
+ - `sessionID` — required.
209
+ - `text` — required; up to 16000 characters by default (`maxTextLength`).
210
+ - `resume?` — default `true`. `false` accepts the message without waking an idle child.
211
+ - `format?` — default `text`.
212
+
213
+ ### Output
214
+
215
+ With `format: "json"`:
216
+
217
+ - `sessionID`, `messageID?`, `delivery`, `chars`, `resume`
218
+ - `status?` — status observed before the message was accepted
219
+ - `active`, `backgroundJob?` — observed target activity and own background work
220
+ - `pending?` — true when the message was accepted without waking an idle child
221
+
222
+ ### Notes
223
+
224
+ - Delivered before the child's next model request. It does not interrupt the current tool call.
225
+ - The plugin cannot move a blocking shell to the background, so delivery may wait for that shell. This is a UI parity gap, not a hard failure.
226
+ - OpenCode sends a `<subagent>` report each time the child goes idle. A report can say `state="running"` and `Background work still running` when the execution is idle but background work remains. Read the report; do not resume the child just to read its result.
227
+ - `delivery` is the server-reported delivery, normally `steer`.
228
+
229
+ ## queue
230
+
231
+ Queue a message as the next independent turn after the current execution settles.
232
+
233
+ ### Inputs
234
+
235
+ - `sessionID` — required.
236
+ - `text` — required; up to 16000 characters by default (`maxTextLength`).
237
+ - `resume?` — default `true`. `false` accepts the message without waking an idle child.
238
+ - `format?` — default `text`.
239
+
240
+ ### Output
241
+
242
+ With `format: "json"`:
243
+
244
+ - `sessionID`, `messageID?`, `delivery`, `chars`, `resume`
245
+ - `status?` — status observed before the message was accepted
246
+ - `active`, `backgroundJob?` — observed target activity and own background work
247
+ - `queued?` — true when the message was accepted but has not started yet
248
+ - `pending?` — true when the message was accepted without waking an idle child
249
+
250
+ ### Notes
251
+
252
+ - The message does not join the current run. It waits for the current execution to settle, then starts a separate turn.
253
+ - Background jobs are not waited for and continue in parallel. The queue is promoted at the idle boundary even when background work remains.
254
+ - `queued` is inferred from the observed status and `resume`; it does not inspect the server's existing queue. Other queued prompts may be ahead.
255
+ - `delivery` is the server-reported delivery, normally `queue`.
256
+
257
+ ## context
258
+
259
+ Inject a synthetic context message without starting a turn.
260
+
261
+ ### Inputs
262
+
263
+ - `sessionID` — required.
264
+ - `text` — required; up to 16000 characters by default (`maxTextLength`).
265
+ - `description?` — up to 200 characters. A short label shown in the transcript.
266
+ - `format?` — default `text`.
267
+
268
+ ### Output
269
+
270
+ With `format: "json"`:
271
+
272
+ - `sessionID`, `messageID?`, `delivery: "next-step"`, `chars`
273
+ - `description?`
274
+ - `status?` — status observed before the message was accepted
275
+ - `active`, `backgroundJob?` — observed target activity and own background work
276
+ - `pending?` — true when the message was accepted without waking an idle child
277
+
278
+ ### Notes
279
+
280
+ - This is a synthetic message, not a user instruction.
281
+ - It always uses `resume: false`. An idle child keeps the message pending until its next run.
282
+ - For an instruction without waking, use `steer` with `resume: false`. For a follow-up turn, use `queue`.
283
+
284
+ ## Permissions and policy
285
+
286
+ - Mutations use `subagent.control` when `enforcePermissions` is `true` (the default); `false` skips the permission check, but ownership still follows `sessionControlPolicy`.
287
+ - `list` and `usage` are read-only, do not request `subagent.control`, and may read any session, including the caller and its ancestors.
288
+ - `sessionControlPolicy` limits mutations only: `"descendants"` (default), `"all-except-ancestors"`, or `"all"`.
289
+ - `cancel_descendants` always stays in the caller's subtree; the policy does not widen it.
290
+ - A mutation cannot target the caller; `usage` may read it.
291
+ - OpenCode's base policy allows all actions, so add an `ask` or `deny` rule to prompt or block. `"all"` is privileged: a subagent can target its parent or root if it knows the ID.
292
+
293
+ ## Errors
294
+
295
+ Refusals are `Tool.Error`: unknown target, self-target, invalid cursor, invalid, empty, or non-array `statuses`, malformed or overlong session/parent ID, target outside `sessionControlPolicy`, or permission denial.
296
+
297
+ Abort behavior:
298
+
299
+ - `list` and `usage` return `Tool.Error` when discovery or context read is aborted.
300
+ - `cancel` returns `Tool.Error` if the abort happens before or during the interrupt; an abort after the interrupt may still return a normal result.
301
+ - `cancel_descendants` returns `Tool.Error` before discovery; otherwise it reports `aborted: true` with the targets it attempted and a warning when discovery was incomplete.
302
+
303
+ In OpenCode 2.3.0+, these `Tool.Error` results are normal call results from a cooperative stop, not interrupted tool calls. The error message is actionable. Correct the arguments and continue.
304
+
305
+ No-op outcomes are not errors: `cancel` on an already stopped, failed, or finished session, and `cancel_descendants` with no running children, return a normal result.
306
+
307
+ ## Background reports
308
+
309
+ In OpenCode 2.3.0+, all subagents run in the background. A `<subagent>` report arrives each time a child goes idle, and again after each later round. A report can say `state="running"` and include `Background work still running` when the child's execution is idle but its own background work remains. Read the report; do not resume the child just to read its result.
310
+
311
+ ## Nested subagents
312
+
313
+ OpenCode creates nested subagents only when `experimental.subagent_depth` is at least `2`; this is an OpenCode setting, not a plugin option. The plugin can list, inspect, steer, queue, and stop nested descendants up to the configured limits, but it does not expose a grandchild's transcript. Use the intermediate parent as a relay or have the grandchild write a handoff file.
314
+
315
+ ## Limits
316
+
317
+ - `list` returns up to 20 rows by default.
318
+ - `cancel_descendants` interrupts up to 20 targets per call by default.
319
+ - `steer`, `queue`, and `context` accept up to 16000 characters by default.
320
+ - `reason` is capped at 500 characters and `description` at 200. These two are fixed, not `limits` options.
321
+ - Discovery defaults: 200 nodes, 8 levels, and 5 pages.
322
+ - The discovery, list, cancel-batch, and text limits are configurable through the plugin's `limits` options.
323
+
324
+ ## Example: budget handoff
325
+
326
+ If cost matters for your workflow, one way to use the tools together is: check `list` for `tokensUsed`, call `usage` for a child that is approaching your budget, `steer` it to write a handoff summary and stop new work, then `cancel` if it does not wind down. Read the handoff and start a fresh child. Keep the old session for audit; `contextTokens` resets after compaction, but `costUSD` and cumulative tokens do not.
327
+
328
+ ## Workflow
329
+
330
+ 1. Call `list`; it includes all statuses by default. Pass `active: true` for one session's own work or `subtreeActive: true` for the whole delegated task. Use `statuses` only when you need a specific execution outcome.
331
+ 2. Pick the session ID from the result. Do not invent or guess IDs.
332
+ 3. To change what a running child is doing, use `steer`; to add a follow-up turn, use `queue`; to add a fact without waking it, use `context`. These adjust the existing session and keep its current run and context. `cancel` stops the session; restarting it with the built-in `subagent` tool is a different workflow.
333
+ 4. To stop one child, use `cancel`. To stop all your running descendants, use `cancel_descendants`; it cannot select one branch.
334
+ 5. After `cancel`, re-run `list` if `interrupt` is `unknown`, `status` is `running` or `unknown`, or `readBackMayLag` is true. After `cancel_descendants`, inspect `targets[].status`/`targets[].readBack`; re-run `list` if a target still looks running. After a nested `cancel_descendants`, also check whether an intermediate parent resumed.
335
+
336
+ ## Examples
337
+
338
+ - The child is editing the wrong file: use `steer` with a concrete constraint.
339
+ - The child should run the benchmark after its current task: use `queue`.
340
+ - The child is idle and you want to leave it idle: use `steer` with `resume: false`.
341
+ - The migration is already applied: use `context` with that fact; do not wake the child.
342
+ - Stop one child but keep its sibling: use `cancel` with the child's session ID.
343
+ - Stop every running descendant of the current session: use `cancel_descendants`.
344
+ - Stop one child and its descendants without touching siblings: `steer` that child to run `cancel_descendants` itself, then `cancel` it; or list its descendants and cancel them individually.
345
+ - If cost matters for a child: `usage` it, then `steer` a handoff before starting a fresh child.