Skip to content

[FEATURE]: task tool results should carry child-session duration and token metrics #47822

Closed as not planned

Description

@moaines

Task tool returns the final text plus child sessionID/model in the tool-part metadata (task.ts:185-190), but no duration, token, or cost figures. The child session row already has everything at return time (sessions table: time_created/time_updated/cost/tokens_*, packages/core/src/session/sql.ts:43-48).

Proposed change

In task.ts (dev@57ef382843, foreground 341-345 + background inject 227-242): append durationMs + tokens (and cost if >0) to metadata and/or one recap line in the output. Requires an extra sessions.get(nextSession.id) (background.wait return info carries no tokens), so ~10 lines is the low end; single site, extend existing task.test.ts.

Use case

Multi-agent delegation observability: watchdogs, cost and budget tracking, per-subagent timing — without an extra DB query from the caller.

Environment

opencode v1.18.29, Linux.

Searched "task metrics", "subagent duration" — no open issue. Complements closed #6354 and #22959 (UI-level timing; this is tool-level).

Activity

  1. github-actions commented on Sep 7, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    Your request is scoped differently (exposing metrics in the Task tool result metadata/output rather than UI-level aggregation), so it may stand on its own — but worth reviewing those issues to see if your use case overlaps or could be addressed together.

  2. JLegends commented on Sep 17, 2026

    @JLegends

    Same gap, from the other side. I run subagent-heavy sessions and the sidebar only reports the root session's cost, so a fan-out with a few subagents can spend a large multiple of what is shown. In the reconciliation on #45417, subagents were 42% of the session's real cost.

    Metrics on the task-tool result would help the caller. It does not help the human watching the run live. I'd want both:

    • duration, tokens and cost on the tool-part metadata, as you propose
    • the same figures rolled up in the TUI, either into the root sidebar or a per-child view

    One implementation note for the TUI side: the plugin API can already reach this. api.client.session.children({ path: { sessionID } }) returns Session[] with cost and tokens per child, so a TUI plugin can walk the tree and sum today. What is missing is a first-class children/list accessor on api.state.session (packages/plugin/src/tui.ts) and any UI that consumes it. If the metadata change is out of scope, the plugin route is open and I'm building it now.

    Happy to test either direction. macOS, v1.18.31.

  3. opencodejr commented on Oct 28, 2026

    @opencodejr

    Thanks for the detailed proposal, @moaines!

    This report is about OpenCode v1 (v1.18.29, packages/opencode/src/tool/task.ts). v1 now only gets fixes for critical bugs such as data loss, security problems or crashes with no workaround, so this enhancement is unlikely to be made there.

    We'd encourage upgrading to v2 (@opencode/cli). In v2 the task tool has been replaced by the subagent tool (packages/core/src/tool/plugin/subagent.ts). It currently returns only sessionID and status in its metadata, so it doesn't include duration, token or cost figures either. If you'd like this in v2, please open a new feature request against the subagent tool, and maintainers can consider it there.

    Related issues:

    If you think this is critical, please reply here and explain why.

  4. opencodejr commented on Oct 29, 2026

    @opencodejr

    Closing this as not planned: it's a feature request for OpenCode v1 (v1.18.29), and v1 only gets fixes for critical bugs. Thanks again for the detailed proposal, @moaines.

    If you'd like this in v2, please open a new feature request against the subagent tool (packages/core/src/tool/plugin/subagent.ts). That tool replaced task, and its metadata currently includes only sessionID and status. You're also welcome to reply here if you think I've misjudged this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions