Spawn Agent
Use a supported coding-agent CLI in headless mode for one self-contained subtask. This file is the shared workflow; each harness reference owns that CLI's flags, permissions, output, authentication, and gotchas.
Supported harnesses
| Harness |
CLI |
Reference |
| Google Antigravity CLI |
agy |
references/antigravity.md |
| Claude Code |
claude |
references/claude.md |
| Cursor Agent |
agent |
references/cursor.md |
| Codex CLI |
codex |
references/codex.md |
If the user names a harness with no reference here, such as Gemini CLI, say it is unsupported and offer a supported harness. Never invent CLI flags from memory; headless interfaces vary by tool and release.
Dispatch
- Select the harness: the one the user named; otherwise the host's CLI if supported; otherwise an installed supported CLI.
- Check availability with
command -v <cli> before composing a command. If it is missing, stop and give installation guidance; never substitute another harness silently.
- Read that harness's reference. Follow it for flags, permissions, output parsing, session resumption, and authentication errors.
Check authentication reactively: run the command, then handle a not-logged-in error as the reference directs. Never inline credentials in a command, settings file, or committed script to make a run work.
Workflow (all harnesses)
Decide whether to spawn at all.
- Spawn when the subtask needs an isolated context window; a different working directory, repository, or Git worktree; a scriptable CI or build step; or an agent host with no suitable built-in subagent.
- Do not spawn when the host's built-in subagent or task tool fits, or for work the host can do directly; it keeps the host's context and usually costs less.
- Do not spawn for anything that needs interactive approval or a terminal UI; headless runs cannot prompt a human.
Make the subtask self-contained.
- The spawned run has no conversation history. Put the goal, relevant paths, constraints, and exact expected output in the prompt.
- Pass large inputs as file paths, not inline text.
Pass behavior-affecting settings explicitly.
- Headless runs inherit local settings, extensions, and project memory, so identical commands can differ across machines. Set the model, permission mode, and directory access per the harness reference.
Pre-authorize every tool the subtask needs.
- A headless run cannot ask for approval. An unapproved tool call may be denied or skipped while the run still reports success, so under-granting can look like success.
- Use the reference's permission flags. Fully unattended bypass also allows unrestricted shell and network access: use it only in a sandbox or throwaway working copy, and say so.
Bound the run before starting it.
- Set the CLI's turn or iteration limit when available, and wrap the call in the host's timeout, such as
timeout 600 <cli> ....
Pick the output format the caller can parse.
- JSON for programmatic use; streaming for progress on long runs.
Run it, then verify the outcome instead of trusting the text.
- Exit 0 or a plausible result is not proof. Before reporting success, confirm the artifact with
git status, git diff, or file inspection.
- Treat every non-zero status as failure and report stderr with the exit code. If a tool lacked approval, correct the grant from step 4 and rerun; do not switch to a bypass mode just to silence the error.
Continue a spawned conversation only through the harness's documented session-resume mechanism.
Gotchas
- Tell the spawned run not to launch further agents unless the user requested nested delegation; nesting can multiply cost without being visible to the caller.
- Do not use a spawned run to launch a long-lived server; background work it starts is torn down when the run ends.
- Flags and behavior change between releases. Do not run
--help as a preflight. Consult --help and the official documentation linked from the harness reference only for uncovered behavior or after a flag or output failure; then update the reference if it has drifted.
1---2name: spawn-agent-23description: Spawn a headless coding-agent CLI run (such as `agy -p`, `claude -p`, `agent -p`, or `codex exec`) for one scoped subtask. Use when the user asks to delegate work to another agent instance, run an agent CLI non-interactively, automate a headless agent in a script, build, or CI step, or fan work out across isolated sessions. Do not use for interactive agent sessions or when the host's own subagent, task, or agent tool already fits.4---56# Spawn Agent78Use a supported coding-agent CLI in headless mode for one self-contained subtask. This file is the shared workflow; each harness reference owns that CLI's flags, permissions, output, authentication, and gotchas.910## Supported harnesses1112| Harness | CLI | Reference |13| ---------------------- | -------- | --------------------------- |14| Google Antigravity CLI | `agy` | `references/antigravity.md` |15| Claude Code | `claude` | `references/claude.md` |16| Cursor Agent | `agent` | `references/cursor.md` |17| Codex CLI | `codex` | `references/codex.md` |1819If the user names a harness with no reference here, such as Gemini CLI, say it is unsupported and offer a supported harness. Never invent CLI flags from memory; headless interfaces vary by tool and release.2021## Dispatch22231. Select the harness: the one the user named; otherwise the host's CLI if supported; otherwise an installed supported CLI.242. Check availability with `command -v <cli>` before composing a command. If it is missing, stop and give installation guidance; never substitute another harness silently.253. Read that harness's reference. Follow it for flags, permissions, output parsing, session resumption, and authentication errors.2627Check authentication reactively: run the command, then handle a not-logged-in error as the reference directs. Never inline credentials in a command, settings file, or committed script to make a run work.2829## Workflow (all harnesses)30311. Decide whether to spawn at all.32 - Spawn when the subtask needs an isolated context window; a different working directory, repository, or Git worktree; a scriptable CI or build step; or an agent host with no suitable built-in subagent.33 - Do not spawn when the host's built-in subagent or task tool fits, or for work the host can do directly; it keeps the host's context and usually costs less.34 - Do not spawn for anything that needs interactive approval or a terminal UI; headless runs cannot prompt a human.35362. Make the subtask self-contained.37 - The spawned run has no conversation history. Put the goal, relevant paths, constraints, and exact expected output in the prompt.38 - Pass large inputs as file paths, not inline text.39403. Pass behavior-affecting settings explicitly.41 - Headless runs inherit local settings, extensions, and project memory, so identical commands can differ across machines. Set the model, permission mode, and directory access per the harness reference.42434. Pre-authorize every tool the subtask needs.44 - A headless run cannot ask for approval. An unapproved tool call may be denied or skipped while the run still reports success, so under-granting can look like success.45 - Use the reference's permission flags. Fully unattended bypass also allows unrestricted shell and network access: use it only in a sandbox or throwaway working copy, and say so.46475. Bound the run before starting it.48 - Set the CLI's turn or iteration limit when available, and wrap the call in the host's timeout, such as `timeout 600 <cli> ...`.49506. Pick the output format the caller can parse.51 - JSON for programmatic use; streaming for progress on long runs.52537. Run it, then verify the outcome instead of trusting the text.54 - Exit 0 or a plausible result is not proof. Before reporting success, confirm the artifact with `git status`, `git diff`, or file inspection.55 - Treat every non-zero status as failure and report stderr with the exit code. If a tool lacked approval, correct the grant from step 4 and rerun; do not switch to a bypass mode just to silence the error.56578. Continue a spawned conversation only through the harness's documented session-resume mechanism.5859## Gotchas6061- Tell the spawned run not to launch further agents unless the user requested nested delegation; nesting can multiply cost without being visible to the caller.62- Do not use a spawned run to launch a long-lived server; background work it starts is torn down when the run ends.63- Flags and behavior change between releases. Do not run `--help` as a preflight. Consult `--help` and the official documentation linked from the harness reference only for uncovered behavior or after a flag or output failure; then update the reference if it has drifted.