You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
subagent: tool remains advertised at the maximum session depth #53356
With the default experimental.subagent_depth of 1, child sessions still get the subagent tool and its "Available subagents" list. Workers write full delegation briefs, then every call fails with:
The depth check only runs at execution (subagent.ts:117-133); the prompt hook adds the agent list without checking depth (subagent.ts:282-309). Hit 8+ times in one day. The error text also nudges agents to raise the limit.
Expected: hide the tool at the depth limit and keep the execution guard. Workaround: deny subagent in each worker agent's permissions, which hides it.
Thanks for the detailed report. I can reproduce this on 2.0.23, and it still happens on the latest dev (fd8268ea5).
With the default experimental.subagent_depth (1), I had a simulated model in the primary session start a general subagent:
The child session's model request still included the subagent tool, with the full "Available subagents" list in its description.
When the child called it, the call failed with Subagent depth limit reached (1). Increase "experimental.subagent_depth" to allow nested subagents.
The depth limit is only checked when the tool runs. The step that adds the subagent list to the tool description doesn't look at session depth, so the tool is still offered.
The recording below shows the run, and the script below reproduces it. Until this is fixed, denying subagent in the worker agents' permissions hides the tool, as you found.
recording.mp4Reproduction script (drive.ts)
// Repro for anomalyco/opencode#53356: the `subagent` tool is still advertised to a// child session at the default experimental.subagent_depth (1), and every call fails.import{appendFileSync}from"node:fs"import{Effect,Stream}from"effect"constlog=(m: string)=>{console.log(m);appendFileSync("/tmp/opencode/repro.log",m+"\n")}import{Llm,OpenCodeDriver}from"opencode-drive"consttoolNames=(body: any): string[]=>(body?.tools??[]).map((t: any)=>t?.function?.name??t?.name).filter(Boolean)consttext=(body: unknown)=>JSON.stringify(body)exportdefaultOpenCodeDriver.use({
...(process.env.OC_DEV ? {opencode: {dev: process.env.OC_DEV}} : {}),tui: {recording: true},},({ ui, llm })=>Effect.gen(function*(){yield*llm.serve((request)=>{constbody=request.bodyasanyconsts=text(body)constisChild=s.includes("CHILD_TASK_MARKER")&&!s.includes("PRIMARY_MARKER")consttools=toolNames(body)log(`[request] ${isChild ? "CHILD" : "PRIMARY"} tools=${JSON.stringify(tools)}`)if(isChild){constdesc=(body.tools??[]).find((t: any)=>(t?.function?.name??t?.name)==="subagent")if(desc)log(`[child subagent description]\n${desc?.function?.description??desc?.description}`)if(s.includes("Subagent depth limit reached")){log("[child] got depth-limit error from subagent tool")returnStream.make(Llm.text("Nested delegation failed: depth limit reached."))}if(tools.includes("subagent"))returnStream.make(Llm.toolCall({index: 0,id: "call_nested",name: "subagent",input: {agent: "general",description: "Nested worker",prompt: "Do part of the work"},}),Llm.finish("tool-calls"),)returnStream.make(Llm.text("Child done without subagent tool."))}if(s.includes("Nested delegation failed")||s.includes("Child done"))returnStream.make(Llm.text("Primary: child finished."))returnStream.make(Llm.toolCall({index: 0,id: "call_child",name: "subagent",input: {agent: "general",description: "Worker task",prompt: "CHILD_TASK_MARKER: split this work up and delegate parts"},}),Llm.finish("tool-calls"),)})yield*ui.submit("PRIMARY_MARKER delegate this to a worker")yield*ui.waitFor("Primary: child finished.",{timeout: 60000}asany)yield*ui.screenshot("final")}),)
Run it with opencode-drive: opencode-drive run ./drive.ts. It drives opencode from your PATH; set OC_DEV to the path of an OpenCode checkout to run that from source instead.
Activity
github-actions commentedon Oct 5, 2026
Thanks for updating the issue with a clear description and reproduction steps!
opencodejr commentedon Oct 27, 2026
Thanks for the detailed report. I can reproduce this on 2.0.23, and it still happens on the latest
dev(fd8268ea5).With the default
experimental.subagent_depth(1), I had a simulated model in the primary session start ageneralsubagent:subagenttool, with the full "Available subagents" list in its description.Subagent depth limit reached (1). Increase "experimental.subagent_depth" to allow nested subagents.The depth limit is only checked when the tool runs. The step that adds the subagent list to the tool description doesn't look at session depth, so the tool is still offered.
The recording below shows the run, and the script below reproduces it. Until this is fixed, denying
subagentin the worker agents' permissions hides the tool, as you found.recording.mp4
Reproduction script (drive.ts)
Run it with opencode-drive:
opencode-drive run ./drive.ts. It drivesopencodefrom yourPATH; setOC_DEVto the path of an OpenCode checkout to run that from source instead.