Skip to content

Commit f71fa73

Browse files
authored
4/10/2026 (#58)
1 parent 81559e8 commit f71fa73

10 files changed

Lines changed: 186 additions & 16 deletions

File tree

.claude/CLAUDE.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# CLAUDE.md
22

3+
@RTK.md
4+
35
## After every change
46

57
Always execute tasks in this order:
@@ -18,4 +20,4 @@ Always execute tasks in this order:
1820

1921
## Git
2022

21-
- Do not ever commit to the default, `main`, or `master` Git branches. Always ask if a new branch should be created instead.
23+
- Do not ever commit to the default, `main`, or `master` Git branches. Always ask if a new branch should be created instead.

.claude/RTK.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# RTK - Rust Token Killer
2+
3+
**Usage**: Token-optimized CLI proxy (60-90% savings on dev operations)
4+
5+
## Meta Commands (always use rtk directly)
6+
7+
```bash
8+
rtk gain # Show token savings analytics
9+
rtk gain --history # Show command usage history with savings
10+
rtk discover # Analyze Claude Code history for missed opportunities
11+
rtk proxy <cmd> # Execute raw command without filtering (for debugging)
12+
```
13+
14+
## Installation Verification
15+
16+
```bash
17+
rtk --version # Should show: rtk X.Y.Z
18+
rtk gain # Should work (not "command not found")
19+
which rtk # Verify correct binary
20+
```
21+
22+
⚠️ **Name collision**: If `rtk gain` fails, you may have reachingforthejack/rtk (Rust Type Kit) installed instead.
23+
24+
## Hook-Based Usage
25+
26+
All other commands are automatically rewritten by the Claude Code hook.
27+
Example: `git status``rtk git status` (transparent, 0 tokens overhead)
28+
29+
Refer to CLAUDE.md for full command reference.

.claude/hooks/.rtk-hook.sha256

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ef0d630994fd7ef5f2b84fb66cd6249c493bb8736bcacd4734d7c798125018fb rtk-rewrite.sh

.claude/hooks/rtk-rewrite.sh

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/usr/bin/env bash
2+
# rtk-hook-version: 3
3+
# RTK Claude Code hook — rewrites commands to use rtk for token savings.
4+
# Requires: rtk >= 0.23.0, jq
5+
#
6+
# This is a thin delegating hook: all rewrite logic lives in `rtk rewrite`,
7+
# which is the single source of truth (src/discover/registry.rs).
8+
# To add or change rewrite rules, edit the Rust registry — not this file.
9+
#
10+
# Exit code protocol for `rtk rewrite`:
11+
# 0 + stdout Rewrite found, no deny/ask rule matched → auto-allow
12+
# 1 No RTK equivalent → pass through unchanged
13+
# 2 Deny rule matched → pass through (Claude Code native deny handles it)
14+
# 3 + stdout Ask rule matched → rewrite but let Claude Code prompt the user
15+
16+
if ! command -v jq &>/dev/null; then
17+
echo "[rtk] WARNING: jq is not installed. Hook cannot rewrite commands. Install jq: https://jqlang.github.io/jq/download/" >&2
18+
exit 0
19+
fi
20+
21+
if ! command -v rtk &>/dev/null; then
22+
echo "[rtk] WARNING: rtk is not installed or not in PATH. Hook cannot rewrite commands. Install: https://github.com/rtk-ai/rtk#installation" >&2
23+
exit 0
24+
fi
25+
26+
# Version guard: rtk rewrite was added in 0.23.0.
27+
# Older binaries: warn once and exit cleanly (no silent failure).
28+
RTK_VERSION=$(rtk --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
29+
if [ -n "$RTK_VERSION" ]; then
30+
MAJOR=$(echo "$RTK_VERSION" | cut -d. -f1)
31+
MINOR=$(echo "$RTK_VERSION" | cut -d. -f2)
32+
# Require >= 0.23.0
33+
if [ "$MAJOR" -eq 0 ] && [ "$MINOR" -lt 23 ]; then
34+
echo "[rtk] WARNING: rtk $RTK_VERSION is too old (need >= 0.23.0). Upgrade: cargo install rtk" >&2
35+
exit 0
36+
fi
37+
fi
38+
39+
INPUT=$(cat)
40+
CMD=$(echo "$INPUT" | jq -r '.tool_input.command // empty')
41+
42+
if [ -z "$CMD" ]; then
43+
exit 0
44+
fi
45+
46+
# Delegate all rewrite + permission logic to the Rust binary.
47+
REWRITTEN=$(rtk rewrite "$CMD" 2>/dev/null)
48+
EXIT_CODE=$?
49+
50+
case $EXIT_CODE in
51+
0)
52+
# Rewrite found, no permission rules matched — safe to auto-allow.
53+
# If the output is identical, the command was already using RTK.
54+
[ "$CMD" = "$REWRITTEN" ] && exit 0
55+
;;
56+
1)
57+
# No RTK equivalent — pass through unchanged.
58+
exit 0
59+
;;
60+
2)
61+
# Deny rule matched — let Claude Code's native deny rule handle it.
62+
exit 0
63+
;;
64+
3)
65+
# Ask rule matched — rewrite the command but do NOT auto-allow so that
66+
# Claude Code prompts the user for confirmation.
67+
;;
68+
*)
69+
exit 0
70+
;;
71+
esac
72+
73+
ORIGINAL_INPUT=$(echo "$INPUT" | jq -c '.tool_input')
74+
UPDATED_INPUT=$(echo "$ORIGINAL_INPUT" | jq --arg cmd "$REWRITTEN" '.command = $cmd')
75+
76+
if [ "$EXIT_CODE" -eq 3 ]; then
77+
# Ask: rewrite the command, omit permissionDecision so Claude Code prompts.
78+
jq -n \
79+
--argjson updated "$UPDATED_INPUT" \
80+
'{
81+
"hookSpecificOutput": {
82+
"hookEventName": "PreToolUse",
83+
"updatedInput": $updated
84+
}
85+
}'
86+
else
87+
# Allow: rewrite the command and auto-allow.
88+
jq -n \
89+
--argjson updated "$UPDATED_INPUT" \
90+
'{
91+
"hookSpecificOutput": {
92+
"hookEventName": "PreToolUse",
93+
"permissionDecision": "allow",
94+
"permissionDecisionReason": "RTK auto-rewrite",
95+
"updatedInput": $updated
96+
}
97+
}'
98+
fi

.claude/settings.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"model": "us.anthropic.claude-opus-4-6-v1",
2+
"model": "opus",
33
"hooks": {
44
"Notification": [
55
{
@@ -22,6 +22,17 @@
2222
}
2323
]
2424
}
25+
],
26+
"PreToolUse": [
27+
{
28+
"matcher": "Bash",
29+
"hooks": [
30+
{
31+
"type": "command",
32+
"command": "/Users/cemmer/.claude/hooks/rtk-rewrite.sh"
33+
}
34+
]
35+
}
2536
]
2637
},
2738
"statusLine": {

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Secrets
2-
*secrets.bash
2+
*secrets.*
33
id_rsa*
44
*kubeconfig*
55
*.pem
@@ -9,7 +9,8 @@ id_rsa*
99
!.config/powerline
1010

1111
.claude/*
12+
!.claude/hooks
1213
!.claude/skills
1314
.claude/skills/githuman
14-
!.claude/CLAUDE.md
15+
!.claude/*.md
1516
!.claude/settings.json

dotpack/.10_macos.sh

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,19 @@ fi
1111

1212
# https://docs.brew.sh/Shell-Completion
1313
if type brew &>/dev/null; then
14-
HOMEBREW_PREFIX="$(brew --prefix)"
15-
if [[ -r "${HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh" ]]; then
16-
source "${HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh"
17-
else
18-
for COMPLETION in "${HOMEBREW_PREFIX}/etc/bash_completion.d/"*; do
19-
# shellcheck disable=SC1090
20-
[[ -r "${COMPLETION}" ]] && source "${COMPLETION}"
21-
done
14+
if [[ "$(basename "${SHELL}")" == "zsh" ]]; then
15+
autoload -Uz compinit
16+
compinit
17+
elif [[ "$(basename "${SHELL}")" == "bash" ]]; then
18+
HOMEBREW_PREFIX="$(brew --prefix)"
19+
if [[ -r "${HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh" ]]; then
20+
source "${HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh"
21+
else
22+
for COMPLETION in "${HOMEBREW_PREFIX}/etc/bash_completion.d/"*; do
23+
# shellcheck disable=SC1090
24+
[[ -r "${COMPLETION}" ]] && source "${COMPLETION}"
25+
done
26+
fi
2227
fi
2328
fi
2429

dotpack/.30_claude.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
##### https://code.claude.com/docs/en/overview
22

3+
export RTK_TELEMETRY_DISABLED=1
4+
35
__claude_auto_update() {
46
if command -v claude &> /dev/null; then
57
claude() {

install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function link() {
3232

3333
# Assume symlinks are ok
3434
if [[ -h "${link}" ]]; then
35-
echo -e "\033[93mIgnoring:\033[0m ${link}"
35+
echo -e "\033[33mIgnoring:\033[0m ${link}"
3636
continue
3737
fi
3838

packages.sh

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ if [[ "${OSTYPE:-}" == "darwin"* ]]; then
2929
fi
3030
command -v jq > /dev/null || brew install jq
3131
command -v rename > /dev/null || brew install rename
32+
command -v rtk > /dev/null || brew install rtk
3233
command -v terminal-notifier > /dev/null || brew install terminal-notifier
3334
command -v tree > /dev/null || brew install tree
3435
command -v watch > /dev/null || brew install watch
@@ -58,6 +59,7 @@ if [[ "${OSTYPE:-}" == "darwin"* ]]; then
5859
#echo "nordvpn"
5960
#echo "postman"
6061
echo "rectangle"
62+
echo "resilio-sync"
6163
#echo "sdformatter"
6264
#echo "signal"
6365
#echo "slack"
@@ -74,10 +76,29 @@ if [[ "${OSTYPE:-}" == "darwin"* ]]; then
7476
| jq --raw-output ".casks[] | select(.token==\"${cask}\") | .artifacts[] | .app // empty | .[]" \
7577
| xargs -I {} sh -c 'test ! -d "/Applications/{}" && echo "{}"' || true)
7678
if [[ -n "${missing_apps}" ]]; then
77-
echo "missing, installing ..."
79+
echo -e "\033[33mmissing, installing ...\033[0m"
7880
brew install --cask "${cask}"
7981
else
80-
echo "found"
82+
echo -e "\033[92mfound\033[0m"
83+
fi
84+
done
85+
86+
# Uninstall old Homebrew casks
87+
if ! sudo -n true &> /dev/null; then
88+
echo -e "\033[1;33mWARN:\033[0m you may be asked for your password to run 'brew uninstall --cask'\n"
89+
fi
90+
for cask in $(
91+
echo "messenger"
92+
); do
93+
printf "Checking for cask '${cask}' ... "
94+
existing_apps=$(brew info --json=v2 --cask "${cask}" \
95+
| jq --raw-output ".casks[] | select(.token==\"${cask}\") | .artifacts[] | .app // empty | .[]" \
96+
| xargs -I {} sh -c 'test -d "/Applications/{}" && echo "{}"' || true)
97+
if [[ -n "${existing_apps}" ]]; then
98+
echo -e "\033[33mfound, uninstalling ...\033[0m"
99+
brew uninstall --cask "${cask}"
100+
else
101+
echo -e "\033[92mnot found\033[0m"
81102
fi
82103
done
83104

@@ -114,6 +135,6 @@ if [[ "${OSTYPE:-}" == "darwin"* ]]; then
114135
if ! sudo -n true &> /dev/null; then
115136
echo -e "\033[1;33mWARN:\033[0m you may be asked for your password to run 'xcodebuild -license'\n"
116137
fi
117-
sudo xcodebuild -license status || sudo xcodebuild -license accept
138+
sudo xcodebuild -license status || sudo xcodebuild -license accept || true
118139
fi
119140
fi

0 commit comments

Comments
 (0)