Skip to content

Commit e3fdc90

Browse files
committed
fix(rescue): inline forwarding into the slash command (closes #17)
The /opencode:rescue --background path was broken because plugin-scoped subagents cannot use permissionMode: bypassPermissions, and Claude Code does not propagate the command's allowed-tools grant to a subagent it spawns. Background-mode subagents have no way to prompt for Bash permission, so the forwarder was auto-denied and returned an error instead of OpenCode's output. Eliminate the subagent layer entirely. The command's own context already has Bash(node:*), so commands/rescue.md now invokes opencode-companion.mjs task ... directly. --background maps 1:1 to the companion's existing detach-a-worker mode, which removes the ambiguity between "Claude backgrounds the subagent" and "the companion detaches a worker" that has plagued every related issue (#16, #37). The command keeps context: fork so OpenCode stdout still lands in a forked context rather than the parent thread. Deletes: - plugins/opencode/agents/opencode-rescue.md (sole-purpose forwarder) - plugins/opencode/skills/opencode-runtime/ (only used by the deleted subagent; marked user-invocable: false) README.md updated to drop the subagent reference from the slash-command list and the project structure tree. All 172 tests pass.
1 parent 87fbd97 commit e3fdc90

4 files changed

Lines changed: 25 additions & 113 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ To check your configured providers:
9999

100100
- `/opencode:review` -- Normal OpenCode code review (read-only). Supports `--base <ref>`, `--pr <number>`, `--model <provider/model>`, `--free`, `--wait`, and `--background`.
101101
- `/opencode:adversarial-review` -- Steerable review that challenges implementation and design decisions. Supports `--base <ref>`, `--pr <number>`, `--model <provider/model>`, `--free`, `--wait`, `--background`, and custom focus text.
102-
- `/opencode:rescue` -- Delegates a task to OpenCode via the `opencode:opencode-rescue` subagent. Supports `--model`, `--free`, `--agent`, `--resume`, `--fresh`, `--worktree`, `--wait`, and `--background`.
102+
- `/opencode:rescue` -- Delegates a task to OpenCode via a direct call to the companion's `task` runtime. Supports `--model`, `--free`, `--agent`, `--resume`, `--fresh`, `--worktree`, and `--background`. Foreground is the default; `--background` detaches a worker and returns a job id you can poll with `/opencode:status`.
103103
- `/opencode:status` -- Shows running/recent OpenCode jobs for the current repo.
104104
- `/opencode:result` -- Shows final output for a finished job, including OpenCode session ID for resuming.
105105
- `/opencode:cancel` -- Cancels an active OpenCode job.
@@ -185,7 +185,6 @@ opencode-plugin-cc/
185185
├── .github/workflows/ci.yml # GitHub Actions CI
186186
├── plugins/opencode/
187187
│ ├── .claude-plugin/plugin.json # Plugin metadata
188-
│ ├── agents/opencode-rescue.md # Rescue subagent definition
189188
│ ├── commands/ # 7 slash commands
190189
│ │ ├── review.md
191190
│ │ ├── adversarial-review.md

‎plugins/opencode/agents/opencode-rescue.md‎

Lines changed: 0 additions & 45 deletions
This file was deleted.

‎plugins/opencode/commands/rescue.md‎

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
---
2-
description: Delegate investigation, an explicit fix request, or follow-up rescue work to the OpenCode rescue subagent
3-
argument-hint: "[--background|--wait] [--worktree] [--resume|--fresh] [--model <provider/model> | --free] [--agent <build|plan>] [what OpenCode should investigate, solve, or continue]"
2+
description: Delegate investigation, an explicit fix request, or follow-up rescue work to OpenCode
3+
argument-hint: "[--background] [--worktree] [--resume|--fresh] [--model <provider/model> | --free] [--agent <build|plan>] [what OpenCode should investigate, solve, or continue]"
44
context: fork
55
allowed-tools: Bash(node:*), AskUserQuestion
66
---
77

8-
Route this request to the `opencode:opencode-rescue` subagent.
9-
The final user-visible response must be OpenCode's output verbatim.
8+
Forward this request to the OpenCode companion's `task` runtime via a single Bash call.
9+
The final user-visible response must be the companion's stdout verbatim — no commentary, summary, or paraphrase before or after it.
1010

1111
Raw user request:
1212
$ARGUMENTS
1313

1414
Execution mode:
1515

16-
- If the request includes `--background`, run the `opencode:opencode-rescue` subagent in the background.
17-
- If the request includes `--wait`, run the `opencode:opencode-rescue` subagent in the foreground.
18-
- If neither flag is present, default to foreground.
19-
- `--background` and `--wait` are execution flags for Claude Code. Do not forward them to `task`, and do not treat them as part of the natural-language task text.
20-
- `--model`, `--free`, and `--agent` are runtime-selection flags. Preserve them for the forwarded `task` call, but do not treat them as part of the natural-language task text. `--free` tells the companion to pick a random first-party `opencode/*` free-tier model from `opencode models`; it is restricted to `opencode/*` because OpenRouter free models have inconsistent tool-use support. `--free` is mutually exclusive with `--model`.
21-
- `--worktree` is an isolation flag. Preserve it for the forwarded `task` call, but do not treat it as part of the natural-language task text. When present, OpenCode runs in an isolated git worktree instead of editing the working directory in-place.
22-
- If the request includes `--resume`, do not ask whether to continue. The user already chose.
23-
- If the request includes `--fresh`, do not ask whether to continue. The user already chose.
24-
- Otherwise, before starting OpenCode, check for a resumable rescue session from this Claude session by running:
16+
- Default to foreground: run `node "${CLAUDE_PLUGIN_ROOT}/scripts/opencode-companion.mjs" task ...` and wait for it to finish. The Bash call must run in the foreground — never set `run_in_background: true` on the Bash tool, even when the user asks for `--background`.
17+
- If the request includes `--background`, append `--background` to the `task` invocation. The companion will spawn a detached worker and return a job id immediately; you then return that job id (with the `Check /opencode:status for progress.` line the companion prints) verbatim.
18+
- `--background` is the only execution-mode flag. Strip it from the natural-language task text before forwarding. `--wait` is accepted as a no-op alias for the default (foreground) mode and must also be stripped from the task text — do not forward it to `task`.
19+
- `--model`, `--free`, and `--agent` are runtime-selection flags. Strip them from the task text and forward each to `task` unchanged. `--free` tells the companion to pick a random first-party `opencode/*` free-tier model from `opencode models`; it is restricted to `opencode/*` because OpenRouter free models have inconsistent tool-use support. `--free` is mutually exclusive with `--model`.
20+
- `--worktree` is an isolation flag. Strip it from the task text and forward it to `task`. When present, OpenCode runs in an isolated git worktree instead of editing the working directory in-place.
21+
- `--resume` and `--fresh` are routing controls. Strip them from the task text. `--resume` becomes `--resume-last` on the forwarded `task` call. `--fresh` means do not add `--resume-last`, regardless of how the natural-language request reads.
22+
- If neither `--resume` nor `--fresh` is present, before starting OpenCode, check for a resumable rescue session from this Claude session by running:
2523

2624
```bash
2725
node "${CLAUDE_PLUGIN_ROOT}/scripts/opencode-companion.mjs" task-resume-candidate --json
@@ -33,20 +31,22 @@ node "${CLAUDE_PLUGIN_ROOT}/scripts/opencode-companion.mjs" task-resume-candidat
3331
- `Start a new OpenCode session`
3432
- If the user is clearly giving a follow-up instruction such as "continue", "keep going", "resume", "apply the top fix", or "dig deeper", put `Continue current OpenCode session (Recommended)` first.
3533
- Otherwise put `Start a new OpenCode session (Recommended)` first.
36-
- If the user chooses continue, add `--resume` before routing to the subagent.
37-
- If the user chooses a new session, add `--fresh` before routing to the subagent.
38-
- If the helper reports `available: false`, do not ask. Route normally.
34+
- If the user chooses continue, add `--resume-last` to the forwarded `task` call.
35+
- If the user chooses a new session, do not add `--resume-last`.
36+
- If the helper reports `available: false`, do not ask. Forward normally.
3937

40-
Operating rules:
38+
Forwarding rules:
4139

42-
- The subagent is a thin forwarder only. It should use one `Bash` call to invoke `node "${CLAUDE_PLUGIN_ROOT}/scripts/opencode-companion.mjs" task ...` and return that command's stdout as-is.
43-
- Return the OpenCode companion stdout verbatim to the user.
44-
- Do not paraphrase, summarize, rewrite, or add commentary before or after it.
45-
- Do not ask the subagent to inspect files, monitor progress, poll `/opencode:status`, fetch `/opencode:result`, call `/opencode:cancel`, summarize output, or do follow-up work of its own.
40+
- Use exactly one foreground Bash call to invoke `node "${CLAUDE_PLUGIN_ROOT}/scripts/opencode-companion.mjs" task ...`.
41+
- Pass the user's task text as a single positional argument to `task`, after all flags. Preserve it as-is apart from stripping the routing flags listed above.
42+
- If the user is clearly asking to continue prior OpenCode work in this repository (such as "continue", "keep going", "resume", "apply the top fix", or "dig deeper") and `--fresh` is not present, add `--resume-last` even if neither `--resume` nor the resume prompt above produced one.
43+
- Rescue is always write-capable. The companion's `task` runtime defaults to write mode and has no read-only switch. If the user wants a read-only diagnosis, point them at `/opencode:review` or `/opencode:adversarial-review` instead.
4644
- Leave `--agent` unset unless the user explicitly asks for a specific agent (build or plan).
47-
- Leave the model unset unless the user explicitly asks for a specific model or `--free`.
48-
- Leave `--resume` and `--fresh` in the forwarded request. The subagent handles that routing when it builds the `task` command.
49-
- If the helper reports that OpenCode is missing or unauthenticated, stop and tell the user to run `/opencode:setup`.
45+
- Leave the model unset unless the user explicitly asks for a specific model or `--free`. `--free` and `--model` are mutually exclusive — if both are present, return nothing and tell the user to pick one.
46+
- Return the stdout of the `task` command exactly as-is.
47+
- Do not paraphrase, summarize, rewrite, or add commentary before or after it.
48+
- Do not inspect the repository, read files, grep, monitor progress, poll `/opencode:status`, fetch `/opencode:result`, call `/opencode:cancel`, summarize output, or do any follow-up work of your own.
49+
- If the Bash call fails or OpenCode cannot be invoked, return the failure stderr verbatim. If the helper reports that OpenCode is missing or unauthenticated, stop and tell the user to run `/opencode:setup`.
5050
- If the user did not supply a request, check for a saved review from `/opencode:review` or `/opencode:adversarial-review`:
5151

5252
```bash

‎plugins/opencode/skills/opencode-runtime/SKILL.md‎

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)