Hands-On Guide to Subagents
Subagents let your main chat session offload bounded research, parallel module audits, multi-model consensus reviews, and isolated implementation tasks to child workers — keeping your main context window clean, fast, and economical.
Every child worker runs under Kompile's governed delegation contract: fail-closed vendor containment (no runaway nested subagents), concurrency and budget caps, live transcript inspection, and a mandatory progress exit report so findings never disappear into truncated output.
Looking for architecture details? See the Subagents Deep Dive for the full containment matrix, admission layers, and four-state budget machine.
Before You Start (1 minute)
Inspect your current subagent setup, saved credentials, and installed agent CLIs:
/explain subagents(Outside chat, run kompile explain subagents.)
Check two things in the output:
- Installed runtimes — Kompile can delegate to its own built-in native runner (
kompile) or to managed external CLIs (claude,codex,gemini,opencode,agy,pi,qwen). - Explicit credentials — subagents never silently borrow your parent chat's OAuth login. Make sure the provider/model you want workers to use has a saved credential (
kompile auth list) or an authenticated native CLI.
Step 1 — Set Safe Defaults (/subagent-config)
Before fanning out parallel workers, lock in concurrency limits, budgets, model bans, and a fallback route so a noisy task can never burn through your quota.
Option A: Interactive wizard (recommended)
Inside kompile chat, run bare /subagent-config to open the numbered settings menu, and /subagent-config failover to configure an ordered fallback ladder when a route hits rate limits:
/subagent-config # interactive numbered settings wizard
/subagent-config failover # interactive fallback-ladder wizard
/subagent-config status # print active settings without opening the menuOption B: Ask your agent conversationally
Prompt: "Set subagent limits to 3 concurrent workers per session (4 globally), a 500,000 billed-equivalent token budget, a $2.00 cost cap, and 20 active minutes per worker. Ban
*opus*models for subagents, preload onlyread,grep,glob,edit, andwrite, and show me a dry-run preview before applying."
Your agent previews the exact changes with onboarding(action="configure", section="subagents", dryRun=true) and writes them to ~/.kompile/config/subagent-config.json once you confirm. Changes take effect immediately for the next dispatch without interrupting running workers.
Option C: Direct shortcuts (for quick tweaks)
/subagent-config max 4
/subagent-config per-session 3
/subagent-config budget 500000
/subagent-config cost-budget 2.00
/subagent-config time 20
/subagent-config ban *opus*
/subagent-config preload-tools read,grep,glob,edit,writeKeep Worker Prompts Lean
Subagents inherit progress automatically. Keeping preload-tools focused on the core tools a worker needs — and leaving agents-md on auto and vendor-prompt on replace — avoids paying thousands of repeated schema tokens on every worker turn.
Step 2 — Run Your First Single Subagent (task)
Start with a focused, read-only research task so you can see the full lifecycle without touching files:
Prompt: "Use a subagent to audit
src/auth/for token-refresh edge cases and report every finding with exact file paths and line numbers."
What happens behind the scenes
- Dispatch (
task): Your main agent launches a single child worker with a self-contained brief. - Isolated context: The worker reads files, runs
grep/lsp/code_search, and explores freely without bloating your main chat's context window. - Fail-closed containment: Kompile strips native delegation tools from the child (for example
--disallowedTools Task,Agenton Claude Code,features.multi_agent=falseon Codex,PreToolUsedeny hooks onagy) so it cannot spawn hidden grandchildren. - Mandatory exit report: Before exiting, the worker must post a structured summary through
progress. If it tries to finish without posting, Kompile holds its exit and re-prompts it automatically.
Check the result right away
/progress-reports-subagents 1 # read the worker's structured report
/subagent-breakdown <id> # inspect token breakdown (startup, skills, tools, results)Step 3 — Fan Out Independent Work in Parallel (multi_task)
When a task splits cleanly into independent areas — auditing multiple modules, running separate investigations, or pairing implementation with documentation — ask your agent to run workers in parallel:
Prompt: "Fan out 3 parallel subagents — one for auth & token refresh, one for database migrations, and one for HTTP error handling. Have each post a concise progress report, then synthesize a prioritized fix list."
What happens
- Your agent calls
multi_taskwith one focused brief per worker. - Kompile's admission layer enforces
maxConcurrentPerSessionandmaxConcurrentso parallel fan-outs never overwhelm your machine or rate limits. - Each worker posts its own tagged report (
source=subagent,run_id=<task-id>), which the parent reads and synthesizes for you.
Tips for parallel editing fan-outs
Read-only fan-outs have zero contention. When multiple workers need to edit files at the same time:
- Partition file ownership clearly in the prompt (e.g., "Worker 1 owns
module-a/, Worker 2 ownsmodule-b/"). - Let file locks protect shared files: Kompile's
edit_coordinatorcoordinates locks across concurrent sessions and workers. - Stage risky refactors in drafts: Ask workers to stage changes with
draftso you or the parent agent can review, rebase, and apply them atomically once all workers finish (see Draft Workflow).
Step 4 — Get Independent Verification With Quorum (quorum_task)
Sometimes you don't want three workers doing different work — you want multiple independent voters checking the same high-stakes question so a single model's blind spot doesn't slip through:
Prompt: "Run a quorum review across 3 independent subagent voters on our OAuth callback handler. Have each voter independently check for open redirects, state-replay gaps, and token leakage, then show where they agree and disagree."
Your agent invokes quorum_task, collects independent verdicts from each voter, and surfaces consensus vs. dissenting findings.
| Pattern | MCP Tool | Best For |
|---|---|---|
| Single worker | task | Deep dive into one subsystem, focused bug fix, or targeted test run |
| Parallel fan-out | multi_task | Splitting independent modules, audits, tests, or docs simultaneously |
| Consensus vote | quorum_task | Security reviews, tricky root-cause verification, architecture decisions |
Step 5 — Watch, Steer & Cancel Live Subagents
You never have to fly blind while workers are running.
In Terminal Chat (kompile chat)
- From an empty prompt, press
↓to focus the Process & Subagent Browser below the input box. - Navigate to any
subagentrow — each row displays the worker's vendor/model, elapsed time, and live↑in ↓outtoken counters. - Take action directly from the browser:
Enter— open the worker's bounded live transcript without cluttering your main chat.- Type a message while inspecting the worker — send a direct follow-up to steer it mid-flight.
Delete— cancel a running subagent cleanly.- Select
← [main] Main chat(or pressEsc) to return to your main conversation.
Useful inspection commands anytime in chat:
/subagents # list available subagent routes and active children
/processes # inspect managed background processes and subagents
/progress-reports-subagents 5 # read the 5 most recent subagent progress reports
/timeline # inspect chronological session & subagent eventsIn the Web Harness (kompile chat --web)
Open the /processes tab to monitor every running and completed subagent in real time, inspect live tool calls and logs, send per-subagent follow-up prompts, or click Kill / Cancel on a runaway worker.
From an Agent
Agents inspect parent/child task trees and live output tails directly with task_transcript.
Step 6 — Resume a Worker Instead of Starting Over (subagent_resume)
Every delegated worker conversation is saved durably under .kompile/task-registry/. If a worker just finished a deep audit and now you want it to implement the fix — with all of its file context already warm — resume it instead of paying to re-read the codebase from scratch:
Prompt: "Resume subagent
<id>and have it implement the top two fixes from its report and run the targeted unit tests."
Your agent calls subagent_resume, continuing that exact child thread (with the same agent, or even handing off the saved transcript to a different configured agent).
Resuming a worker that hit its budget
When a subagent reaches 90% of its token, cost, or active-runtime limit, Kompile warns it to wrap up. At 100%, it enters a wind-down checkpoint where only write, edit, and progress remain open so it can save its work and post its report cleanly (BUDGET_EXHAUSTED).
If you want that worker to keep going with a fresh budget, grant it explicitly as the human operator:
/subagent-config refresh <subagent-id>Then ask your agent to resume the worker.
Step 7 — Specialize Workers With Roles & Per-Role Routing
If you repeatedly delegate the same kinds of work (security reviews, test authoring, SQL migrations, docs updates), define reusable roles and route each role to the right model:
1. Create a role
Run bare /roles in chat for the interactive role menu, or ask your agent directly:
Prompt: "Create a
security-reviewerrole focused on auth boundaries, secret hygiene, and input validation, with strict read-only review instructions."
(Your agent saves it via role_manager in .kompile/roles/ for the project or ~/.kompile/roles/ globally.)
2. Pin a model route to that role
/subagent-config role-route security-reviewer <provider/model>Now every subagent dispatched with the security-reviewer role automatically uses that model and persona — while routine exploration workers can stay routed to a faster, cheaper model.
Need Structured Multi-Stage Handoffs & Human Approval Gates?
When you want a repeatable multi-agent pipeline (for example designer → workers → reviewer with explicit delegation edges and human-in-the-loop approval gates), run /workflow create to build a saved Workflow Team. See Interactive Workflows.
Step 8 — Audit Token Spend & Efficiency
After a few delegated runs, check whether your subagents are actually saving you money and tokens:
/cost subagents # dollar spend & token breakdown for subagents only
/cost main # compare against main-thread spend
/cost models # compare spend across models
/subagent-breakdown <id> # see exact startup, skill, tool-schema, and result tokensIf /subagent-breakdown <id> shows high startup overhead:
- Trim
preload-toolsvia/subagent-config preload-tools ...so workers only load the tools they need upfront (they can still load extra groups on demand viaactivate_tools). - Verify
agents-mdis set toautoso runtimes that already readAGENTS.md(opencode,agy) aren't charged for it twice. - Keep
vendor-promptonreplaceforclaude-codeandopencodeso Kompile's compact prompt replaces redundant vendor system prompts.
Quick Reference
| What you want to do | Command / Tool |
|---|---|
| Check active subagent routes, limits & bans | /explain subagents or /subagent-config status |
| Configure caps, budgets, bans, routes & preload | Bare /subagent-config (wizard) |
| Configure fallback models for rate limits | /subagent-config failover (wizard) |
| Run one focused worker | task |
| Fan out independent parallel workers | multi_task |
| Run independent multi-voter consensus | quorum_task |
| Watch live transcripts, follow up, or cancel | Press ↓ in kompile chat, or open Web /processes |
| Read subagent progress reports | /progress-reports-subagents [n] |
| Resume a completed or stopped worker | subagent_resume |
| Grant fresh budget to a budget-exhausted worker | /subagent-config refresh <subagent-id> |
| Create/assign specialized worker personas | Bare /roles or role_manager + /subagent-config role-route |
| Inspect where a worker spent tokens & dollars | /subagent-breakdown <id> and /cost subagents |
Where to Go Next
- Subagents Deep Dive — Full vendor containment matrix, two-layer admission rules, four-state budget machine, and exit-gate mechanics.
- Customizing the Harness With an Agent — Complete
/subagent-configkey reference, Enforcer/Judge tuning, and periodicpolicy_enforcesubagent audits. - Monitors & Reactive Wake-Ups — Process & Subagent Browser controls, completion monitors, and avoiding shell polling loops.
- Edit Coordinator & Message Bus — Multi-agent file locks, FIFO named locks, and peer mailboxes for concurrent editing.
- Cost Estimation & Quota Attribution — Tracking main vs. subagent spend, cache ratios, and provider quota windows.