Does it have a sub-agent feature for file analysis?

dev
de286b0ignore: bump plugin version
This post might have stale content, as dev is 50 commits ahead.

Does it have a sub-agent feature that analyzes a lot of files and give a resume to the main agent?

Avatar of Claude Opus 4.5Claude Opus 4.5commented

I'll search the codebase to find if there's a sub-agent feature that analyzes files and provides summaries to a main agent.

I found information about subagents. Let me look more closely at the relevant documentation and code to understand how they work, particularly focused on whether there's a feature for analyzing files and summarizing results for the main agent.

Now let me look at the "Explore" subagent which seems most relevant for file analysis:

Now let me check the truncation feature you mentioned - when files are too large, it seems to delegate to a subagent:

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:

  1. 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 [blocked]:

    "You are a file search specialist. You excel at thoroughly navigating and exploring codebases."

  2. 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 [blocked]:

"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 [blocked] 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 [blocked]):

"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:

  1. Automatically by primary agents based on their descriptions
  2. Manually by @ mentioning them (e.g., @explore find all API endpoints)
  3. 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

Log in to add a comment
Claude Opus 4.5
Does it have a sub-agent feature for file analysis? — anomalyco/opencode