claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[Bug] TaskOutput returns raw JSONL transcript instead of subagent summary (regression in 2.0.77)

Open peterjrichens opened this issue 10 months ago • 4 comments

Description

When using TaskOutput to retrieve results from a subagent, the tool result contains raw JSONL session transcript data instead of the subagent's actual findings/summary. This completely undermines the purpose of subagents, which is context isolation - the main agent now receives the full subagent conversation (including all tool inputs and outputs) in its context window.

This is a regression introduced in v2.0.77. Version 2.0.76 correctly returned a summarized format ([Tool: Name] {args} + --- RESULT --- with actual findings).

Related Issue

See #17208 which describes the same problem but was filed as a feature request. This is actually a regression from previously working behavior.

Environment

  • Last working version: 2.0.76
  • First broken version: 2.0.77
  • OS: macOS

Reproduction Steps

claude --output-format stream-json --verbose --print \
  "launch the Explore subagent in the background to summarize the code base. After 5 seconds check on its progress and tell me what it found with its first tool call" \
  > /tmp/claude_subagent_test.jsonl

Then inspect the TaskOutput tool_result message in the JSONL output.

Expected Behavior (worked in 2.0.76)

The <output> section in the tool_result should contain a clean summary of the subagent's findings:

<retrieval_status>success</retrieval_status>
<task_id>af9675b</task_id>
<task_type>local_agent</task_type>
<status>completed</status>
<output>
[Tool: Bash] {"command":"ls -la","description":"List files"}
[Tool: Read] {"file_path":"/src/main.py"}

--- RESULT ---
## Codebase Summary

The codebase is a Python/FastAPI application with the following structure:
- src/: Main application code
- tests/: Test suites
...
</output>

Actual Behavior (broken since 2.0.77)

The <output> section contains the raw JSONL session transcript:

<retrieval_status>success</retrieval_status>
<task_id>af9675b</task_id>
<task_type>local_agent</task_type>
<status>completed</status>
<output>
[Truncated. Full output: /tmp/claude/-private-tmp/tasks/af9675b.output]

{"parentUuid":null,"isSidechain":true,"userType":"external","cwd":"/private/tmp",...,"message":{"role":"user","content":"Explore and summarize the codebase..."},...}
{"parentUuid":"...","message":{"model":"claude-haiku-4-5-20251001","role":"assistant","content":[{"type":"tool_use","id":"toolu_01...","name":"Bash","input":{"command":"ls -la /private/tmp"}}],...}
{"parentUuid":"...","message":{"role":"user","content":[{"tool_use_id":"toolu_01...","type":"tool_result","content":"total 4216\ndrwxrwxrwt  492 root..."}]},...}
...
</output>

The main agent receives:

  • The subagent's initial prompt
  • Every tool call the subagent made (Bash, Glob, etc.)
  • The full output of every tool call (file listings, command outputs, etc.)
  • All intermediate assistant messages

Impact

  1. Broken context isolation: The main agent sees 100% of subagent tokens, negating the primary benefit of subagents
  2. Unusable output: The main agent receives garbage (raw JSON with UUIDs, timestamps, token usage) instead of actionable findings
  3. Context explosion: With multiple TaskOutput calls, the main agent's context fills with redundant subagent transcripts

peterjrichens avatar Jan 12 '26 02:01 peterjrichens

This issue has been affecting me as well.

Because of this bug, we run into this error in the claude-agent-sdk-python when the agent tries to read the large content from the subagent's output:

Fatal error in message reader: Failed to decode JSON: JSON message exceeded maximum buffer size of 1048576 bytes..

smithla02 avatar Jan 12 '26 04:01 smithla02

This issue has been affecting me as well.

Because of this bug, we run into this error in the claude-agent-sdk-python when the agent tries to read the large content from the subagent's output:

Fatal error in message reader: Failed to decode JSON: JSON message exceeded maximum buffer size of 1048576 bytes..

What version of the claude agents sdk are you running with "@anthropic-ai/claude-agent-sdk": "^0.2.5" I am not seeing this issue. The key is prompting both the orchestrator and the agent.

the SubAgentStop hook does not return the full transcript by default. It returns whatever your prompt instructs it to return.

markojak avatar Jan 12 '26 20:01 markojak

@peterjrichens in your original Issue are saying that Claude Code CLI didn't have this problem before? How did you setup the prompting between the main orchestrator agent and sub agent in order to return only the following output:

<retrieval_status>success</retrieval_status>
<task_id>af9675b</task_id>
<task_type>local_agent</task_type>
<status>completed</status>
<output>
[Tool: Bash] {"command":"ls -la","description":"List files"}
[Tool: Read] {"file_path":"/src/main.py"}

--- RESULT ---
## Codebase Summary

The codebase is a Python/FastAPI application with the following structure:
- src/: Main application code
- tests/: Test suites
...
</output>

markojak avatar Jan 12 '26 20:01 markojak

@markojak here are more detailed reproduction steps:

Step 1: Test with working version (2.0.76)

  # Create test directory and install working version
  mkdir -p /tmp/claude-test-working && cd /tmp/claude-test-working
  npm init -y
  npm install @anthropic-ai/[email protected]

  # Verify version
  ./node_modules/.bin/claude --version
  # Expected: 2.0.76 (Claude Code)

  # Run subagent test
  echo "Use the Task tool to spawn a Bash subagent in background to run 'ls -la'. Then use TaskOutput to get the result." \
    | ./node_modules/.bin/claude --output-format stream-json --verbose --print --dangerously-skip-permissions \
    > output.jsonl 2>&1

  # Extract TaskOutput result
  cat output.jsonl | jq -r 'select(.type=="user") | .message.content[]? | select(.type=="tool_result") | .content' | grep -A 100 "<output>"

  Expected output (CORRECT):
  <output>
  [Tool: Bash] {"command":"ls -la","description":"List all files with details"}

  --- RESULT ---
  The `ls -la` command was executed successfully...
  </output>

  Step 2: Test with broken version (2.1.1)

  # Create test directory and install broken version
  mkdir -p /tmp/claude-test-broken && cd /tmp/claude-test-broken
  npm init -y
  npm install @anthropic-ai/[email protected]

  # Verify version
  ./node_modules/.bin/claude --version
  # Expected: 2.1.1 (Claude Code)

  # Run same subagent test
  echo "Use the Task tool to spawn a Bash subagent in background to run 'ls -la'. Then use TaskOutput to get the result." \
    | ./node_modules/.bin/claude --output-format stream-json --verbose --print --dangerously-skip-permissions \
    > output.jsonl 2>&1

  # Extract TaskOutput result
  cat output.jsonl | jq -r 'select(.type=="user") | .message.content[]? | select(.type=="tool_result") | .content' | grep -A 100 "<output>"

  Expected output (BUG - raw JSONL):
  <output>
  {"parentUuid":null,"isSidechain":true,"userType":"external","cwd":"/private/tmp/claude-test-broken","sessionId":"...","version":"2.1.1",...}
  {"parentUuid":"...","isSidechain":true,...,"message":{"content":[{"type":"tool_use","name":"Bash",...}]},...}
  ...
  </output>

peterjrichens avatar Jan 14 '26 00:01 peterjrichens

Additional findings from debugging

We encountered this same issue (#18351, closed as dup) while running parallel background subagents.

Root cause observation

On version 2.1.17, the .output file for background agents is a symlink pointing to the agent's JSONL transcript:

$ ls -la /tmp/claude/-workspaces/tasks/
lrwxrwxrwx ... a3d761c.output -> /home/.../.claude/projects/.../subagents/agent-a3d761c.jsonl

When TaskOutput reads this file, it follows the symlink and returns the entire JSONL transcript instead of a summary.

Our experience (#18351)

We ran 4-5 parallel background subagents for research tasks. Upon completion, ~900KB of JSONL data flooded the parent context, triggering compaction.


✍️ Author: Claude Code (DevContainer) with @carrotRakko

Note: This comment was written and submitted by an AI agent (Claude Code), with human review and approval.

carrotRakko avatar Jan 23 '26 13:01 carrotRakko

This issue is still alive and well; I just had my session get compacted because it read a full task's transcript instead of only the final output.

asermax avatar Feb 18 '26 03:02 asermax