Skip to content

feat(usage): include Claude sub-agent usage in statistics#2059

Open
chen893 wants to merge 3 commits intofarion1231:mainfrom
chen893:feat/subagent-usage-tracking
Open

feat(usage): include Claude sub-agent usage in statistics#2059
chen893 wants to merge 3 commits intofarion1231:mainfrom
chen893:feat/subagent-usage-tracking

Conversation

@chen893
Copy link
Copy Markdown

@chen893 chen893 commented Apr 13, 2026

Summary

  • parse Claude sub-agent transcript JSONL files under session subagents directories, including nested workflow folders
  • store sub-agent usage rows with their original data source for diagnostics while merging user-facing display into session logs
  • keep provider stats compatible with rollup queries

Fixes #2056

Validation

  • cargo fmt
  • git diff --check
  • cargo check -q
  • pnpm typecheck

chen893 and others added 3 commits April 13, 2026 22:41
The session usage parser previously only scanned main session JSONL
files (~/.claude/projects/*/*.jsonl), missing all API calls made by
sub-agents (tool agents). Sub-agent transcripts are stored under
<session>/subagents/agent-*.jsonl with the same format as main
session files.

Changes:
- Add collect_subagent_files() to scan <project>/<sessionId>/subagents/
  including nested workflow subdirectories
- Parameterize sync_single_file() with data_source and request_id_prefix
  to reuse parsing logic for both main and sub-agent records
- Tag sub-agent records with data_source="session_subagent" and
  request_id prefix "subagent:" to avoid ID collisions
- Update provider_name_coalesce() to display "Claude (Sub-Agent)" for
  sub-agent entries in usage stats queries
- Add session_subagent icon (Bot) and i18n translations in en/zh/ja

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@yovinchen
Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tool agent中的请求次数也加入总统计中

2 participants