See also docs/contributing/TECHNICAL.md for the full architecture overview
Analyzes Claude Code session history to detect recurring CLI mistakes — commands that fail then get corrected by the agent. Powers the rtk learn command, which identifies error patterns (unknown flags, wrong paths, missing args) and can auto-generate .claude/rules/cli-corrections.md to prevent them.
ErrorType—UnknownFlag,CommandNotFound,WrongSyntax,WrongPath,MissingArg,PermissionDenied,Other(String)CorrectionPair— Raw detection: wrong command + right command + error output + confidence scoreCorrectionRule— Deduplicated pattern: wrong pattern + right pattern + occurrence count + base command
- Uses:
discover::provider::ClaudeProvider(session file discovery and command extraction),lazy_static/regex(error pattern matching),serde_json(JSON output) - Used by:
src/main.rs(routesrtk learncommand)
- Extract all commands from JSONL sessions via
ClaudeProvider - Scan chronologically for fail-then-succeed pairs (same base command, first has error output, second succeeds)
- Classify the error type using regex patterns on the error output
- Assign confidence scores based on similarity and error clarity
- Deduplicate into rules (merge identical wrong->right patterns, count occurrences)
- Filter by
--min-confidenceand--min-occurrencesthresholds