[PR #13261] feat(opencode): Support background subagents #14586

Open
opened 2026-02-16 18:19:22 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/13261

State: open
Merged: No


What does this PR do?

Closes https://github.com/anomalyco/opencode/issues/5887

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)
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/13261 **State:** open **Merged:** No --- ### What does this PR do? Closes https://github.com/anomalyco/opencode/issues/5887 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)
yindo added the pull-request label 2026-02-16 18:19:22 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14586