rtk-ai/rtk

rtk gain stats not recorded when commands are rewritten via Claude Code hook

Open

#1082 opened on Apr 8, 2026

View on GitHub
 (4 comments) (3 reactions) (0 assignees)Rust (48,085 stars) (2,914 forks)batch import
bugeffort-smallgood first issue

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

  1. Install RTK with global hook: rtk init -g
  2. Confirm hook is active in ~/.claude/hooks/rtk-rewrite.sh
  3. Note current count: rtk gain | grep "Total commands"
  4. Run git status via Claude Code Bash tool (hook rewrites it to rtk git status)
  5. Wait 1+ seconds, then check again: rtk gain | grep "Total commands"

Result: count does not increase.

  1. Run rtk git status directly
  2. 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

Contributor guide