Skip to content

Agents, tasks, and subagents

This page maps the task and subagent surfaces visible in the extracted cli.js.

Source anchors

Semantic aliasSourceApproximate locationString or symbolMeaning
AgentsCommandFamilycli.jsline ~19550, byte 0xdcc1acH.command("agents")Background agents command family.
InlineAgentsFlagcli.jsline ~19525, byte 0xdc1fcb--agents <json>Custom agent definitions injected from root flags.
TaskCreateToolcli.jsline ~1091, byte 0x4804f6var LX="TaskCreate"Task-create tool/action constant.
TaskGetToolcli.jsline ~1091, byte 0x48050avar DQ="TaskGet"Task status/result retrieval constant.
TaskListToolcli.jsline ~1091, byte 0x48051bvar UZ="TaskList"Task list constant.
TaskUpdateToolcli.jsline ~1091, byte 0x48052dvar J0="TaskUpdate"Task update constant.
SubagentLifecycleHookscli.jsline ~185, byte 0x10b75dSubagentStart, SubagentStopSubagent lifecycle hook events.
TaskLifecycleHookscli.jsline ~185, byte 0x10b7d5TaskCreated, TaskCompletedTask lifecycle hook events.
SubagentContextClassifiercli.jsline ~253, byte 0x2104ceagentType==="subagent"Runtime subagent context classifier.
UltraReviewCommandcli.jsline ~19550, byte 0xdcc963H.command("ultrareview [target]")Cloud-hosted multi-agent code-review command.

Agent/task map

flowchart TD
Root[Root flags/commands] --> Custom[--agents JSON custom agents]
Root --> AgentsCmd[claude agents]
Root --> Ultra[ultrareview]
Runtime[Session runtime] --> TaskTools[TaskCreate / TaskGet / TaskList / TaskUpdate]
TaskTools --> Subagent[Subagent runtime context]
Subagent --> Hooks[SubagentStart / SubagentStop]
TaskTools --> TaskHooks[TaskCreated / TaskCompleted]

Confirmed automation surfaces

SurfaceRuntime role
claude agentsManages background agents; root flags on this command pass settings/MCP/plugins/model/permission defaults into dispatched sessions.
--agents <json>Defines custom agents inline for the current session. The help example includes description and prompt fields.
TaskCreate, TaskGet, TaskList, TaskUpdateTask tool/action names used by agent/task orchestration paths.
SubagentStart, SubagentStopHook events around subagent lifecycle.
TaskCreated, TaskCompletedHook events around task lifecycle.
agentType === "subagent"Runtime context marker distinguishing subagent execution.
ultrareview [target]Cloud-hosted multi-agent code-review command.

Background agents command flags

The agents command accepts settings/integration defaults for dispatched sessions, including:

  • --setting-sources
  • --add-dir
  • --plugin-dir
  • --settings
  • --mcp-config
  • --strict-mcp-config
  • --permission-mode
  • --dangerously-skip-permissions
  • --model

This shows that background-agent sessions inherit the same core runtime surfaces as foreground sessions: settings, working directories, plugins, MCP, permissions, and models.

Hosted review

ultrareview [target] is described as a cloud-hosted multi-agent code review command. Adjacent strings include /ultrareview, /review, and /v1/ultrareview/preflight, indicating both local command UX and remote preflight/API surfaces.

Task and subagent runtime internals

This section deepens the surfaces above by mapping the task tool family, subagent lifecycle events, background/scheduled task mechanics, and hosted review surfaces.

Additional anchors

Semantic aliasSourceApproximate locationString or symbolMeaning
TaskCreatePromptcli.jsline ~3860, byte 0x893b91Use this tool to create a structured task list for your current coding sessionTaskCreate prompt/description.
TaskGetDeferredDescriptorcli.jsline ~3921, byte 0x894f87TaskGet, shouldDefer:!0, isReadOnly(){return!0}TaskGet is deferred, concurrency-safe, and read-only.
TaskUpdateFreshnessGuardcli.jsline ~3968, byte 0x8959d4Make sure to read a task's latest state using `TaskGet` before updating it.Task staleness guard in TaskUpdate prompt text.
TaskStoreNotFoundErrorcli.jsline ~99, byte 0x97bc0Task not found:Task-store error path.
TaskUpdateWaitercli.jsline ~99, byte 0x97bfb_waitForTaskUpdateTask polling/wait behavior for not-yet-completed task results.
SubagentStartHookSchemacli.jsline ~2004, byte 0x5120cfSubagentStart, agent_id, agent_typeSubagent start hook input schema.
SubagentStopHookSchemacli.jsline ~2004, byte 0x512146SubagentStop, agent_transcript_path, last_assistant_messageSubagent stop hook input schema.
TaskLifecycleHookSchemacli.jsline ~2004, byte 0x51247aTaskCreated, TaskCompletedTask lifecycle hook input schema.
LargeAgentDescriptionWarningcli.jsline ~5805, byte 0xa164ecLarge agent descriptionsToken-pressure warning for large custom-agent descriptions.
CronSchedulerPromptInjectioncli.jsline ~19354, byte 0xdaa61ecreateCronSchedulerScheduled/recurring task prompt injection inside headless loop.
UltraReviewPreflightApicli.jsline ~6664, byte 0xab2665/v1/ultrareview/preflightHosted review preflight API path.

Task tool family

The task constants are grouped near TodoWrite and Skill, placing task orchestration in the same capability family as planning and skill dispatch: TaskCreate, TaskGet, TaskList, TaskUpdate.

TaskUpdate prompt text defines a status workflow pending → in_progress → completed and also allows deleted. It explicitly tells the model to read fresh task state with TaskGet before updating — a staleness warning implying the runtime expects concurrent/multi-agent task state to change underneath the current agent.

Task result waiting

The task-store path around line ~99 follows a request handler pattern:

  1. Fetch the task by ID.
  2. If absent, throw Task not found: <id>.
  3. If status is non-terminal, wait via _waitForTaskUpdate(...) and retry.
  4. If terminal, fetch the task result, clear the task queue, and include task metadata in _meta.

This is why TaskGet is marked shouldDefer: true — a task query may wait for completion/update rather than returning immediately.

Subagent context and hooks

The runtime has an async-local context classifier agentType === "subagent". Related helpers derive whether the current execution is a built-in or user-defined subagent. Hook schemas then expose subagent lifecycle data:

HookFieldsRuntime meaning
SubagentStartagent_id, agent_typeA subagent execution started.
SubagentStopagent_id, agent_transcript_path, agent_type, last_assistant_messageA subagent stopped and can expose transcript/summary context.
TaskCreatedtask_id, task_subject, optional description/team fieldsA task was created.
TaskCompletedtask_id, task_subject, optional description/team fieldsA task completed.

SubagentStop carrying agent_transcript_path and last_assistant_message indicates that subagent execution is transcript-backed and can surface a concise final message without parsing the full transcript.

Background and scheduled task mechanics

Inside HeadlessControlLoop, when isKairosCronEnabled() is true, the runtime creates a cron scheduler whose onFire callback resolves a loop-default prompt and enqueues it as a later-priority prompt with a workload marker. Scheduled/recurring task behavior is therefore implemented by feeding prompts back into the same headless loop, not by a separate executor.

Custom-agent token pressure

The Large agent descriptions warning is produced when custom-agent descriptions exceed a threshold. It lists the largest contributors and reports total tokens versus threshold — agent descriptions are counted as context budget contributors and can produce warnings before model execution.

Hosted review path

ultrareview [target] is a top-level command described as cloud-hosted multi-agent code review. The preflight API path /v1/ultrareview/preflight checks whether the hosted review can run and returns user-facing blockers such as essential-traffic-only mode and data residency constraints.

Implementation takeaways

  1. Tasks are shared mutable runtime state; TaskGet/TaskUpdate are designed for staleness and concurrency.
  2. Subagents have explicit runtime context, transcript paths, and lifecycle hooks.
  3. Scheduled tasks re-enter the same loop as prompt injections.
  4. Hosted multi-agent review is gated by a preflight API path and traffic/data policy conditions.
  5. Custom-agent descriptions are budgeted as model context and can trigger token-pressure warnings.

Agent communication protocol handoff

The source-confirmed agent/subagent communication surface is not a separate peer socket protocol. It is tool/state/event mediated: SendMessage, TaskCreate, TaskGet, TaskList, and TaskUpdate feed task stores, task queues, transcript-backed subagent contexts, and lifecycle hooks. Remote/team updates such as team_permission_update are typed envelopes on the broader runtime control channel. For the cross-cutting protocol view, see Runtime communication protocols.

Created and maintained by Yingting Huang.