Skip to main content

Overview

The rtk discover command scans your Claude Code session history (stored as JSONL files) to find commands where RTK would have saved tokens but wasn’t used. It helps you:
  • Measure what you’re missing — see exactly how many tokens you could save
  • Identify habits — find which commands you keep running without rtk
  • Spot new opportunities — see unhandled commands that could become rtk features
rtk discover is read-only and never modifies your Claude Code session files. It only analyzes JSONL logs to identify potential savings.

Quick Start

Command Options

flag
Scan all Claude Code projects instead of just the current working directory
integer
default:"30"
Number of days to look back in session history (default: 30 days)
string
Filter sessions by project name (substring match on directory name)
string
default:"text"
Output format: text (human-readable) or json (machine-readable)
flag
Show verbose output including session file paths and parse errors

How It Works

Session Discovery

  1. Project Directory Resolution
    • Default: Current working directory → ~/.claude/projects/-path-to-current-dir/
    • --all: All directories in ~/.claude/projects/
    • -p <name>: Substring match on project directory names
  2. JSONL File Scanning
    • Recursively walks project directories (includes subagents/ subdirectories)
    • Filters by modification time (last N days via --since)
    • Parses JSONL session logs for Bash tool use events
  3. Command Classification
    • Extracts Bash commands from tool_use blocks
    • Matches against RTK’s internal command registry
    • Estimates token savings based on tool_result output lengths

Classification Categories

Commands RTK already handles with dedicated filters:
  • Git: git status, git diff, git log, etc.
  • Cargo: cargo test, cargo build, cargo clippy
  • JavaScript: tsc, eslint, prettier, vitest, playwright
  • Files: cat, grep, rg, ls, find
  • Infra: docker ps, kubectl get
These represent missed savings — you ran the raw command instead of rtk <cmd>.

Output Examples

Text Format (Default)

Sections explained:
  1. Header: Sessions scanned, total Bash commands found, RTK usage rate
  2. Missed Savings: Commands RTK handles but you didn’t use (sorted by estimated savings)
  3. Top Unhandled: Commands RTK doesn’t support yet (sorted by frequency)

Status Column

JSON Format

Token Estimation

How Savings Are Calculated

Category averages (used when real output length unavailable):

Savings Percentages by Command

Use Cases

Weekly Habit Check

Project-Specific Analysis

Feature Request Prioritization

Team Adoption Metrics

Advanced Usage

Filter by Project Substring

Verbose Output

Combine with rtk gain

Troubleshooting

No sessions found

Low command counts

Parse errors

Zero savings shown

Privacy & Security

rtk discover reads Claude Code session files which may contain:
  • Command history (Bash tool invocations)
  • Command output (tool_result content)
  • Project paths (encoded in directory names)
Data handling:
  • All analysis happens locally (no network requests)
  • No session data is stored or logged
  • Output contains only aggregated statistics (not raw session content)

Command Registry

rtk discover uses the same command classification engine as the RTK hook. The registry includes:
  • git status, log, diff, show, add, commit, push, pull, branch, fetch, stash, worktree
  • Savings: 59-80% depending on subcommand

Best Practices

  1. Run Weekly: rtk discover --since 7 to catch habit changes
  2. Install Hook: If you see high missed savings, install the RTK hook with rtk init -g
  3. Track Adoption: Use --format json to track adoption rate over time
  4. Feature Requests: Export unsupported commands and open GitHub issues for top candidates
  5. Project-Specific: Use -p to analyze individual projects before rolling out RTK team-wide

See Also

rtk gain Command

View actual token savings over time with temporal breakdowns

RTK Hook

Automatic command rewriting for 100% RTK adoption