Background local_agent tasks never write to .output file (always 0 bytes)
Bug Description
Background local_agent tasks (spawned via the Task tool with run_in_background: true) create a .output file but never write content to it. The file is always 0 bytes. This means TaskOutput always returns an empty string for agent results, even though the agent completed successfully and produced output.
local_bash background tasks work correctly — their output files contain the expected content.
Environment
- Platform: Windows 10 + Git Bash (MINGW64)
- Claude Code version: 2.1.42
- Node.js: via npm global install
Evidence
- 70+ agent output files (task IDs prefixed with
a) across multiple projects: all 0 bytes - 5+ bash output files (task IDs prefixed with
b) in same temp directory: all have content - Agent JSONL session files confirm agents ran successfully (100KB–500KB of transcript data, 16–39+ assistant turns, successful tool calls, text output generated)
- The agent's result text IS computed and included in the
f31completion notification (via<result>XML tag), butTaskOutputreads from the empty file, not the notification
Root Cause (from source analysis of cli.js)
The OK1 function is the only function that writes to .output files (via appendFile from fs/promises). It is called from:
stdoutStream.on("data")handlers (4 call sites) — forlocal_bashtasks ✅iQYpolling loop (1 call site) — forremote_agenttasks ✅- Nothing — for
local_agenttasks ❌
The f31 function handles local_agent completion. It sends a notification with the result text inline (<result>${w}</result>) but never calls OK1(A, w) to write the result to the output file.
The w01 function creates the output file as empty (writeFileSync(path, "", "utf8")), and since no code path ever appends to it for local agents, it stays empty.
TaskOutput (QZ6 function) reads the file via O$6(A.id) → readFileSync, gets empty string, and returns result: "".
Suggested Fix
Add OK1(A, w) call in f31 before sending the notification, so the result text is written to the output file:
// In f31, before constructing the notification:
if (w) OK1(A, w);
Or alternatively, wire up the iQY polling mechanism for local_agent tasks the same way it works for remote_agent tasks.
Workaround
Instruct agents to write their output to a known file path (e.g., .claude/tmp/report.md) using the Write tool, and have the parent read that file instead of relying on TaskOutput. This bypasses the broken .output file entirely.
Impact
- All background agent results are silently lost on affected platforms
- Parent session falls back to re-reading files manually, wasting the agent's entire token cost
- Users see "Agent outputs were empty" without understanding it's a systematic framework bug
- The notification mechanism delivers the result text, but
TaskOutputdoesn't use it
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗