@@ -1,4 +1,5 @@
11 import * as c from "yoctocolors";
2+import { isAbortError } from "../agent/agent-helpers.ts";
23 import type { ThinkingEffort } from "../llm-api/providers.ts";
34 import { fetchAvailableModels } from "../llm-api/providers.ts";
45 import {
@@ -6,15 +7,16 @@ import {
67 listMcpServers,
78 upsertMcpServer,
89 } from "../session/db/index.ts";
9-
1010 import { loadAgents } from "./agents.ts";
1111 import {
1212 type CustomCommand,
1313 expandTemplate,
1414 loadCustomCommands,
1515 } from "./custom-commands.ts";
16+import { watchForCancel } from "./input.ts";
1617 import { renderMarkdown } from "./markdown.ts";
1718 import { PREFIX, write, writeln } from "./output.ts";
19+
1820 import { loadSkills } from "./skills.ts";
1921
2022 // ─── Types ────────────────────────────────────────────────────────────────────
@@ -462,6 +464,7 @@ async function handleCustomCommand(
462464 writeln(`${PREFIX.info} ${label} ${src}`);
463465 writeln();
464466
467+ // context: fork (Claude Code) or subtask: true (OpenCode) → isolated subagent.
465468 // context: fork (Claude Code) or subtask: true (OpenCode) → isolated subagent.
466469 // Default: run inline in the current conversation.
467470 const fork = cmd.context === "fork" || cmd.subtask === true;
@@ -470,9 +473,18 @@ async function handleCustomCommand(
470473 return { type: "inject-user-message", text: prompt };
471474 }
472475
476+ const abortController = new AbortController();
477+ const stopWatcher = watchForCancel(abortController, {
478+ allowSubagentEsc: true,
479+ });
473480 try {
474481 ctx.startSpinner("subagent");
475- const output = await ctx.runSubagent(prompt, cmd.agent, cmd.model);
482+ const output = await ctx.runSubagent(
483+ prompt,
484+ cmd.agent,
485+ cmd.model,
486+ abortController.signal,
487+ );
476488
477489 write(renderMarkdown(output.result));
478490 writeln();
@@ -482,9 +494,13 @@ async function handleCustomCommand(
482494 text: `/${cmd.name} output:\n\n${output.result}\n\n<system-message>Summarize the findings above to the user.</system-message>`,
483495 };
484496 } catch (e) {
497+ if (isAbortError(e as Error)) {
498+ return { type: "handled" };
499+ }
485500 writeln(`${PREFIX.error} /${cmd.name} failed: ${String(e)}`);
486501 return { type: "handled" };
487502 } finally {
503+ stopWatcher();
488504 ctx.stopSpinner();
489505 }
490506 }