#13261 · @tomjw64 · opened Feb 12, 2026 at 5:02 AM UTC · last updated Mar 21, 2026 at 9:53 PM UTC
feat(opencode): Support background subagents
Score breakdown
Impact
Clarity
Urgency
Ease Of Review
Guidelines
Readiness
Size
Trust
Traction
Summary
This PR introduces support for asynchronous background subagents, allowing the main agent to remain interactive while subtasks run. It addresses community interest in concurrency by calling SessionPrompt.prompt async and emitting a BackgroundTaskCompleted event. The PR includes detailed verification steps.
Description
Issue for this PR
Closes #5887
Type of change
- [ ] Bug fix
- [x] New feature
- [ ] Refactor / code improvement
- [ ] Documentation
What does this PR do?
The goal of this PR is to support fire-and-forget/async/background tasks in my best approximation of how Claude Code handles it.
This is done by calling SessionPrompt.prompt async and emitting a new BackgroundTaskCompleted event when the promise resolves. The new SessionBackground component listens for these events (and the idle status event) and takes care of flushing the queue of finished task information to the parent session and forcing it to take it a turn with the results of the completed task(s).
This attempts to be a bit more minimal than https://github.com/anomalyco/opencode/pull/7206 to increase the chances of acceptance. I am a first-time contributor to opencode and I almost certainly overlooked something here. I'm happy to receive any suggestions or review.
How did you verify your code works?
I opened opencode and entered the following prompt:
Run 4 general background subagents in parallel. Each one should use bash to
sleep for an amount of time and then print out a random number. Have them sleep
for 10, 18, 18.2, and 18.2 seconds, respectively. Then print out a chart to be
updated as each task notifies you of its completion.
And verified that the agent (tested with Kimi K2.5 Free):
- Could handle additional user interaction before the first subagent completed.
- Woke after the first subagent completed to update the chart.
- Woke a second time after the second subagent completed to update the chart.
- Woke a third and final time after the third and fourth subagents completed (to test that we buffer the results of two completions but still only give the primary agent a single turn once idled again)
Checklist
- [x] I have tested my changes locally
- [x] I have not included unrelated changes in this PR
If you do not follow this template your PR will be automatically rejected.
Linked Issues
#5887 [feat] True Async/Background Sub-Agent Delegation
View issueComments
PR comments
tomjw64
Received some review expressing some concern over task cancellation:
- subagents prompts not cancelled on session delete
- no way of individually cancelling a session in the TUI
We can address (1) in this PR (update: done), but I will open a separate issue for individual issue cancellation (update: done), so that background tasks can be cancelled without e.g. closing out the entire app.
Changed Files
packages/opencode/src/project/bootstrap.ts
+2−0packages/opencode/src/session/background.ts
+99−0packages/opencode/src/session/index.ts
+21−0packages/opencode/src/session/message-v2.ts
+1−0packages/opencode/src/session/prompt.ts
+1−0packages/opencode/src/session/status.ts
+1−2packages/opencode/src/tool/task.ts
+59−13packages/opencode/src/tool/task.txt
+5−0packages/sdk/js/src/v2/gen/types.gen.ts
+21−0