You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
rtk discover scans Claude Code JSONL session logs to identify commands that could benefit from RTK filtering. However, these logs record commands before the PreToolUse hook rewrites them - so discover never sees the rtk prefix and reports them all as missed.
This makes discover metrics unreliable for anyone using the hook-based setup from rtk init -g.
Repro
Install RTK with rtk init -g (hook-based setup)
Run a Claude Code session with several Bash commands
Verify commands are processed: rtk gain shows them correctly
Run rtk discover --since 1 - the same commands show up as missed
420 commands went through RTK according to gain, but discover only finds 7 because the JSONL stores the pre-rewrite command.
Root cause
Claude Code logs the original tool_input.command to the session JSONL, not the rewritten version from the hook output. discover pattern-matches against these raw entries and never finds an rtk prefix.
Suggestion
Cross-reference discover results with RTK's own execution history, or flag in the output that hook-rewritten commands can't be detected from JSONL alone.
I think the important distinction here is covered by a hook vs missed opportunity. A one-line fix that treats every Classification::Supported raw command as already using RTK would match the session adoption view, but it would also make rtk discover stop finding real misses from sessions where the hook was not installed, excluded, disabled, or bypassed.
Repo-grounded read of current develop:
src/discover/mod.rs only increments already_rtk in the Classification::Ignored branch when the raw part starts with rtk . Any Classification::Supported command is aggregated into the MISSED SAVINGS table.
src/analytics/session_cmd.rs already encodes the opposite semantics for an adoption lens: part.starts_with("rtk ") || matches!(classify_command(part), Classification::Supported { .. }). Its tests explicitly cover the hook-rewrite case where Claude JSONL logs git status even though the hook ran rtk git status.
src/core/tracking.rs has the execution-side evidence: commands.timestamp, original_cmd, rtk_cmd, and project_path. Existing public recent-history helpers only expose timestamp, rtk_cmd, savings fields, so discover probably needs a narrow read-only lookup rather than reusing get_recent_filtered as-is.
src/discover/provider.rs currently keeps command, session_id, output, error state, and sequence_index, but drops the Bash tool_use id and any JSONL timestamp if present. Keeping those would give discover better join keys and diagnostics.
src/hooks/hook_audit_cmd.rs can also prove rewrite activity when RTK_HOOK_AUDIT=1 is enabled, but the tracking DB is the better default because it is always part of RTK execution accounting.
A durable fix could split the report into explicit buckets instead of forcing a binary already_rtk/missed result:
Already using RTK (explicit prefix)
Covered by RTK tracking (hook/proxy execution observed)
Potential missed savings
Ambiguous hook-rewrite candidates
RTK_DISABLED bypass
Concrete implementation shape:
Extend ExtractedCommand with optional provenance: tool_use_id, observed_at from the JSONL line when present, session_path or derived project slug, and perhaps the raw session file mtime as a fallback. Keep sequence_index; it is useful when timestamps are missing.
Add a tracker query shaped for this use case, for example Tracker::find_execution_match(original_cmd, project_path, observed_at, window). It should match on original_cmd = raw part or rtk_cmd = expected equivalent, scoped by project path and a small time window when possible. Exact command-only matching will over-count common commands like git status and grep.
In discover, classify supported commands roughly like this:
if raw part starts with "rtk ": explicit already_rtk
else if RTK_DISABLED prefix: bypass bucket
else if tracker match exists: covered_by_tracking
else if Claude hook appears installed/current: ambiguous_hook_rewrite
else: missed savings
hook_check::status() can probably supply the Claude hook status; AgentIntegrationStatus currently covers Cursor/Hermes/Copilot notes but not the Claude rewrite hook state that this issue hinges on.
Do not make session_cmd::count_rtk_commands the discover rule directly. I would factor a shared lower-level helper that returns a semantic enum like ExplicitRtk, SupportedRaw, Ignored, Unsupported, DisabledByEnv, then let session_cmd and discover interpret SupportedRaw differently. That prevents the two views from drifting while preserving their different jobs.
Tests I would add:
Claude JSONL raw git status plus tracking row { original_cmd: "git status", rtk_cmd: "rtk git status", project_path: same project } => covered by tracking, not missed.
Claude JSONL raw git status with no tracking row and no hook installed => potential missed savings.
Claude JSONL raw git status with hook installed but no tracking row => ambiguous hook-rewrite candidate, not confident missed savings.
Explicit rtk git status in JSONL => explicit already using RTK.
RTK_DISABLED=1 git status => bypass bucket remains separate.
Chained commands like cd app && git status && echo done preserve per-part accounting.
Subagent JSONL stays intentional: either include it consistently in both discover and tracking comparison, or mark it separately. discover currently walks subagents, while session_cmd filters them out.
The same lesson shows up in ax: transcript logs are pre-execution intent, while hook/tracking telemetry is execution outcome. Adoption metrics should not infer execution outcome from the transcript alone when a rewrite hook sits between the two.
Closing as a duplicate of #1441, which tracks the same problem with the more complete discussion. Please follow up there; if your case differs in a way that issue does not cover, comment here and it can be reopened.
Activity
pszymkowiak commentedon Apr 4, 2026
🔍 Automated Triage
bugmediumSummary
rtk discover miscounts RTK adoption because JSONL logs store pre-hook commands; fix requires cross-referencing RTK's own execution history
Triaged automatically by wshm · This is an automated analysis, not a human review.
fix(discover): cross-reference tracking DB to exclude hook-handled co…
Necmttn commentedon Jun 21, 2026
I think the important distinction here is
covered by a hookvsmissed opportunity. A one-line fix that treats everyClassification::Supportedraw command as already using RTK would match the session adoption view, but it would also makertk discoverstop finding real misses from sessions where the hook was not installed, excluded, disabled, or bypassed.Repo-grounded read of current
develop:src/discover/mod.rsonly incrementsalready_rtkin theClassification::Ignoredbranch when the raw part starts withrtk. AnyClassification::Supportedcommand is aggregated into theMISSED SAVINGStable.src/analytics/session_cmd.rsalready encodes the opposite semantics for an adoption lens:part.starts_with("rtk ") || matches!(classify_command(part), Classification::Supported { .. }). Its tests explicitly cover the hook-rewrite case where Claude JSONL logsgit statuseven though the hook ranrtk git status.src/core/tracking.rshas the execution-side evidence:commands.timestamp,original_cmd,rtk_cmd, andproject_path. Existing public recent-history helpers only exposetimestamp,rtk_cmd, savings fields, sodiscoverprobably needs a narrow read-only lookup rather than reusingget_recent_filteredas-is.src/discover/provider.rscurrently keepscommand,session_id, output, error state, andsequence_index, but drops the Bashtool_useid and any JSONL timestamp if present. Keeping those would givediscoverbetter join keys and diagnostics.src/hooks/hook_audit_cmd.rscan also prove rewrite activity whenRTK_HOOK_AUDIT=1is enabled, but the tracking DB is the better default because it is always part of RTK execution accounting.A durable fix could split the report into explicit buckets instead of forcing a binary
already_rtk/missedresult:Concrete implementation shape:
Extend
ExtractedCommandwith optional provenance:tool_use_id,observed_atfrom the JSONL line when present,session_pathor derived project slug, and perhaps the raw session file mtime as a fallback. Keepsequence_index; it is useful when timestamps are missing.Add a tracker query shaped for this use case, for example
Tracker::find_execution_match(original_cmd, project_path, observed_at, window). It should match onoriginal_cmd = raw partorrtk_cmd = expected equivalent, scoped by project path and a small time window when possible. Exact command-only matching will over-count common commands likegit statusandgrep.In
discover, classify supported commands roughly like this:hook_check::status()can probably supply the Claude hook status;AgentIntegrationStatuscurrently covers Cursor/Hermes/Copilot notes but not the Claude rewrite hook state that this issue hinges on.Do not make
session_cmd::count_rtk_commandsthe discover rule directly. I would factor a shared lower-level helper that returns a semantic enum likeExplicitRtk,SupportedRaw,Ignored,Unsupported,DisabledByEnv, then letsession_cmdanddiscoverinterpretSupportedRawdifferently. That prevents the two views from drifting while preserving their different jobs.Tests I would add:
git statusplus tracking row{ original_cmd: "git status", rtk_cmd: "rtk git status", project_path: same project }=> covered by tracking, not missed.git statuswith no tracking row and no hook installed => potential missed savings.git statuswith hook installed but no tracking row => ambiguous hook-rewrite candidate, not confident missed savings.rtk git statusin JSONL => explicit already using RTK.RTK_DISABLED=1 git status=> bypass bucket remains separate.cd app && git status && echo donepreserve per-part accounting.discovercurrently walks subagents, whilesession_cmdfilters them out.The same lesson shows up in ax: transcript logs are pre-execution intent, while hook/tracking telemetry is execution outcome. Adoption metrics should not infer execution outcome from the transcript alone when a rewrite hook sits between the two.
Generated with ax.
Yohjisakamoto commentedon Jul 22, 2026
Your false-positive missed-savings report shows why hook-rewritten commands can distort RTK analytics. Tura’s DeepSWE benchmark measures completed tasks and verifier outcomes, finding fewer agent rounds cut about 80% of overhead. Would you evaluate it? https://turaai.net/docs#benchmark-current-test-set-record
KuSh commentedon Jul 26, 2026
Hi, should be handled by #3206
KuSh commentedon Sep 5, 2026
Closing as a duplicate of #1441, which tracks the same problem with the more complete discussion. Please follow up there; if your case differs in a way that issue does not cover, comment here and it can be reopened.