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
{{ message }}
Repository navigation
rtk discover reports false negatives when hook-based rewriting is active #1055
rtk discover reports commands as "missed savings" even when the PreToolUse hook (rtk-rewrite.sh) is actively rewriting them. This makes the discover output misleading -- it suggests massive token waste that isn't actually happening.
Steps to reproduce
Install RTK with the Claude Code hook via rtk init
Use Claude Code normally (commands like git diff, ls -la, etc.)
Run rtk gain -- shows 2683 commands processed, 6M tokens saved (86.4%)
Run rtk discover -- shows "Already using RTK: 27 commands (0%)" and reports ~1.3M tokens as "saveable"
Root cause
Claude Code's conversation history (JSONL files) records the command as the assistant requested it (e.g., git diff), not what was actually executed after the hook rewrote it (e.g., rtk git diff).
rtk discover scans these JSONL files, sees git diff, and concludes it wasn't processed by RTK. But the hook intercepted and rewrote it before execution.
Evidence
rtk gain shows 2683 commands with 86.4% savings -- these came from the hook
rtk discover says only 27 commands (0%) used RTK -- it only counts explicit rtk prefixed commands in the history
Output format in Claude Code sessions confirms RTK is active (compact ls output, filtered git diff, etc.)
The hook works correctly when tested manually: echo '{"tool_input":{"command":"git diff"}}' | rtk-rewrite.sh produces the correct rewrite
Suggested fix
Options:
Check if hook is configured: if rtk-rewrite.sh is present in Claude Code's settings.json, assume supported commands are already being rewritten and exclude them from "missed savings"
Hook-side logging: have the hook log rewritten commands to a file that rtk discover can cross-reference against the conversation history
Label the output: at minimum, add a note to discover output like "Note: if using hook-based rewriting, these commands may already be handled"
Environment
rtk 0.30.1 (also checked: not fixed in 0.35.0 release notes)
The hook is functioning correctly (verified with a live test: ls -la /tmp → rewritten to rtk ls -la /tmp and the rtk DB increments). The discrepancy comes from CC's session JSONL storing the original tool_input.command, not the post-hook value, so any session-log-based scanner under-reports rewrites by ~25×. Almost led us to "fix" a working hook config based on the discover output.
Suggested resolution direction (FYI for whoever picks this up): could discover cross-reference the local rtk telemetry DB and discount commands whose timestamp+cwd matches a recorded rewrite? Or simpler — surface a clear note in the discover output when rtk gain shows significant activity, warning that hook-rewritten commands aren't visible in session logs.
Activity
pszymkowiak commentedon Apr 12, 2026
Closing as duplicate of #2036. See the original issue for updates.
fix(discover): cross-reference tracking DB to exclude hook-handled co…
PoloBLS commentedon Apr 30, 2026
Hitting this on Claude Code, both macOS (Homebrew rtk 0.31.0) and Debian (deb 0.31.0). Concrete numbers from a 30-day window on the Mac:
rtk discover: 240 / 9771 commands "already using RTK" → reports 2% adoptionrtk gain: 3380 commands processed, 5.4M tokens saved → 51.7% efficiencyThe hook is functioning correctly (verified with a live test:
ls -la /tmp→ rewritten tortk ls -la /tmpand the rtk DB increments). The discrepancy comes from CC's session JSONL storing the originaltool_input.command, not the post-hook value, so any session-log-based scanner under-reports rewrites by ~25×. Almost led us to "fix" a working hook config based on the discover output.Suggested resolution direction (FYI for whoever picks this up): could
discovercross-reference the local rtk telemetry DB and discount commands whose timestamp+cwd matches a recorded rewrite? Or simpler — surface a clear note in the discover output whenrtk gainshows significant activity, warning that hook-rewritten commands aren't visible in session logs.