Persist subagent token usage to session JSONL files
Resolved 💬 3 comments Opened Feb 5, 2026 by brandon-pltsci Closed Mar 5, 2026
Description
When using the Task tool to spawn subagents, the token usage from those subagent API calls is tracked in-memory and displayed by the /cost command, but it's not persisted to the session JSONL files.
Current behavior
- Main session messages include full
usagedata inassistantmessages - Subagent (Task tool) results only store the text response, not token usage
/costcommand shows accurate totals (main + subagents) from in-memory state- Session files only contain ~50-70% of actual usage when subagents are used
Requested behavior
Include subagent usage in the tool_result or a separate message type when a Task completes:
{
"type": "tool_result",
"tool_use_id": "toolu_xxx",
"content": "Agent completed...",
"subagent_usage": {
"model": "claude-haiku-4-5-20251001",
"input_tokens": 97300,
"output_tokens": 3800,
"cache_read_input_tokens": 0,
"cache_creation_input_tokens": 27900
}
}
Use case
- Teams using Claude Code with AWS Bedrock need to track and report usage across multiple users
- Session files are the only persistent record of usage, but they're incomplete
- Without this data, cost tracking/auditing requires manual
/costlogging or AWS CloudWatch access
Workaround
Currently using /cost output manually or AWS CloudWatch metrics, but neither integrates well with local session history.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗