docs/design/2026-07-16-default-background-subagents.md
Top-level one-shot subagents should run in the background by default. Callers
that require an inline result can opt out with run_in_background: false.
Nested subagent launches and launches pinned to a caller-owned working_dir
remain foreground operations because the current background lifecycle cannot
safely return results to those callers. Forks and named Agent Teams teammates
keep their existing behavior.
The Agent tool already supports background execution across interactive,
headless, and SDK consumers, but callers must currently request it with
run_in_background: true or select an agent declared with background: true.
This makes ordinary delegation block the parent by default even when the parent
could continue independent work. Making background execution the top-level
default better matches the tool's parallel delegation guidance while retaining
an explicit foreground escape hatch for result-dependent work.
run_in_background is omitted.run_in_background: false as an explicit foreground opt-out.working_dir.The runtime resolves one-shot subagent execution in this order:
working_dir and no configured background
default runs in the foreground because the caller owns that worktree's
lifecycle. An explicit or configured background request remains invalid.run_in_background: false runs in the foreground.run_in_background: true runs in the background.run_in_background runs in the background.The existing agent-level background: true frontmatter remains accepted for
compatibility. It is no longer necessary to obtain the new top-level default.
An explicit tool-call value of run_in_background: false takes precedence and
selects the foreground path.
The dispatch decision remains in the Agent tool so every consumer receives the same behavior. The background decision should distinguish three concepts:
The implementation should reuse the existing background branch rather than add
a second launch path. Tool schema text and model-facing usage guidance should
describe background as the default and tell callers to pass
run_in_background: false when they need the result inline.
The working_dir exception must be resolved before the existing incompatibility
guard. An omitted background parameter must not turn previously valid pinned
review launches into errors. An explicit run_in_background: true or an agent
configured with background: true remains incompatible with working_dir,
preserving the existing safety check.
A default-background launch returns the existing background-launch response to the parent immediately. The detached task remains registered with the existing background task registry. When it terminates, the registry emits the existing completion, failure, or cancellation notification and the parent processes the result in a later turn. No new message format or SDK event is introduced.
Foreground opt-outs continue through the existing synchronous branch and return the sanitized subagent result inline.
The subagent user guide should state that named one-shot subagents run in the
background by default at the top level and explain
run_in_background: false. The fork comparison should focus on context
inheritance and result semantics rather than claiming that all named subagents
block the parent.
Unit coverage should verify:
run_in_background: false returns the result inline;run_in_background: true retains the existing background behavior;working_dir launch with an omitted flag remains foreground;working_dir remains rejected;Existing tests that intentionally exercise the foreground branch should pass
run_in_background: false so their expectation is explicit. The focused Agent
tool test file, build, and typecheck are required before submission. A manual
interactive E2E check should confirm that a normal delegation returns control
immediately and later delivers a completion notification, while an explicit
foreground delegation blocks and returns its result inline.
The change is behaviorally breaking for prompts, skills, and programmatic
callers that omit the flag and assume the Agent tool response contains the
subagent result. Those callers must pass run_in_background: false.
Default background execution can also increase concurrent work. Existing global concurrency limits and queueing remain the controlling safeguards. Permission handling, shutdown, and headless waiting already use the established background task lifecycle and are not changed by this design.