Delegate to subagents
Let an agent hand one task to another agent, provider, or model, keep working, and read the answer when it finishes — then watch, inspect, and cancel subagents yourself.
14 min read17 pages in Sessions
On this page15
- Before you start
- Step 1: Ask for a second opinion
- Step 2: Watch the subagent card
- Step 3: Let the parent pick up the answer
- Step 4: Find subagents later
- Step 5: Check it from the terminal
- How subagents behave
- Limit the size of answers
- React when a subagent finishes
- For agents: the subagent tools
- If something goes wrong
- Next steps
- Give a subagent its own branch
- Corrective rounds and handoff
- Messages to always-on agents
A subagent is a second agent session that your session's agent starts for one task. The agent writes the task, picks who should do it (another agent, another provider such as Codex, or another model), and keeps working. When the subagent finishes, CompozyOS wakes the agent, and the agent reads the answer and uses it.
At the end of this page you will have asked a Claude session for a second opinion from Codex, watched the subagent run as a card in the transcript, seen the parent pick up the answer on its own, and checked the same subagent from the terminal.
Before you start
- CompozyOS is running (
compozy status) and the Web UI is open on a project. This page uses a project namedcheckout-api. - You have a session with an agent that has CompozyOS tools, for example the default
claudeagent. - A second provider is signed in. This page uses Codex. If Codex isn't signed in, the agent will see that it can't delegate there and tell you; any provider marked as available works.
You don't configure anything to turn subagents on. Every session whose agent has the session tools can delegate.
Step 1: Ask for a second opinion
In the session's composer, write what you want in plain words and send it:
Ask Sol in Codex to review the plan in docs/diff-panel.md. I want a recommendation and the three
biggest risks. Keep working on the edge cases while it does that.The agent first checks who it can delegate to. A row appears in the transcript:
⚒ Checked subagent capabilitiesStep 2: Watch the subagent card
Right after that, a card appears where the agent delegated:
(codex●) Sol: diff panel default and base diff design 7s ›
RunningThe card shows the provider's mark, the task title, agent, reported model and reasoning effort, status, and elapsed time. Progress appears below the runtime details, for example "Reading docs/diff-panel.md". The agent's own work keeps streaming next to it; it doesn't wait.
Things you can do with the card:
- Hover or focus it to see the model, reasoning effort, status, elapsed time, and a short preview of the answer once there is one.
- Click it to inspect its live, read-only transcript in a right drawer. The parent conversation and unsent draft stay in place. Drag the drawer's left edge to resize it; close it with Escape or the close button. On a narrow screen it overlays the conversation.
- Open as session in the drawer opens the child as the current conversation. Its "Subagent of" divider has an Open parent action. ⌘-click (Ctrl-click on Windows and Linux) on a delegated subagent opens its session in a new window instead.
- When the agent starts several subagents at once, they share one group card, such as "3 subagents" with "2 working · 1 done".
The composer's toolbar also has a subagents button, between the context ring and the paperclip. It
stays a quiet icon while no subagent runs; while some do, it shows a small live dot and how many are
running, such as 2. Click it to see the same list as the inspector: the ones working now first,
then Previous subagents. Each row names the model and what the subagent is doing. Clicking a row
slides to that subagent inside the panel: what it was asked to do, the tools it ran, and, when the
provider reports them, its tool and token counts. Subagents goes back, and Open shows the
same drawer as the inspector.
If the parent's turn ends while subagents are still running, a banner above the composer reads "Waiting on subagent Sol: diff panel default and base diff design" (or "Waiting on 2 subagents"). Its Stop button cancels them.
Step 3: Let the parent pick up the answer
When Codex finishes, the card flips to Completed and its elapsed time stops. A moment later the parent agent is woken with a short message — you see it as a new turn — and it reads the result and answers you, for example:
Sol recommends defaulting the panel to "branch" when the session has a worktree. The three biggest
risks it found are …You didn't have to prompt the parent again. If the parent was still in the middle of its turn, the answer reaches it in that turn when the agent supports it; otherwise it starts a new turn as soon as the current one ends, ahead of anything you queued.
Step 4: Find subagents later
Subagent sessions don't crowd the sessions list. The parent's row shows a small chip instead, such as
1/3 while one of three subagents is running. Click the chip to expand a bounded branch beneath
that parent. Click any subagent row to inspect it in the drawer. The Subagents section of the
session inspector also opens the drawer; failed rows stay near the top and finished rows fold into
Previous subagents. Delegated rows have a Stop subagent button while they run. After the
subagents settle, the sidebar chip keeps their total so you can return to their work.
Searching the sessions list still finds subagent sessions.
Step 5: Check it from the terminal
List the subagents of the parent session (use your session id):
compozy session subagents sess-7f3a2c11d09e4b58ID TITLE RUNTIME STATUS ELAPSED
sub-3c9e1f0a7b2d4e61 Sol: diff panel default and base diff design codex/gpt-6.1-sol completed 2m 48sShow one subagent, including its answer:
compozy session subagents show sub-3c9e1f0a7b2d4e61Subagent sub-3c9e1f0a7b2d4e61
Title Sol: diff panel default and base diff design
Parent sess-7f3a2c11d09e4b58 (turn turn-91aa04c2)
Child sess-b41d77e05a3c9f12 (idle)
Runtime codex · gpt-6.1-sol · high · normal
Status completed (result available) · acknowledged
Started 2026-10-08 21:14:03 · settled 2026-10-08 21:16:51 (2m 48s)
Result
Recommendation: default the panel to 'branch' when the session has a worktree ...Your ids, model names, and times will differ. "acknowledged" means the parent agent already read the answer.
The word after the child id is the child session's own activity: working, idle, or stopped. A
finished subagent keeps its completed status even when someone prompts its child session again; the
child then shows working until it goes quiet. Subagents recorded by older versions show no activity.
Cancel a subagent that is still running:
compozy session subagents cancel sub-3c9e1f0a7b2d4e61 --reason "Direction abandoned."Cancel requested for sub-3c9e1f0a7b2d4e61 (Sol: diff panel default and base diff design).Add --json to any of these commands for machine-readable output. The list also filters with
--origin delegated|provider_native, --status running,completed, --limit (default 50, at most
200), and --cursor. To list sessions without subagent sessions, the way the sidebar does:
compozy session list --subagents excludeHow subagents behave
- The subagent receives a self-contained brief. Include the facts it needs in the task or a structured handoff because the parent's conversation and attachments are unavailable.
- Permissions only narrow. A subagent can do what its parent can do, or less. It never gets more. Conversation forks and continued sessions can delegate the tools authorized by their own agent definition. Their source-session link records provenance and does not remove that capability.
- No limits on depth or count. A subagent can start its own subagents. Nothing expires on a timer.
- Shared files. By default, subagents work in the same project and worktree as the parent. Two subagents editing the same file at once can step on each other, so ask for separate files or read-only work.
- Stop means stop. Stopping the parent session stops all its running subagents. Interrupting one
turn doesn't stop them, but their answers no longer wake the parent; read them with
compozy session subagents show. - Approvals stay with the subagent. When a subagent needs your approval, its card reads "Waiting for you". Open it and answer there.
- Restarts preserve work. Results and pending wake-ups survive a CompozyOS restart or crash. Eligible interrupted subagents reload their native sessions and continue once, then deliver their results to the parent. Pending approvals, changed permissions or runtime bindings, and repeated restart failures pause automatic continuation. Explicitly stopping CompozyOS or the parent cancels the work; it does not automatically resume on the next start. See Resume for recovery controls and the attempt limit.
- Archiving follows the parent. Archive or unarchive the parent and its subagents follow. Subagent sessions have no archive action of their own.
Claude can also start its own built-in subagents (its Agent or Task tool). CompozyOS shows those as the same kind of card. Clicking a native card or row opens its own prompt, tool activity and result in the drawer, using the same transcript disclosures. These subagents have no separate session, so there is no Open as session action. Their inner steps stay separate from the parent's work. They can't be canceled on their own; stop the parent's turn instead. When Claude runs one in the background, the card stays Running while it works and changes as soon as that subagent finishes, even if Claude and other subagents keep going: Completed, Failed, or Canceled when Claude stopped it. Its answer preview is Claude's short summary of the subagent's work, which can arrive a moment after the status. If Claude never reports how one went, the card reads Completed without a preview when the turn ends. Stopping the turn early marks a still-running one interrupted.
Limit the size of answers
A long answer is cut before it reaches the parent so one subagent can't flood its context. The default is 60,000 characters; the full answer always stays in the subagent's own session. Change it with:
compozy config set subagents.result_max_chars 20000[subagents]
result_max_chars = 20000 # 1,000–1,000,000; default 60000When an answer is cut, compozy session subagents show --json reports "result_truncated": true.
The parent can recover the complete assistant text with compozy__session_history, passing
session_id from child_session_id, type: "agent_message", and limit: 1. This filters out tool
payloads before reading them. Include turn_id for a specific reply and keep the filter when
paging. If the answer itself is too large, follow the returned artifact continuation to the end.
See [subagents] in the config reference.
React when a subagent finishes
Extensions and config hooks can observe every finished subagent with the subagent.settled hook.
Its payload names the subagent, its parent and child sessions, the final status, the provider and
model, and how long it ran. It also includes isolation and, for isolated subagents, a worktree
object with checkout identity and available Git/PR settlement facts:
{
"event": "subagent.settled",
"isolation": "shared",
"workspace_id": "ws-01",
"subagent_id": "sub-3c9e1f0a7b2d4e61",
"parent_session_id": "sess-7f3a2c11d09e4b58",
"child_session_id": "sess-b41d77e05a3c9f12",
"origin": "delegated",
"status": "completed",
"runtime": { "provider": "codex", "model": "gpt-6.1-sol" },
"duration_ms": 167608
}The existing spawn.pre_create hook also runs before every delegation, with spawn_role: "subagent" and a subagent object holding the title, role, and task_chars. A hook can deny a
delegation the same way it denies a spawn. See the hook event catalog.
For agents: the subagent tools
Agents use four native tools, all in the sessions toolset. Each one needs an active turn in the
calling session.
| Tool | What it does |
|---|---|
compozy__subagent_capabilities | Lists the agents, providers, and models the caller can delegate to, and why any are unavailable. |
compozy__subagent_delegate | Starts a subagent for one self-contained task; mode is async (default) or wait. |
compozy__subagent_status | Reads a subagent's status and answer; reading a finished answer marks it as delivered. |
compozy__subagent_cancel | Cancels a running subagent. |
Capabilities include model lists only for providers with can_delegate: true, capped at 40 entries
per provider. The caller's current model comes first, followed by the provider default.
models_total reports the full catalog count; models_truncated indicates that entries were omitted,
including models hidden for unavailable providers. Any model ID advertised by the provider is accepted
even if it is not listed in this preview; delegation validates the full catalog.
The intended loop is: check capabilities, delegate with mode: "async", end the turn, get woken, call
compozy__subagent_status, answer. The wake message is a pointer, not the answer:
Subagent "Sol: diff panel default and base diff design" (sub-3c9e1f0a7b2d4e61) finished: completed.
Call compozy__subagent_status to read its result.When several subagents settle in the same batch, the wake lists one line per subagent and ends with
Call compozy__subagent_status to read each result.
mode: "wait" blocks until the answer or timeout_ms (default 10 minutes, at most 60). A timeout
doesn't cancel the subagent; the agent is woken later instead. Use
compozy__session_spawn instead when you need a long-lived child with
its own TTL that you prompt repeatedly.
If something goes wrong
| What you see | What to do |
|---|---|
The agent says Provider codex is unavailable: … | Sign in to that provider or turn it on, then ask again. compozy__subagent_capabilities lists the reason for each provider. |
The agent says Model … is not available on codex. Available: … | Ask for one of the listed models, or leave the model out to use the provider's default. |
Subagents require an active turn in the calling session. | Only an agent in the middle of a turn can delegate. Ask the agent to do it in a prompt. |
Subagent cannot widen permissions: … | The task asked for a tool or mode the parent doesn't have. Narrow the request or change the parent's permissions. |
| A card reads Waiting for you | The subagent needs an approval or an answer. Click the card and respond in its session. |
subagent_not_cancelable when you cancel | It's one of Claude's built-in subagents. Stop the parent's turn instead. |
Subagent sessions are archived with their parent session. | Archive or unarchive the parent session. |
subagent_not_found: subagent sub-… not found from the CLI | Check the id with compozy session subagents <session-id>, and that you're on the parent's profile. |
Next steps
Give a subagent its own branch
For independent code changes, ask the agent to delegate with isolation: "worktree":
{
"title": "Add billing retries",
"task": "Implement billing retries, commit the changes, then run compozy worktree deliver.",
"isolation": "worktree",
"base_ref": "origin/main"
}base_ref is optional and only valid with worktree isolation. A fresh delegation defaults to the
caller checkout's current HEAD. A corrective round can inherit the
prior subagent's branch. A new worktree carries committed changes. The branch
name combines the configured run namespace, task title and an ID suffix, so concurrent delegates
with the same title have distinct branches. Shared children inherit the parent's checkout;
isolated children of an isolated subagent start from that checkout's HEAD.
The first prompt tells the child its branch and how to deliver. A failed setup returns
isolation_failed; a denying worktree or spawn hook returns capability_denied.
When the child settles, its wake names the branch and pull request when available. Inspect the
same snapshot with compozy__subagent_status or:
compozy session subagents show <subagent-id>
compozy session subagents show <subagent-id> --jsonThe worktree object includes the ID, name, path, branch, requested base_ref, resolved base_sha,
and observed Git/PR facts. commits_ahead counts from the creation commit, even if the requested
ref moves later. Missing Git fields mean unavailable information. PR status unknown means no
provider or a failed lookup; none means a successful lookup found no PR. Shared subagents have
isolation: "shared" and no worktree object.
The isolated worktree remains after completion, cancellation, parent stop and archive. Use the existing worktree commands to inspect, deliver or remove it. Recovery removes only unadmitted, clean checkouts with no commits beyond the creation commit; changed checkouts are retained.
Settlement fields, including pull_request_status, are omitted while the child is running.
A settled unknown PR status means the forge lookup was unavailable or failed; it does not mean
that no PR exists.
Corrective rounds and handoff
When a subagent's result fails verification or needs another pass, delegate a new task with
prior_subagent_id and handoff. Use a prior subagent ID from the same parent session and workspace.
{
"title": "Fix billing retries edge case",
"task": "Fix the missing exponential backoff clamp and verify with the reproduction script.",
"prior_subagent_id": "sub-3c9e1f0a7b2d4e61",
"handoff": {
"objections": "The backoff loop retries without a jitter cap, saturating the test harness.",
"findings": "Retries work for 429 status codes but fail on 503.",
"files": ["internal/billing/client.go"]
},
"isolation": "worktree"
}Each of handoff.objections and handoff.findings accepts up to 40,000 characters. handoff.files
accepts up to 64 paths of 1,024 characters each. The task and formatted handoff share the
120,000-character prompt limit.
With isolation: "worktree" and an omitted base_ref, the new worktree starts from the prior
subagent's branch, including its committed changes. An explicit base_ref takes precedence. If the
prior subagent used shared isolation, the caller's HEAD stays the default. If it used worktree
isolation and has no associated branch yet, delegation returns invalid_request.
Messages to always-on agents
An agent can address compozy__session_prompt by agent and workspace, instead of a session ID.
CompozyOS resolves the current main when it admits the message, so rotation does not leave an old
address behind. Use compozy agent instance list --peers to discover reachable names and scopes.
An initial, unfiltered list can include a note when access rules hid all candidates. In the
structured result, the optional peers_note gives the reason without identifying hidden peers.
Instance list active_count measures occupied capacity across every workspace in the selected
profiles, independently of row filters and pagination. max_active_instances is the per-profile
cap. An empty filtered page can therefore have a positive count. Native instance lists default to
the caller's agent and workspace and return only authorized instances; CLI lists filter agent names
only with --agent. These capacity semantics apply only to ordinary lists. Peer lists
(peers: true, CLI --peers) leave both capacity fields at zero to mean unavailable,
not unused capacity.
Ensure-main requires an existing instance. Missing native targets return
agent_instance_not_found. Ensure-main does not support dry runs: the native tool rejects
dry_run: true before starting a main, and the CLI has no --dry-run flag for it.
Use agent instance show (native compozy__agent_instance_get) to inspect an instance.
Messages sent to a paused instance return delivery: held; its input queue shows the same held
status. They run after the operator resumes it and retain their identity across daemon restart.
A child requested during a human turn may run while the instance is paused. A child requested by
an autonomous turn waits, and a delegate with wait:true returns held immediately. Messages keep
the sender's agent authority and never count as operator approval.