Use case
rtk session shows my last 10 Claude Code sessions with the RTK vs raw command ratio, so I can see if my hook is working.
Scope MVP (v1)
Single command, zero flags. Displays the 10 most recent sessions.
Technical approach: reuse provider.rs directly
ClaudeProvider already exposes:
discover_sessions(project_filter, since_days) -> Vec<PathBuf> — finds JSONL session files
extract_commands(path) -> Vec<ExtractedCommand> — parses JSONL, returns command + output_len
What session_cmd.rs does:
ClaudeProvider.discover_sessions(None, Some(30)) → all sessions last 30 days
- For each session:
extract_commands(path) → Vec<ExtractedCommand>
- Count:
total = cmds.len(), rtk_count = cmds.iter().filter(|c| c.command.starts_with("rtk ")).count()
- Calculate adoption %, format output_len
- Sort by mtime desc, take top 10
- Display table
Zero JSONL parsing duplication — reuses the trait as-is.
Target output
RTK Session Overview (last 10)
------------------------------------------------------------------
Session Date Cmds RTK Adoption Output
------------------------------------------------------------------
abc123de Mar 10 42 38 90% @@@@. 24K
fed987cb Mar 09 18 12 67% @@@.. 8K
------------------------------------------------------------------
Average adoption: 83%
Tip: Run `rtk discover` to find missed RTK opportunities
(ASCII progress bar with simple blocks for terminal compatibility)
Files to create/modify
| File |
Action |
src/session_cmd.rs |
Create (~250 lines, shorter thanks to provider reuse) |
src/main.rs |
Add mod session_cmd, Commands::Session, routing |
scripts/test-all.sh |
Add smoke test assertion |
Reuse existing
discover::provider::{ClaudeProvider, SessionProvider, ExtractedCommand}
tracking::estimate_tokens()
- Table pattern from
gain.rs
dirs::home_dir()
Error handling
~/.claude/projects/ absent → "No Claude Code sessions found."
- Corrupted JSONL → handled by provider (skip line)
- Session with no Bash commands → skip
- Implicit limit: 10 sessions max (perf guard)
Tests
- Inline tests with JSONL fixtures in tempdir
- Test RTK vs raw count on mock
ExtractedCommand
- Test progress bar rendering (0%, 50%, 100%)
- Test empty session → skip
Verification
cargo fmt --all && cargo clippy --all-targets && cargo test
./target/debug/rtk session # on real setup
hyperfine 'rtk session' # target <500ms (I/O bound, JSONL parsing)
Out of scope (v2, defer)
--project filter by current project
--days N temporal filter
--format json
--verbose per-session command detail
Acceptance criteria
Use case
rtk sessionshows my last 10 Claude Code sessions with the RTK vs raw command ratio, so I can see if my hook is working.Scope MVP (v1)
Single command, zero flags. Displays the 10 most recent sessions.
Technical approach: reuse
provider.rsdirectlyClaudeProvideralready exposes:discover_sessions(project_filter, since_days) -> Vec<PathBuf>— finds JSONL session filesextract_commands(path) -> Vec<ExtractedCommand>— parses JSONL, returns command + output_lenWhat
session_cmd.rsdoes:ClaudeProvider.discover_sessions(None, Some(30))→ all sessions last 30 daysextract_commands(path)→Vec<ExtractedCommand>total = cmds.len(),rtk_count = cmds.iter().filter(|c| c.command.starts_with("rtk ")).count()Zero JSONL parsing duplication — reuses the trait as-is.
Target output
(ASCII progress bar with simple blocks for terminal compatibility)
Files to create/modify
src/session_cmd.rssrc/main.rsmod session_cmd,Commands::Session, routingscripts/test-all.shReuse existing
discover::provider::{ClaudeProvider, SessionProvider, ExtractedCommand}tracking::estimate_tokens()gain.rsdirs::home_dir()Error handling
~/.claude/projects/absent → "No Claude Code sessions found."Tests
ExtractedCommandVerification
Out of scope (v2, defer)
--projectfilter by current project--days Ntemporal filter--format json--verboseper-session command detailAcceptance criteria
rtk sessiondisplays last 10 sessions with adoption %provider.rswithout JSONL parsing duplicationcargo testpasses, clippy clean