[FEATURE] Enable Subagents to Pass Follow-up Commands to the Main Agent for Execution
Preflight Checklist
- [x] I have searched existing requests and this feature hasn't been requested yet
- [x] This is a single feature request (not multiple features)
Problem Statement
Currently, it's not possible to build a fully automated, single-prompt workflow where one subagent programmatically triggers another. The core issue is that subagents, when invoked via the Task tool, operate in a completely isolated context.
My workflow involves creating modular, specialized agents that can hand off tasks to one another. For example, I want an implementer agent to write code and then, as its final step, trigger a reviewer agent to check that code. I want to initiate this entire sequence with a single command.
While the new SlashCommand tool (v1.0.123) allows a subagent to generate a follow-up command, that command is effectively "trapped" within the subagent's isolated session. The main agent only receives the final text summary from the subagent's Task and is unaware of the follow-up command that was generated. This breaks the chain of automation and prevents true, agent-driven composition, forcing me to use less intuitive workarounds that centralize logic outside of the agents themselves.
Proposed Solution
I propose that the Task tool's result be enhanced to optionally return a "follow-up prompt" or "next command" string to the main agent.
When a subagent completes its execution, the Task tool result passed back to the main agent should be able to contain two fields:
- A final text summary (as it does now).
- An optional follow-up prompt string.
If the main agent receives a Task result with a follow-up prompt, it should:
- Display the text summary to the user.
- Immediately add the follow-up prompt to its own execution queue and run it as the very next step.
This would create a seamless and intuitive handoff mechanism. From a user's perspective, the interaction would be a single, uninterrupted flow. The subagent's final action (e.g., using SlashCommand) would directly and automatically trigger the main agent's next action.
Alternative Solutions
I have explored several workarounds, but none are as clean or as powerful as the proposed solution.
- The "Coordinator Slash Command" Pattern: This is the best current workaround. I create a master slash command that contains a multi-step plan telling the main agent to call Subagent A, then Subagent B.
- Limitation: This centralizes the workflow logic in the slash command, making the agents themselves less autonomous. The
implementeragent can't decide to call thereviewer; the sequence is pre-scripted. It prevents dynamic, conditional chaining based on the first agent's results.
- Manual Two-Step Process: I can run the first subagent, wait for it to complete, and then manually run the slash command to trigger the second subagent.
- Limitation: This is not automated and defeats the purpose of creating an agentic workflow.
- Subagent Instructs the User: I can modify the first subagent's prompt to instruct me, the user, to run the next command.
- Limitation: This still requires manual intervention (copying and pasting) and is prone to user error.
Priority
High - Significant impact on productivity
Feature Category
CLI commands and flags
Use Case Example
Here is a step-by-step walkthrough of the ideal experience for an "implement and review" workflow:
- Setup:
- A subagent named
implementeris defined. Its final instruction is to use theSlashCommandtool to run/review-file <file_path>. - A subagent named
revieweris defined. - A slash command
/review-fileexists, which prompts the main agent to use thereviewersubagent on a file.
- User Interaction (Single Prompt):
````
> Use the implementer agent to add a new function to 'utils.js'
- Execution Flow (Behind the Scenes):
- The main agent invokes the
implementersubagent. - The
implementersubagent writes the new function toutils.js. - As its last action, the
implementeruses theSlashCommandtool to execute/review-file utils.js. - The
SlashCommandtool generates the prompt:"Please use the reviewer subagent to review the file at utils.js". - (Proposed Change) The
Tasktool for theimplementerfinishes, returning both its summary ("I have added the function.") and thefollow_up_promptto the main agent. - The main agent displays the summary to the user and immediately executes the follow-up prompt.
- The main agent invokes the
reviewersubagent onutils.js.
- Final Output:
- The user sees the final, detailed code review from the
reviewersubagent, completing the entire automated chain.
Additional Context
This feature would unlock the true potential of the recently added SlashCommand tool as a mechanism for inter-agent communication.
A potential technical implementation could involve changing the tool_result schema for the Task tool.
Current Task Tool Result (Simplified):
{
"content": [
{
"type": "text",
"text": "Final summary from subagent."
}
]
}
Proposed Task Tool Result (Simplified):
{
"content": [
{
"type": "text",
"text": "Final summary from subagent."
}
],
"follow_up_prompt": "/review-file utils.js" // Optional field
}
This would provide a clean, structured way for subagents to chain actions without breaking their isolation, making Claude Code an even more powerful platform for building complex AI-driven automations.
This issue has 6 comments on GitHub. Read the full discussion on GitHub ↗