Background agents complete but output files are empty

Resolved 💬 3 comments Opened Jan 27, 2026 by dmcnelis Closed Jan 31, 2026

Summary

When launching Task agents with run_in_background: true, the agents complete successfully (status shows "completed") but their output files are empty. This requires re-running agents without the background flag to get actual results.

Environment

  • Product: Claude Code CLI
  • Platform: Windows 11

Steps to Reproduce

  1. Launch multiple Task agents with run_in_background: true
  2. Wait for all agents to complete (TaskOutput returns status: "completed")
  3. Attempt to read the output files using the Read tool or cat command

Expected Behavior

The output files at the paths provided in the Task tool response should contain the agent's output/results.

Example expected output file path:

C:\Users\...\AppData\Local\Temp\claude\...\tasks\a10faa3.output

This file should contain the agent's analysis, findings, and conclusions.

Actual Behavior

  1. Task tool returns successfully with output_file path:
Async agent launched successfully.
agentId: a10faa3
output_file: C:\Users\...\tasks\a10faa3.output
  1. TaskOutput confirms completion:
<retrieval_status>success</retrieval_status>
<task_id>a10faa3</task_id>
<task_type>local_agent</task_type>
<status>completed</status>
  1. But reading the output file returns empty or minimal content:
# Using Read tool:
Warning: the file exists but is shorter than the provided offset (1). The file has 1 lines.

# Using cat:
(no output)
  1. Eventually, task-notification messages arrive with the actual results, but by then the workflow has been interrupted.

Workaround

Re-run the agents without run_in_background: true to get results synchronously. This defeats the purpose of parallel agent execution.

Impact

  • Workflow disruption: Cannot process parallel agent results efficiently
  • Wasted time: Must re-run agents synchronously after discovering empty outputs
  • Unreliable parallel execution: Background agents cannot be trusted to produce usable output

Session Details

During a PR review workflow:

  • Launched 5 agents in parallel (code-reviewer, pr-test-analyzer, silent-failure-hunter, comment-analyzer, code-simplifier)
  • All 5 returned "completed" status via TaskOutput
  • All 5 output files were empty when read
  • Had to re-run each agent synchronously to get actual results

Additional Context

This has happened multiple times, suggesting this is a recurring issue rather than a one-time failure.

Suggested Investigation Areas

  1. Race condition between agent completion and output file write
  2. Output file being written to wrong location
  3. Output stream not being flushed before marking task complete
  4. Windows-specific file path or encoding issue
  5. Task completion notification sent before output fully written

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗