[Bug] Background agents output files remain empty (0 bytes) - run_in_background=true broken
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?
Bug Report: Background agents output files remain empty (0 bytes)
Summary
When launching sub-agents with run_in_background=true, the output files are created but remain empty (0 bytes). The agent work is executed (confirmed by system notifications showing tool usage and token consumption), but results are never written to the output files and cannot be retrieved.
Environment
- OS: Windows 10/11 (MINGW64_NT-10.0-26200)
- Platform: win32
- Claude Code Version: Latest as of January 9, 2026
- Model: claude-opus-4-5-20251101
Steps to Reproduce
- Launch a sub-agent with
run_in_background=true:
Task tool call:
- description: "Test background agent"
- prompt: "List all Use Cases in src/application/use-cases/"
- subagent_type: "codebase-analyzer"
- run_in_background: true
- Wait for agent completion (system notifications confirm progress: "25 new tools used, 50237 new tokens")
- Receive task completion notification with output file path
- Attempt to read the output file
Expected Behavior
The output file should contain the agent's results/findings.
Actual Behavior
- Output file is created at the specified path
- File size remains 0 bytes even after agent completion
Readtool returns: "Warning: the file exists but is shorter than the provided offset"TaskOutputtool returnsstatus: completedbut no contentcatcommand on the file produces no output
Diagnostic Evidence
File listing showing 0-byte files:
$ ls -la /c/Users/.../tasks/
-rw-r--r-- 1 User 197121 0 Jan 9 17:49 a4b6c47.output
-rw-r--r-- 1 User 197121 0 Jan 9 17:49 aa80314.output
-rw-r--r-- 1 User 197121 0 Jan 9 17:49 aecb4d8.output
TaskOutput returns no content:
<retrieval_status>success</retrieval_status>
<task_id>a4b6c47</task_id>
<task_type>local_agent</task_type>
<status>completed</status>
<!-- No actual output/results -->
System notifications confirm agents ARE working:
Agent aecb4d8 progress: 25 new tools used, 50237 new tokens
Agent a4b6c47 progress: 10 new tools used, 29172 new tokens
Agent aa80314 progress: 35 new tools used, 35686 new tokens
Workaround
Synchronous agents work correctly. When launching agents WITHOUT run_in_background=true, results are returned properly:
Task tool call (synchronous):
- description: "Test synchronous agent"
- prompt: "List TypeScript files in src/domain/"
- subagent_type: "Explore"
- run_in_background: false (or omitted)
Result: Successfully returns agent findings
Comparison Table
| Mode | File Created | File Size | Results Returned |
|------|--------------|-----------|------------------|
| run_in_background=true | Yes | 0 bytes | No |
| run_in_background=false | Yes | 0 bytes | Yes (inline) |
Impact
- Cannot run multiple research agents in parallel
- Cannot perform deep codebase analysis that benefits from background processing
- Forces sequential agent execution, reducing efficiency
- Breaks workflows that depend on background agent results
Timeline
- Working: Before January 2026
- Broken: Noticed around January 7-9, 2026
Additional Context
This bug affects all agent types tested:
Explorecodebase-locatorcodebase-analyzer
The issue appears to be in the mechanism that writes agent results to the temporary output files, not in the agents themselves (they execute successfully based on token/tool usage metrics).
What Should Happen?
When launching sub-agents with run_in_background=true:
- The output file should contain the agent's complete results/findings after task completion
- The
TaskOutputtool should return the actual content produced by the agent - The
Readtool should be able to retrieve the agent's output from the specified output file
Currently, synchronous agents (without run_in_background) return results correctly - the same should work for background agents.
Error Messages/Logs
Steps to Reproduce
- Launch any sub-agent with
run_in_background=trueparameter:
- Example: Task tool with subagent_type="Explore" or "codebase-analyzer"
- prompt: any research task like "List files in src/"
- run_in_background: true
- Wait for agent completion (system notifications show progress: "X new tools used, Y new tokens")
- Receive task completion notification with output_file path
- Try to read the output file using:
- Read tool → returns "file exists but is shorter than the provided offset"
- TaskOutput tool → returns status "completed" but no content
- Bash: ls -la shows file size = 0 bytes
- Bash: cat produces no output
- Compare with synchronous agent (same task without run_in_background=true):
- Results are returned correctly inline
Claude Model
Not sure / Multiple models
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
2.1.2
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
PowerShell
Additional Information
_No response_
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗