Problem
Subagents run in their own AgentSession. Their LLM spend never reaches the parent session's cost accounting. Every surface that reads parent session cost under-reports total spend. This includes pi core's getUsageCostBreakdown, /session, and statusline extensions such as pi-starship and pi-powerline-footer. In a test on pi 0.83.0, two one-turn subagent runs spent $0.066 and none of it reached the parent session's cost accounting.
Proposal
Pi provides a canonical channel for tool spend: ToolResultMessage.usage. Pi core aggregates that field into its "Tools/summaries" cost bucket, and statusline extensions sum the same field. The extension already accumulates per-agent token usage from message_end events. It does not track cost and does not attach anything to the tool results it returns.
I propose three changes:
- Extend the lifetime usage accumulator with
cacheRead and cost.
- Attach the not-yet-reported usage slice to tool results at terminal points: foreground
Agent return, resume return, and terminal get_subagent_result.
- Advance a per-record watermark on each report so resumes and repeated result fetches never report the same spend twice.
I implemented and tested this in #202.
Problem
Subagents run in their own
AgentSession. Their LLM spend never reaches the parent session's cost accounting. Every surface that reads parent session cost under-reports total spend. This includes pi core'sgetUsageCostBreakdown,/session, and statusline extensions such as pi-starship and pi-powerline-footer. In a test on pi 0.83.0, two one-turn subagent runs spent $0.066 and none of it reached the parent session's cost accounting.Proposal
Pi provides a canonical channel for tool spend:
ToolResultMessage.usage. Pi core aggregates that field into its "Tools/summaries" cost bucket, and statusline extensions sum the same field. The extension already accumulates per-agent token usage frommessage_endevents. It does not track cost and does not attach anything to the tool results it returns.I propose three changes:
cacheReadandcost.Agentreturn,resumereturn, and terminalget_subagent_result.I implemented and tested this in #202.