Background tasks
Long-running work doesn't have to block the agent. With background: true (the default), the agent can detach slow shell commands and subagent batches into background tasks, keep working in the foreground, and pick up the results when they land. You get incremental output polling, cancellation, and a background_completed event per finished task — all surfaced through the normal event stream.
Use it
Nothing to configure — background tasks are on by default. The model opts in per call:
bashwithrun_in_background: trueruns detached — it returns abg_…id immediately and never blocks the run's end. Poll incremental output with theBashOutputtool; the process is stopped automatically when the run ends.Agentwithrun_in_background: true(opt-in; blocking is the default) dispatches a subagent batch as one joinable task — the run stays alive until it finishes, and the aggregated result arrives as a<background-task-completed>notification.KillBackgroundcancels any running background task by id.
Detached vs. joinable: a detached task (background bash) is fire-and-forget — the run may end while it runs, and it is stopped at run end. A joinable task (background Agent) keeps the run alive until it completes, so its result is always delivered.
The background_completed event
As each task finishes, a background_completed event is emitted into the run's event stream (and persisted into the session log like every other event):
This makes background completions visible to UIs and audit sinks — see Observability.
Options
backgroundLimits fields:
Built-in tools
Both are registered only when background is enabled, and can be filtered like any other tool via allowedTools / disallowedTools.
See also
- Subagents — the
Agenttool and background dispatch. - Observability — consuming
background_completedevents. - Checkpointing — background completions land in the session event log.