feat: Add max_return_size parameter to Task tool and task-notification truncation

Resolved 💬 3 comments Opened Feb 21, 2026 by Caylub Closed Feb 25, 2026

Problem

When a background agent (launched via the Task tool with run_in_background: true) completes, its full result is injected into the orchestrator's conversation as a <task-notification> message. There is no mechanism to:

  • Limit the size of this notification payload
  • Redirect it to a file instead of inline context
  • Auto-summarize it before injection
  • Set a max_return_size on the Task tool

This is the root cause of context explosion in multi-agent orchestration workflows. All other mitigations are workarounds for this missing feature.

Real-World Impact

In a session orchestrating 36+ background agents (each returning 2000-4000 word knowledge extractions), the task notifications consumed the majority of the orchestrator's context window, triggering unwanted compaction and causing loss of critical orchestration state (wave tracking, agent assignments, completion counts).

Current workaround requires copy-pasting 6 defensive rules into every multi-agent prompt:

1. Never call TaskOutput — check file existence instead
2. Agent returns <= 15 words — just "DONE: /path/to/output.md"
3. Don't acknowledge task notifications — stay silent
4. Don't read agent output files — let a synthesis agent read them
5. Check completion via file existence — ls *.done | wc -l
6. Monitor agents via heartbeat staleness — not manual polling

This works but requires strict prompt discipline. Every orchestration prompt must include these rules, and a single agent ignoring them can blow the context budget. The problem should be solved at the platform level.

Proposed Solutions (in order of preference)

1. max_return_size parameter on the Task tool

Add an optional parameter that truncates the agent's return value to N tokens before injecting it as a <task-notification>:

{
  "name": "Task",
  "parameters": {
    "prompt": "...",
    "subagent_type": "general-purpose",
    "run_in_background": true,
    "max_return_size": 50
  }
}

If the agent's return exceeds max_return_size tokens, truncate and append ... [truncated, full result in TaskOutput].

2. task_notification_mode setting

A per-invocation or global setting controlling how task results are delivered:

| Mode | Behavior |
|------|----------|
| "full" | Current behavior — inject full result (default) |
| "summary" | Auto-summarize the result before injection |
| "file" | Write result to a temp file, inject only the file path |
| "silent" | No notification at all (check via TaskOutput) |

3. task_notification_max_tokens global setting

A setting in settings.json that caps all task notification payloads globally:

{
  "task_notification_max_tokens": 100
}

4. Allow PostToolUse hooks to modify/suppress task notification content

Currently PostToolUse hooks fire at task launch time, not completion time. If hooks could intercept task completion notifications with gate behavior, users could implement custom truncation logic.

Reproduction Steps

  1. Launch 6+ background agents that each return >1000 tokens of content
  2. Wait for all agents to complete
  3. Observe the orchestrator's context filling with full task notification payloads
  4. Note that no parameter exists to control this behavior

Related Issues

  • #22702 — Allow suppressing background task notifications via Notification hook (complementary — suppression vs. truncation)
  • #22703 — Batch background task notifications when Claude is idle
  • #20920 — False user confirmation from task notifications and compaction events
  • #21343 — Task notifications arrive after TaskOutput already returned results

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗