[PR #4611] feat(task): expose subagent token consumption to primary agent #11038

Closed
opened 2026-02-16 18:15:49 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/4611

State: closed
Merged: No


Primary agent now receives token consumption data from subagents via task_metadata, enabling smarter delegation decisions based on remaining context capacity.

The task_metadata now includes:

  • Token breakdown (input, output, reasoning, cache read/write)
  • Context limit (model's max context window)
  • Context percentage (how much capacity is used)
  • Cumulative cost

Example

<task_metadata>
session_id: ses_557a4d402ffe73PZcaOCWS06V8
tokens_input: 11
tokens_output: 285
tokens_reasoning: 0
tokens_cache_read: 17234
tokens_cache_write: 2622
cost: 0
context_limit: 200000
context_percentage: 10
</task_metadata>

Why

Previously, task_metadata only returned session_id. The primary had no visibility into how much context a subagent had consumed, making it impossible to know when to spawn a fresh session vs continue with an existing one.

Primary can now check context_percentage and decide to continue with the same subagent or start fresh when context is running low.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/4611 **State:** closed **Merged:** No --- Primary agent now receives token consumption data from subagents via `task_metadata`, enabling smarter delegation decisions based on remaining context capacity. The `task_metadata` now includes: - Token breakdown (input, output, reasoning, cache read/write) - Context limit (model's max context window) - Context percentage (how much capacity is used) - Cumulative cost ### Example ```xml <task_metadata> session_id: ses_557a4d402ffe73PZcaOCWS06V8 tokens_input: 11 tokens_output: 285 tokens_reasoning: 0 tokens_cache_read: 17234 tokens_cache_write: 2622 cost: 0 context_limit: 200000 context_percentage: 10 </task_metadata> ``` ### Why Previously, `task_metadata` only returned `session_id`. The primary had no visibility into how much context a subagent had consumed, making it impossible to know when to spawn a fresh session vs continue with an existing one. Primary can now check `context_percentage` and decide to continue with the same subagent or start fresh when context is running low.
yindo added the pull-request label 2026-02-16 18:15:49 -05:00
yindo closed this issue 2026-02-16 18:15:49 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#11038