Skip to content

feat: add rtk session command for adoption overview#547

Merged
aeppling merged 5 commits intortk-ai:developfrom
ousamabenyounes:feat/rtk-session
Mar 13, 2026
Merged

feat: add rtk session command for adoption overview#547
aeppling merged 5 commits intortk-ai:developfrom
ousamabenyounes:feat/rtk-session

Conversation

@ousamabenyounes
Copy link
Copy Markdown
Contributor

Summary

  • Adds rtk session command that displays the last 10 Claude Code sessions with RTK adoption metrics
  • Reuses ClaudeProvider from discover module — zero JSONL parsing duplication
  • Also fixes pre-existing build error: missing truncate import in cargo_cmd.rs

Output example

RTK Session Overview (last 10)
----------------------------------------------------------------------
Session      Date          Cmds   RTK  Adoption           Output
----------------------------------------------------------------------
703dbcb4     Today          190     0        0% .....     101.0K
e5701247     Today          461    14        3% @....     251.2K
----------------------------------------------------------------------
Average adoption: 2%
Tip: Run `rtk discover` to find missed RTK opportunities

Test plan

  • 7 unit tests (progress bar rendering, adoption % calculation, edge cases)
  • Manual test: cargo run -- session on real Claude Code sessions
  • cargo fmt --all && cargo clippy --all-targets clean (no new warnings)
  • Smoke test in scripts/test-all.sh

Closes #487

🤖 Generated with Claude Code

@aeppling
Copy link
Copy Markdown
Contributor

Hello,

I'm checking with maintainers if we want to implement this, but if we do you will need to document this in rtk documentation.

@aeppling aeppling self-assigned this Mar 13, 2026
@aeppling
Copy link
Copy Markdown
Contributor

aeppling commented Mar 13, 2026

We want to implement this commands in RTK, however there is some point to be addressed first:

Adoption metric always look very low

  • When hooks are installed, Claude sends git status and the hook transparently rewrites it to rtk git status. The
    JSONL logs the original command (git status), not the rewritten one. So hook-based usage shows as 0% adoption.

  • When Claude explicitly types rtk commands, it counts, but that's rare.

DOCS

Do not forget document this command !

Thanks for contributing !

@aeppling
Copy link
Copy Markdown
Contributor

aeppling commented Mar 13, 2026

Closed the git -C related PR, just add correct documentation and fix and we will merge this PR for both the "rtk session" command and "git -C " fix

@ousamabenyounes
Copy link
Copy Markdown
Contributor Author

Thanks @aeppling! All 3 points addressed:

1. Adoption metric fixed
The hook rewrites git statusrtk git status but JSONL logs the original command. count_rtk_commands now uses classify_command() from the rewrite registry to also detect commands the hook would rewrite. Result: adoption went from ~2% to ~68% on real sessions.

2. Documentation
Added rtk session to README.md.

3. git -C fix
Cherry-picked into this PR (PR #556 can stay closed).

Example output with the fix:

RTK Session Overview (last 10)
----------------------------------------------------------------------
Session      Date          Cmds   RTK  Adoption           Output
----------------------------------------------------------------------
e5701247     Today          508   352       69% @@@..     279.6K
facf2ba6     Today          105    67       64% @@@..      96.7K
----------------------------------------------------------------------
Average adoption: 68%

@aeppling
Copy link
Copy Markdown
Contributor

Hey !

I retried with your latest fix, indeed it work better ! But got some trouble with chained commands that still display 0% adoption (example , claude running "cd ./your/app/path && rtk ls"

The discover module already handles chained commands. In src/discover/mod.rs:86:

let parts = split_command_chain(&ext_cmd.command);

Could you implement this so our adoption metric always make sense and does not display 0% on chained commands ?

If you could also add a testing for those chained command which is kind of edge case for your adoption metric.

ousamabenyounes and others added 5 commits March 13, 2026 14:09
Shows last 10 Claude Code sessions with RTK vs raw command ratio,
adoption percentage, and output token count. Reuses ClaudeProvider
from discover module — zero JSONL parsing duplication.

Also fixes missing `truncate` import in cargo_cmd.rs (pre-existing
build error on develop).

Closes rtk-ai#487

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Ousama Ben Younes <benyounes.ousama@gmail.com>
Replace trivial progress bar tests with meaningful tests:
- Parse JSONL with mixed rtk/raw commands, verify counts
- Verify non-Bash tools (Read/Grep) are ignored
- Verify empty sessions produce no commands
- Test count_rtk_commands with all-rtk, no-rtk, mixed, empty

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Ousama Ben Younes <benyounes.ousama@gmail.com>
The regex pattern for git commands now accepts -C and -c flags
before the subcommand, using a non-capturing group to preserve
subcommand extraction.

Closes rtk-ai#555

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Ousama Ben Younes <benyounes.ousama@gmail.com>
The hook rewrites "git status" → "rtk git status" but JSONL logs the
original command. count_rtk_commands now uses classify_command() to
also count commands the hook would rewrite, giving realistic adoption
percentages (68% vs previous 2%).

Also adds rtk session to README.md documentation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Ousama Ben Younes <benyounes.ousama@gmail.com>
Commands like "cd ./path && rtk ls" are now split via
split_command_chain() before classification, matching the
discover module's behavior. Each part is counted independently.

4 tests added: chain with &&, semicolons, all-supported,
and JSONL integration with chained command.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Ousama Ben Younes <benyounes.ousama@gmail.com>
@ousamabenyounes
Copy link
Copy Markdown
Contributor Author

Thanks @aeppling! Chained commands are already handled in the latest push.

count_rtk_commands uses split_command_chain() from the discover module to break chains before classification:

let parts = split_command_chain(&c.command);
for part in &parts {
    if part.starts_with("rtk ")
        || matches!(classify_command(part), Classification::Supported { .. })
    { ... }
}

So cd ./your/app/path && rtk ls splits into 2 commands → cd (unsupported) + rtk ls (counted) = 50% adoption for that line.

Tests covering this:

  • test_count_chained_commands_splitcd ./path && rtk ls → 2 total, 1 RTK
  • test_count_chained_all_supportedgit status && git log -5 → 2 total, 2 RTK
  • test_count_chained_with_semicolonecho a ; echo b ; git status → 3 total, 1 RTK
  • test_parse_jsonl_chained_command — full JSONL parsing integration test with chained command

@aeppling
Copy link
Copy Markdown
Contributor

Work well ! Thanks for contributing

Merged will be available in next release

@aeppling aeppling merged commit be67d66 into rtk-ai:develop Mar 13, 2026
2 of 3 checks passed
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.

2 participants