Task notifications arrive after TaskOutput already returned results
Description
When using background agents via the Task tool with run_in_background=true, followed by TaskOutput with block=true to wait for completion, the <task-notification> messages still arrive after the workflow has moved on.
Steps to Reproduce
- Launch multiple background agents using
Taskwithrun_in_background=true - Call
TaskOutputwithblock=trueon each agent to wait for completion - Receive the full agent outputs and proceed with next steps (e.g., PR creation)
- Observe that
<task-notification>messages arrive afterward, even though the outputs were already retrieved
Expected Behavior
Either:
<task-notification>messages should arrive before or at the same time asTaskOutputreturns, OR<task-notification>messages should be suppressed if the output was already retrieved viaTaskOutput
Actual Behavior
<task-notification> messages arrive asynchronously after TaskOutput has already returned the full results, creating a confusing presentation where it looks like agents completed after the workflow moved on.
Impact
This is a minor UX/presentation issue. The workflow functions correctly - TaskOutput with block=true properly waits for completion. The late-arriving notifications just create confusion when reviewing the conversation flow, making it appear that agents weren't properly awaited before proceeding.
Environment
- Claude Code version: 2.1.20
- Using Task tool with subagent_type for parallel validation agents
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗