feat(tracking): add parent session ID for subagent aggregation - #4
Open
karl82 wants to merge 3 commits into
Open
feat(tracking): add parent session ID for subagent aggregation#4karl82 wants to merge 3 commits into
karl82 wants to merge 3 commits into
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds `parent_session_id` tracking so token savings from Claude Code subagents (spawned via the Agent tool) can be aggregated under their parent session. - DB: new `parent_session_id TEXT DEFAULT ''` column + index migration - tracking: `set_parent_session_id()` + `OnceLock` override; reads `CLAUDE_CODE_PARENT_SESSION_ID` → `RTK_PARENT_SESSION_ID` env vars - rewrite hook: injects `--parent-session=<id>` into rewritten RTK commands when running as a subagent (positions before subcommand so Clap consumes it before routing to git/cargo/etc.) - CLI: global `--parent-session` flag on both the top-level `Cli` (consumed by tracking) and `rtk gain` (for viewing aggregated stats) - gain: `--parent-session [<id>]` shows root-session view with parent + all child session savings aggregated per row - `get_by_root_session()` query groups by effective root session Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…tree - `get_summary_for_root_session(prefix)`: aggregates all commands where `session_id GLOB prefix*` OR `parent_session_id GLOB prefix*` - `show_root_session_detail()`: same KPI + by-command layout as `--session <id>`, with optional subagent session breakdown header - `rtk gain --parent-session` (bare) still lists root sessions - `rtk gain --parent-session <id>` now shows full detail view Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
parent_session_id TEXT DEFAULT ''column + index to the tracking DB (migration-safe)--parent-session=<id>into the rewritten command whenCLAUDE_CODE_PARENT_SESSION_IDorRTK_PARENT_SESSION_IDis set — positioned before the subcommand so Clap consumes it without leaking into the underlying command's args--parent-sessionCLI flag onCliwrites into aOnceLockoverride (highest priority), falling back to env varsget_by_root_session()query aggregates parent + all child sessions into one rowrtk gain --parent-session [<id>]shows the root-session view with per-tree savingsHow it works
Notes on
--parent-sessionflag isolation--parent-session=Xis injected before the subcommand (rtk --parent-session=X git status). Clap parses it at theClilevel viaglobal = true; it never appears in the args passed to git/cargo/etc.original_cmdand token counts are unaffected.Stacked on
PR #3 (
feat/gain-session) — per-session savings view.🤖 Generated with Claude Code