Does it have a sub-agent feature for file analysis?
Does it have a sub-agent feature that analyzes a lot of files and give a resume to the main agent?
Excellent! Now I have a clear picture. Let me provide you with a comprehensive answer.
##Yes, OpenCode has a sub-agent feature!
OpenCode has a Task tool that allows the primary agent to launch subagents to handle specialized tasks autonomously. Here's how it works:
###Built-in Subagents
OpenCode comes with two built-in subagents specifically designed for file analysis:
-
Explore (
mode: subagent)- A fast agent specialized for exploring codebases
- Has access to:
grep,glob,list,bash,webfetch,websearch,codesearch,read - Supports thoroughness levels: "quick", "medium", or "very thorough"
- From
packages/opencode/src/agent/prompt/explore.txt:
"You are a file search specialist. You excel at thoroughly navigating and exploring codebases."
-
General (
mode: subagent)- A general-purpose agent for researching complex questions and executing multi-step tasks
- Can execute multiple units of work in parallel
###How Results Are Returned
From packages/opencode/src/tool/task.txt:
"When the agent is done, it will return a single message back to you. The result returned by the agent is not visible to the user. To show the user the result, you should send a text message back to the user with a concise summary of the result."
The Task tool in packages/opencode/src/tool/task.ts creates a child session, runs the subagent, and returns a summary of all tool calls plus the final text response to the parent agent.
###Automatic Delegation for Large Files
There's also an automatic truncation feature that encourages subagent delegation. When tool output is too large (>2000 lines or >50KB), the system truncates it and tells the main agent (from packages/opencode/src/tool/truncation.ts):
"Use the Task tool to have a subagent process this file with Grep and Read (with offset/limit). Do NOT read the full file yourself - delegate to save context."
###Invoking Subagents
Subagents can be invoked:
- Automatically by primary agents based on their descriptions
- Manually by
@mentioning them (e.g.,@explore find all API endpoints) - Via custom commands that trigger subtask invocation
So yes, this is exactly the pattern you described - subagents analyze files/code and return a summary/resume to the main agent to preserve context!
END OF POST