subagents.mdx 4.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. ---
  2. title: "Subagents"
  3. sidebarTitle: "Subagents"
  4. description: "Run parallel research agents to explore your codebase without filling the main agent's context window."
  5. ---
  6. Subagents let Cline spawn focused research agents that run in parallel. Each subagent gets its own prompt and context window, explores the codebase independently, and returns a detailed report to the main agent. This keeps the main agent's context clean while gathering broad information fast.
  7. <Tip>
  8. Subagents is an experimental feature. Behavior may change in future releases.
  9. </Tip>
  10. ## How It Works
  11. When Cline uses the `use_subagents` tool, it launches independent agents simultaneously. Each one:
  12. - Gets its own prompt describing what to investigate
  13. - Runs with a separate context window and token budget
  14. - Can read files, search code, list directories, run read-only commands, and use skills
  15. - Cannot edit files, use the browser, access MCP servers, or spawn nested subagents
  16. - Returns a result focused on the most relevant file paths for the main agent to read next
  17. Subagent costs (tokens and API spend) are tracked separately per subagent and rolled into the task's total cost. You can see per-subagent stats (tool calls, tokens, cost) in the chat UI as they run.
  18. ## Enabling Subagents
  19. Subagents are disabled by default. To turn them on:
  20. 1. Open Cline Settings (click the gear icon in the Cline panel)
  21. 2. Go to **Features**
  22. 3. Under the **Agent** section, toggle **Subagents** on
  23. This setting applies across all editors (VS Code, JetBrains, CLI).
  24. ## Using Subagents
  25. Cline does not automatically decide to use subagents. You need to ask for them in your prompt. When the feature is enabled and you mention subagents (or describe a task that benefits from parallel exploration), Cline will use the `use_subagents` tool.
  26. Example prompts:
  27. - "Use subagents to explore how authentication works and where the database models are defined"
  28. - "Spin up subagents to investigate the API routes, the test setup, and the deployment config"
  29. - "I'm new to this codebase. Use subagents to map out the main entry points, the routing layer, and the data access patterns"
  30. Each subagent prompt should describe a focused research question. Cline will run them in parallel and synthesize the results.
  31. You can also run only one subagent when the task is small enough that parallel discovery would be unnecessary overhead.
  32. ## Auto-Approve Behavior
  33. Subagents follow the **Read project files** auto-approve permission. If you have "Read project files" enabled in [Auto Approve](/features/auto-approve), subagent launches will be auto-approved.
  34. In [YOLO mode](/features/auto-approve#yolo-mode), subagents are always auto-approved.
  35. If auto-approve is off, Cline will ask for your approval before launching subagents, showing you the prompts it plans to send.
  36. ## What Subagents Can Do
  37. Subagents are read-only research agents. Here is what they have access to:
  38. | Tool | Purpose |
  39. |------|---------|
  40. | `read_file` | Read file contents |
  41. | `list_files` | List directory contents |
  42. | `search_files` | Regex search across files |
  43. | `list_code_definition_names` | List top-level classes, functions, and methods |
  44. | `execute_command` | Run read-only commands (`ls`, `grep`, `git log`, `git diff`, etc.) |
  45. | `use_skill` | Load and activate skills |
  46. Subagents cannot write files, apply patches, use the browser, access MCP servers, or perform web searches. They also cannot spawn their own subagents.
  47. <Note>
  48. Commands run by subagents execute in the background and are restricted to read-only operations. Subagents will not run commands that modify files or system state.
  49. Subagents also benefit from command pipelines and filters to narrow output quickly before reading files, for example `rg ... | sort | uniq`.
  50. </Note>
  51. ## When to Use Subagents
  52. Subagents work best when you need broad context from multiple areas of a codebase at once:
  53. - **Onboarding to an unfamiliar project**: Ask subagents to map out the architecture, key entry points, and data flow in parallel.
  54. - **Investigating cross-cutting concerns**: Have separate subagents trace authentication, logging, and error handling simultaneously.
  55. - **Pre-edit research**: Before making changes, use subagents to gather context from related files so the main agent can make informed edits without burning through its context window.
  56. - **Large codebases**: When reading many files sequentially would consume too much of the main agent's context, subagents let you explore broadly without that tradeoff.
  57. For small, focused tasks where you already know which files to look at, subagents add unnecessary overhead. Just ask Cline directly.