Skip to content

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:

text
/explain subagents

(Outside chat, run kompile explain subagents.)

Check two things in the output:

  1. 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).
  2. 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.

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:

text
/subagent-config             # interactive numbered settings wizard
/subagent-config failover    # interactive fallback-ladder wizard
/subagent-config status      # print active settings without opening the menu

Option 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 only read, grep, glob, edit, and write, 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) ​

text
/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,write

Keep 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 ​

  1. Dispatch (task): Your main agent launches a single child worker with a self-contained brief.
  2. Isolated context: The worker reads files, runs grep / lsp / code_search, and explores freely without bloating your main chat's context window.
  3. Fail-closed containment: Kompile strips native delegation tools from the child (for example --disallowedTools Task,Agent on Claude Code, features.multi_agent=false on Codex, PreToolUse deny hooks on agy) so it cannot spawn hidden grandchildren.
  4. 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 ​

text
/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_task with one focused brief per worker.
  • Kompile's admission layer enforces maxConcurrentPerSession and maxConcurrent so 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:

  1. Partition file ownership clearly in the prompt (e.g., "Worker 1 owns module-a/, Worker 2 owns module-b/").
  2. Let file locks protect shared files: Kompile's edit_coordinator coordinates locks across concurrent sessions and workers.
  3. Stage risky refactors in drafts: Ask workers to stage changes with draft so 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.

PatternMCP ToolBest For
Single workertaskDeep dive into one subsystem, focused bug fix, or targeted test run
Parallel fan-outmulti_taskSplitting independent modules, audits, tests, or docs simultaneously
Consensus votequorum_taskSecurity 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) ​

  1. From an empty prompt, press ↓ to focus the Process & Subagent Browser below the input box.
  2. Navigate to any subagent row — each row displays the worker's vendor/model, elapsed time, and live ↑in ↓out token counters.
  3. 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 press Esc) to return to your main conversation.

Useful inspection commands anytime in chat:

text
/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 events

In 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:

text
/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-reviewer role 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 ​

text
/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:

text
/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 tokens

If /subagent-breakdown <id> shows high startup overhead:

  • Trim preload-tools via /subagent-config preload-tools ... so workers only load the tools they need upfront (they can still load extra groups on demand via activate_tools).
  • Verify agents-md is set to auto so runtimes that already read AGENTS.md (opencode, agy) aren't charged for it twice.
  • Keep vendor-prompt on replace for claude-code and opencode so Kompile's compact prompt replaces redundant vendor system prompts.

Quick Reference ​

What you want to doCommand / Tool
Check active subagent routes, limits & bans/explain subagents or /subagent-config status
Configure caps, budgets, bans, routes & preloadBare /subagent-config (wizard)
Configure fallback models for rate limits/subagent-config failover (wizard)
Run one focused workertask
Fan out independent parallel workersmulti_task
Run independent multi-voter consensusquorum_task
Watch live transcripts, follow up, or cancelPress ↓ in kompile chat, or open Web /processes
Read subagent progress reports/progress-reports-subagents [n]
Resume a completed or stopped workersubagent_resume
Grant fresh budget to a budget-exhausted worker/subagent-config refresh <subagent-id>
Create/assign specialized worker personasBare /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 ​

Released under the Apache-2.0 License.