[BUG] TaskOutput deprecation note causes agents to Read full sub-agent conversation history, triggering autocompact thrashing
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 a background local_agent task completes, the TaskOutput tool's deprecation message instructs the agent to Read the task's .output file directly:
DEPRECATED: Prefer using the Read tool on the task's output file path instead.
Background tasks return their output file path in the tool result, and you receive
a <task-notification> with the same path when the task completes — Read that file directly.
This guidance does not distinguish between task types. For local_bash tasks, the .output file contains stdout/stderr — reading it is appropriate.
For local_agent tasks, however, the .output file contains the full raw conversation history JSON of the sub-agent, which can be 80K+ characters.
The Agent tool already returns a summarized result directly when the task completes. But following the deprecation note, the agent reads the .output file anyway — injecting the entire sub-agent conversation dump into the main agent's context window. When multiple sub-agents run in the same session, this causes rapid context saturation and triggers autocompact thrashing.
What Should Happen?
The deprecation guidance should distinguish between task types:
- local_bash tasks: Reading the .output file is appropriate — it contains command stdout/stderr.
- local_agent tasks: The Agent tool result already contains the sub-agent's summarized output. The agent should not Read the .output file — it
contains the full conversation history JSON and will inflate the context unnecessarily.
Suggested fix to the TaskOutput prompt:
DEPRECATED: Prefer using the Read tool on the task's output file path instead.
- For bash tasks: Read the output file path to get stdout/stderr.
- For agent tasks: use the Agent tool result directly. Do NOT Read the .output file —
it contains the full sub-agent conversation history and will overflow your context window.
Error Messages/Logs
SDK AssistantMessage carries error=invalid_request | text_len=257
SDK API error (fatal): error=invalid_request |
raw={'content': [TextBlock(text='Autocompact is thrashing: the context refilled to the limit
within 3 turns of the previous compact, 3 times in a row. A file being read or a tool output
is likely too large for the context window. Try reading in smaller chunks, or use /clear to
start fresh.')]}
The oversized Read that triggered the issue:
tool_call Read | input: {'file_path': '/tmp/claude-1000/.../tasks/aa8bd3ced112e5ae5.output'}
tool_result Read | ok | output: {"parentUuid":null,"isSidechain":true,"promptId":"747dfb10...",
"type":"user","message":{"role":"user","content":"In the repo at ... <- 87,286 chars
Comparison — Agent tool result vs .output file:
Agent tool return value : 4,087 chars (summarized result, appropriate)
.output file via Read : 87,286 chars (full conversation history JSON, 21x larger)
3 compacts each saving ~167K tokens, all triggered within the same turn:
SDK compact triggered: count=1 pre_tokens=167199 tokens_saved=167199 text=SDK auto compact
SDK compact triggered: count=2 pre_tokens=167883 tokens_saved=167883 text=SDK auto compact
SDK compact triggered: count=3 pre_tokens=167202 tokens_saved=167202 text=SDK auto compact
Steps to Reproduce
- Use Claude Code (v2.1.92) with a long-running agent session.
- Launch a sub-agent using the Agent tool with run_in_background: true.
- When task_notification fires, observe the main agent immediately calling Read on the path /tmp/claude-1000/.../tasks/<task_id>.output.
- The file read returns the full sub-agent conversation history JSON (~87K chars per sub-agent).
- With 3+ sub-agents in one session, context fills to the 800K token compact threshold.
- After 3 consecutive compacts where context refills within a few turns each time, the SDK raises invalid_request: Autocompact is thrashing.
Claude Model
None
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.92
Platform
Anthropic API
Operating System
Ubuntu/Debian Linux
Terminal/Shell
Terminal.app (macOS)
Additional Information
_No response_
This issue has 10 comments on GitHub. Read the full discussion on GitHub ↗