rtk gain stats not recorded when commands are rewritten via Claude Code hook
#1082 opened on Apr 8, 2026
Description
Bug Description
When git status is intercepted by the Claude Code PreToolUse hook and rewritten to rtk git status, the command executes correctly but is never recorded in rtk gain statistics. Only commands invoked directly as rtk git status are tracked.
Steps to Reproduce
- Install RTK with global hook:
rtk init -g - Confirm hook is active in
~/.claude/hooks/rtk-rewrite.sh - Note current count:
rtk gain | grep "Total commands" - Run
git statusvia Claude Code Bash tool (hook rewrites it tortk git status) - Wait 1+ seconds, then check again:
rtk gain | grep "Total commands"
Result: count does not increase.
- Run
rtk git statusdirectly - Check again: count increases by 1.
Evidence
Database (~/Library/Application Support/rtk/history.db) only contains entries from direct invocations, never from hook-rewritten executions:
| original_cmd | rtk_cmd | timestamp |
|---|---|---|
| git status | rtk git status | 2026-04-08T08:21... |
| git status | rtk git status | 2026-04-06T05:26... |
Verified: defaultMode: bypassPermissions is set, so sandbox write restrictions are not the cause (unlike issue #320).
Root Cause Hypothesis
TimedExecution::start() is only called in run_fallback() and Commands::Proxy. When Claude Code executes the hook-rewritten rtk git status, it goes through Commands::Git which has no tracking call. Something in the hook execution environment prevents the tracking path from being reached.
Environment
- rtk: 0.34.3
- Claude Code hook version: 3
- macOS Darwin 25.3.0
- DB path:
~/Library/Application Support/rtk/history.db