rtk-ai/rtk

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

开放

#1,082 创建于 2026年4月8日

 (4 条评论) (3 个反应) (0 位负责人)Rust (2,914 个派生)batch import
area:clibugeffort-smallgood first issueplatform:macospriority:medium

仓库指标

星标
 (48,085 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

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

贡献者指南