Repository navigation
Description
Problem
Commands with no dedicated filter are recorded, but not measured: rtk hook claude leaves them alone, they run raw, and the row that lands in history.db has input_tokens=0, output_tokens=0.
On my machine that is 4,267 of 18,140 rows — 23.5% (rtk 0.44.0). Those rows are not harmless:
input=0means the raw size was never captured, so nothing can be said about what the command would have cost.- Any savings rollup that divides by row count, or that treats those rows as "zero consumption", is wrong by whatever share they represent.
rtk proxy already solves the measurement half — it executes without filtering and tracks. What is missing is having the hook reach for it automatically.
Request
A flag on rtk hook claude (--proxy-fallback, or config), so that when rtk rewrite has no equivalent, the hook emits updatedInput wrapping the command in rtk proxy instead of staying silent.
I implemented this as an external hook and it has been running fine, so the shape is validated — but it costs an extra process per Bash call (~7.7ms measured), which is pure waste given rtk hook claude is already being executed.
Implementation notes — the four places this goes wrong
These are all things I got wrong first, so they may be worth having in the issue rather than rediscovered:
1. It must go through a shell. rtk proxy execs directly, with no shell, so the wrapper has to be rtk proxy bash -c '<original>'. Wrapping argv directly breaks everything compound:
$ rtk proxy echo A && echo B
A && echo B # the operator became a literal argument
2. Some commands must never be wrapped. Anything whose first word acts on the parent shell:
cd export source . set unset eval exec alias unalias shift trap ulimit umask
pushd popd dirs for while until if case select function time declare local
readonly typeset wait jobs bg fg return exit logout history hash builtin command
plus a leading VAR=value assignment. This one matters more than it looks: Claude Code's Bash tool keeps cwd between calls, so cd inside bash -c silently stops working and the session breaks in a way that is very hard to attribute back to the hook. The decision must be made on the first word of the first instruction — cd /x && python3 y is decided by the cd.
3. Quoting must be POSIX single-quote escaping (shlex.quote in Python, @sh in jq): wrap in '…', replace ' with '\''. printf %q is not equivalent — it emits $'…' ANSI-C forms that mutilate some commands silently. I verified the two escapes against each other over an exhaustive corpus (607 commands, checking byte-for-byte what bash actually delivers as argv), which is the only way I found to be sure.
4. It is blocked on #2829. Wrapping every unfiltered command in rtk proxy while that bug is open converts a niche hang into a per-command one. I commented there with a Linux repro on 0.44.0 and the heuristic I am using in the meantime. This feature should probably ship after #2830, or with the background-command guard built in.
Happy to share the hook implementation if useful.
Activity
pszymkowiak commentedon Aug 10, 2026
🔍 Automated Triage
featuremediumSummary
Add a
--proxy-fallbackoption tortk hook claudeso unfiltered commands are wrapped inrtk proxy bash -cfor measurement instead of running raw with 0/0 token counts; author has a validated external implementation and notes it's blocked on #2829.📁 Relevant files
src/hook/claude.rssrc/proxy.rsTriaged automatically by wshm · This is an automated analysis, not a human review.