feat(analytics): add Codex session stats to rtk gain and rtk session#1893
Open
yaco16 wants to merge 2 commits into
Open
feat(analytics): add Codex session stats to rtk gain and rtk session#1893yaco16 wants to merge 2 commits into
yaco16 wants to merge 2 commits into
Conversation
Parse ~/.codex/sessions/**/*.jsonl to count exec_command tool calls and accumulate token usage (input/output/cached) per session. - src/analytics/codex.rs: new module — discover_sessions() walks the Codex sessions dir; parse_session() extracts exec_command call counts and the final cumulative total_token_usage from token_count events. - src/analytics/session_cmd.rs: rtk session now appends a Codex table (last 10 sessions, columns: Session / Date / Calls / Tokens). - src/analytics/gain.rs: rtk gain default summary now shows a compact Codex Activity block (sessions, CLI calls, token breakdown). - src/analytics/mod.rs: expose pub mod codex. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Extract exec_command.arguments.cmd from Codex JSONL and apply the same classify_command + split_command_chain logic used for Claude Code sessions. - CodexSessionSummary: replace tool_calls with total_cmds/rtk_cmds + adoption_pct() - parse_session: parse inner arguments JSON, classify each command part - rtk session: Codex table now mirrors Claude Code (Cmds / RTK / Adoption% / bar / Tokens) - rtk gain: Codex Activity block shows RTK adoption ratio alongside token breakdown - 4 new tests: explicit rtk prefix, hook-rewritten commands, chained commands, empty args 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
Adds first-class Codex analytics to `rtk gain` and `rtk session`, using the same session-parsing architecture as the existing Claude Code provider.
New: `src/analytics/codex.rs`
Parses `~/.codex/sessions/**/*.jsonl` to extract per-session statistics:
Updated: `src/analytics/gain.rs`
Default summary (`rtk gain`) now appends a Codex Activity (last 30d) block:
```
Codex Activity (last 30d)
─────────────────────────────────────────────
Sessions 27
RTK adoption 329/1 342 cmds (25%)
Total tokens 104M (in: 98M, out: 5M, cached: 0)
```
Updated: `src/analytics/session_cmd.rs`
`rtk session` appends a Codex RTK Adoption table (last 10 sessions):
```
Codex RTK Adoption (last 10)
Session Date Cmds RTK Adoption Tokens
019e2704 Today 48 12 25% █░░░░ 104.2M
Average adoption: 24%
```
Codex JSONL format
Sessions live at `~/.codex/sessions/YYYY/MM/DD/.jsonl`:
Test plan
🤖 Generated with Claude Code