[BUG] run_in_background=true Task agents silently lose all output unless Write tool explicitly called
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
When spawning Task agents with run_in_background=true, the agent's response is silently discarded after completion. The output file referenced in the task notification exists but is empty (0 bytes). All agent work is lost without any error or warning.
Steps to reproduce:
- Spawn a Task agent with run_in_background: true and a prompt requesting analysis
- Wait for task-notification showing status: completed
- Read the output file - it's empty despite agent completing "successfully"
Workarounds attempted (all failed):
- Adding explicit "You MUST use the Write tool" instructions
- Adding "Your work will be LOST if you only return text" warnings
- Background agents don't reliably follow Write tool instructions
Current workaround: Avoid run_in_background=true entirely; use blocking execution.
What Should Happen?
Background agent responses should be captured to the output file, same as blocking execution. Alternatively, if this is intentional behavior, there should be a clear warning when spawning background agents that their conversational output will not be captured.
Error Messages/Logs
No errors are surfaced. That's part of the problem - silent data loss.
Task tool result:
agentId: a6bc4c0
output_file: C:\Users\...\tasks\a6bc4c0.output
status: completed
Reading output file:
(empty - 0 bytes)
Agent completes with success status but output file contains nothing.
Steps to Reproduce
Steps to reproduce
- Spawn a Task agent with run_in_background: true:
Task({
subagent_type: "general-purpose",
run_in_background: true,
prompt: "Analyze these files and report findings: [file list]"
})
- Wait for task-notification showing status: completed
- Read the output file referenced in the notification:
Read(output_file path from notification)
- Output file is empty (0 bytes) - all agent analysis is lost
Note: Adding explicit Write tool instructions to the prompt ("You MUST use Write tool to save output") does not reliably fix this - background agents don't consistently follow these instructions.
Claude Model
Opus
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.2
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
Windows Terminal
Additional Information
- Spawned 5 parallel agents with run_in_background: true - all 5 completed but produced zero output
- Agents were instructed to write to specific file paths with warnings like "Your work will be LOST if you only return text without calling Write tool" - still no output
- The designated output directory was never created, confirming agents didn't call Write tool despite explicit instructions
- This appears to be a fundamental issue with how background agent responses are handled, not a prompt engineering problem
- Blocking execution (run_in_background: false or omitted) works correctly and captures agent responses
- Discovered in Claude Code CLI session on 2026-01-08
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗