add dev tooling guide and RTK token-saving hook#10
add dev tooling guide and RTK token-saving hook#10GlamgarOnDiscord wants to merge 1 commit intoLeonxlnx:mainfrom
Conversation
Adds CLAUDE.md with tool preferences for working on this codebase, AGENTS.md with quick-reference rules for AI agents, and a Claude Code PreToolUse hook that routes bash commands through rtk for 60–90% token reduction on common operations. CLAUDE.md covers all supported providers, recommended CLI tools (fd, rg, ast-grep, jq, sd, tokei), and usage patterns that reduce context noise. AGENTS.md is the short-form version for agent consumption. The .claude/settings.json hook is opt-in and only fires on Bash tool calls. No source files are modified.
Reviewer's GuideAdds developer-facing documentation for efficient CLI usage in this repo and introduces an optional Claude Code PreToolUse hook that rewrites bash commands through the Sequence diagram for Claude Code PreToolUse RTK rewrite hooksequenceDiagram
actor Developer
participant ClaudeCode
participant PreToolUseHook
participant rtk
Developer->>ClaudeCode: Request bash operation
ClaudeCode->>PreToolUseHook: PreToolUse event with tool_input
PreToolUseHook->>PreToolUseHook: Check jq installed
PreToolUseHook->>PreToolUseHook: Check rtk installed and version >= 0.23.0
PreToolUseHook->>PreToolUseHook: Read tool_input.command
alt command missing or empty
PreToolUseHook-->>ClaudeCode: No change
ClaudeCode->>Developer: Run original or abort
else command present
PreToolUseHook->>rtk: rewrite CMD
rtk-->>PreToolUseHook: rewritten command and exit code
alt exit code 0 and rewritten differs
PreToolUseHook-->>ClaudeCode: updatedInput with rewritten command and permissionDecision allow
ClaudeCode->>Developer: Inform about RTK auto rewrite
ClaudeCode->>Shell: Execute rewritten command
else exit code 1 no equivalent
PreToolUseHook-->>ClaudeCode: No change
ClaudeCode->>Shell: Execute original command
else exit code 2 deny rule
PreToolUseHook-->>ClaudeCode: No change
ClaudeCode->>Developer: Native deny handling
else exit code 3 ask rule
PreToolUseHook-->>ClaudeCode: updatedInput with rewritten command no permissionDecision
ClaudeCode->>Developer: Prompt for confirmation
alt Developer approves
ClaudeCode->>Shell: Execute rewritten command
else Developer rejects
ClaudeCode-->>Developer: Command cancelled
end
end
end
Flow diagram for RTK rewrite hook decision logicflowchart TD
A_start[Start hook] --> B_check_jq{jq installed}
B_check_jq -- no --> Z1_warn_jq[Warn jq missing and exit 0]
B_check_jq -- yes --> C_check_rtk{rtk installed}
C_check_rtk -- no --> Z2_warn_rtk[Warn rtk missing and exit 0]
C_check_rtk -- yes --> D_check_version[Check rtk version >= 0.23.0]
D_check_version -->|too old| Z3_warn_old[Warn rtk too old and exit 0]
D_check_version -->|ok or unknown| E_read_input[Read JSON stdin]
E_read_input --> F_extract_cmd[Extract tool_input.command]
F_extract_cmd --> G_cmd_empty{Command empty}
G_cmd_empty -- yes --> Z4_exit_noop[Exit 0 no change]
G_cmd_empty -- no --> H_call_rewrite[Call rtk rewrite CMD]
H_call_rewrite --> I_exit_code{rtk rewrite exit code}
I_exit_code -->|0| J_compare[Compare CMD vs REWRITTEN]
J_compare -->|same| Z4_exit_noop
J_compare -->|different| K_allow[Build updatedInput auto allow]
K_allow --> Z5_output_allow[Output hookSpecificOutput with permissionDecision allow]
I_exit_code -->|1 no equivalent| Z4_exit_noop
I_exit_code -->|2 deny rule| Z4_exit_noop
I_exit_code -->|3 ask rule| L_ask[Build updatedInput without permissionDecision]
L_ask --> Z6_output_ask[Output hookSpecificOutput ask]
I_exit_code -->|other| Z4_exit_noop
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
📝 WalkthroughWalkthroughNew infrastructure for integrating Claude Code with RTK (Rust Toolkit). Adds a Bash hook script that intercepts and rewrites Claude Code tool-use commands to use RTK equivalents, along with configuration to enable the hook and documentation about supported developer tools and setup procedures. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Hey - I've found 4 issues, and left some high level feedback:
- In
CLAUDE.mdthertkinstall command includes an escaped pipe (\| sh) inside a code block, which will break copy-paste usage; it should be a plain| shwithout the backslash. - The example
jq 'keys' shared/providerModels.jsinCLAUDE.mdassumes that file is valid JSON; if it’s actually JavaScript/TypeScript, consider either pointing to a real JSON file or showing a more appropriate inspection command to avoid confusing users.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `CLAUDE.md` the `rtk` install command includes an escaped pipe (`\| sh`) inside a code block, which will break copy-paste usage; it should be a plain `| sh` without the backslash.
- The example `jq 'keys' shared/providerModels.js` in `CLAUDE.md` assumes that file is valid JSON; if it’s actually JavaScript/TypeScript, consider either pointing to a real JSON file or showing a more appropriate inspection command to avoid confusing users.
## Individual Comments
### Comment 1
<location path=".claude/hooks/rtk-rewrite.sh" line_range="28-33" />
<code_context>
+
+# Version guard: rtk rewrite was added in 0.23.0.
+# Older binaries: warn once and exit cleanly (no silent failure).
+RTK_VERSION=$(rtk --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
+if [ -n "$RTK_VERSION" ]; then
+ MAJOR=$(echo "$RTK_VERSION" | cut -d. -f1)
+ MINOR=$(echo "$RTK_VERSION" | cut -d. -f2)
+ # Require >= 0.23.0
+ if [ "$MAJOR" -eq 0 ] && [ "$MINOR" -lt 23 ]; then
+ echo "[rtk] WARNING: rtk $RTK_VERSION is too old (need >= 0.23.0). Upgrade: cargo install rtk" >&2
+ exit 0
</code_context>
<issue_to_address>
**issue (bug_risk):** Guard against non-standard or shorter version strings when parsing rtk version
If `rtk --version` ever returns a non-semver or shorter string, `MAJOR`/`MINOR` may be empty or non-numeric, causing `[ "$MAJOR" -eq 0 ]` to fail. Consider validating that `MAJOR` and `MINOR` are set and numeric before doing comparisons, and exit with a clear warning if parsing fails.
</issue_to_address>
### Comment 2
<location path=".claude/hooks/rtk-rewrite.sh" line_range="50-73" />
<code_context>
+fi
+
+# Delegate all rewrite + permission logic to the Rust binary.
+REWRITTEN=$(rtk rewrite "$CMD" 2>/dev/null)
+EXIT_CODE=$?
+
+case $EXIT_CODE in
+ 0)
+ # Rewrite found, no permission rules matched — safe to auto-allow.
+ # If the output is identical, the command was already using RTK.
+ [ "$CMD" = "$REWRITTEN" ] && exit 0
+ ;;
+ 1)
+ # No RTK equivalent — pass through unchanged.
+ exit 0
+ ;;
+ 2)
+ # Deny rule matched — let Claude Code's native deny rule handle it.
+ exit 0
+ ;;
+ 3)
+ # Ask rule matched — rewrite the command but do NOT auto-allow so that
+ # Claude Code prompts the user for confirmation.
+ ;;
+ *)
+ exit 0
+ ;;
+esac
+
+ORIGINAL_INPUT=$(echo "$INPUT" | jq -c '.tool_input')
+UPDATED_INPUT=$(echo "$ORIGINAL_INPUT" | jq --arg cmd "$REWRITTEN" '.command = $cmd')
+
+if [ "$EXIT_CODE" -eq 3 ]; then
</code_context>
<issue_to_address>
**suggestion:** Handle the case where `rtk rewrite` succeeds but returns an empty string
If `rtk rewrite` exits with 0 or 3 but stdout is empty, we’ll end up rewriting to an empty command and possibly auto-allowing it. Consider checking `[ -n "$REWRITTEN" ]` before using it, and falling back to passthrough when it’s empty to avoid issuing an empty command.
```suggestion
case $EXIT_CODE in
0)
# Rewrite found, no permission rules matched — safe to auto-allow.
# If the output is identical, the command was already using RTK.
[ "$CMD" = "$REWRITTEN" ] && exit 0
;;
1)
# No RTK equivalent — pass through unchanged.
exit 0
;;
2)
# Deny rule matched — let Claude Code's native deny rule handle it.
exit 0
;;
3)
# Ask rule matched — rewrite the command but do NOT auto-allow so that
# Claude Code prompts the user for confirmation.
;;
*)
exit 0
;;
esac
# If rtk rewrite returned success/ask but produced no output, fall back to passthrough.
if [ -z "$REWRITTEN" ]; then
exit 0
fi
ORIGINAL_INPUT=$(echo "$INPUT" | jq -c '.tool_input')
```
</issue_to_address>
### Comment 3
<location path="CLAUDE.md" line_range="29" />
<code_context>
+
+| Tool | Install | Replaces | Gain |
+|------|---------|----------|------|
+| **rtk** | `curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/refs/heads/master/install.sh \| sh` | — | -60/90% tokens on bash output |
+| **rg** | `apt install ripgrep` / `brew install ripgrep` | grep | Fastest content search |
+| **fd** | `apt install fd-find` / `brew install fd` | find | -99% output on targeted search |
</code_context>
<issue_to_address>
**issue (bug_risk):** The backslash before `|` in the `rtk` install command will break copy-paste usage.
In inline code you don’t need to escape `|`. As written, `\|` will be copied literally and the shell pipeline will fail. Please drop the backslash so the command is `curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/refs/heads/master/install.sh | sh` for correct copy-paste behavior.
</issue_to_address>
### Comment 4
<location path="AGENTS.md" line_range="11" />
<code_context>
+| Find files | `fd -e ts src/` | `find src -name "*.ts"` |
+| Search content | `rg 'pattern' src/ -t ts` | `grep -r` |
+| Structural search | `ast-grep run --lang ts --pattern '...' src/` | complex regex |
+| Query JSON | `jq '.key' file.json` | `cat file.json \| grep` |
+| Replace strings | `sd 'old' 'new' file.ts` | `sed -i` |
+| Run tests | `node --test tests/*.test.mjs` | — |
</code_context>
<issue_to_address>
**issue (bug_risk):** The `cat`/`grep` example unnecessarily escapes `|`, which would break the shell command.
Because this is inline code, `|` doesn’t need escaping in Markdown. Keeping the backslash will show up in the copied command and make it invalid shell syntax. Please change this to ``cat file.json | grep``.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| RTK_VERSION=$(rtk --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1) | ||
| if [ -n "$RTK_VERSION" ]; then | ||
| MAJOR=$(echo "$RTK_VERSION" | cut -d. -f1) | ||
| MINOR=$(echo "$RTK_VERSION" | cut -d. -f2) | ||
| # Require >= 0.23.0 | ||
| if [ "$MAJOR" -eq 0 ] && [ "$MINOR" -lt 23 ]; then |
There was a problem hiding this comment.
issue (bug_risk): Guard against non-standard or shorter version strings when parsing rtk version
If rtk --version ever returns a non-semver or shorter string, MAJOR/MINOR may be empty or non-numeric, causing [ "$MAJOR" -eq 0 ] to fail. Consider validating that MAJOR and MINOR are set and numeric before doing comparisons, and exit with a clear warning if parsing fails.
| case $EXIT_CODE in | ||
| 0) | ||
| # Rewrite found, no permission rules matched — safe to auto-allow. | ||
| # If the output is identical, the command was already using RTK. | ||
| [ "$CMD" = "$REWRITTEN" ] && exit 0 | ||
| ;; | ||
| 1) | ||
| # No RTK equivalent — pass through unchanged. | ||
| exit 0 | ||
| ;; | ||
| 2) | ||
| # Deny rule matched — let Claude Code's native deny rule handle it. | ||
| exit 0 | ||
| ;; | ||
| 3) | ||
| # Ask rule matched — rewrite the command but do NOT auto-allow so that | ||
| # Claude Code prompts the user for confirmation. | ||
| ;; | ||
| *) | ||
| exit 0 | ||
| ;; | ||
| esac | ||
|
|
||
| ORIGINAL_INPUT=$(echo "$INPUT" | jq -c '.tool_input') |
There was a problem hiding this comment.
suggestion: Handle the case where rtk rewrite succeeds but returns an empty string
If rtk rewrite exits with 0 or 3 but stdout is empty, we’ll end up rewriting to an empty command and possibly auto-allowing it. Consider checking [ -n "$REWRITTEN" ] before using it, and falling back to passthrough when it’s empty to avoid issuing an empty command.
| case $EXIT_CODE in | |
| 0) | |
| # Rewrite found, no permission rules matched — safe to auto-allow. | |
| # If the output is identical, the command was already using RTK. | |
| [ "$CMD" = "$REWRITTEN" ] && exit 0 | |
| ;; | |
| 1) | |
| # No RTK equivalent — pass through unchanged. | |
| exit 0 | |
| ;; | |
| 2) | |
| # Deny rule matched — let Claude Code's native deny rule handle it. | |
| exit 0 | |
| ;; | |
| 3) | |
| # Ask rule matched — rewrite the command but do NOT auto-allow so that | |
| # Claude Code prompts the user for confirmation. | |
| ;; | |
| *) | |
| exit 0 | |
| ;; | |
| esac | |
| ORIGINAL_INPUT=$(echo "$INPUT" | jq -c '.tool_input') | |
| case $EXIT_CODE in | |
| 0) | |
| # Rewrite found, no permission rules matched — safe to auto-allow. | |
| # If the output is identical, the command was already using RTK. | |
| [ "$CMD" = "$REWRITTEN" ] && exit 0 | |
| ;; | |
| 1) | |
| # No RTK equivalent — pass through unchanged. | |
| exit 0 | |
| ;; | |
| 2) | |
| # Deny rule matched — let Claude Code's native deny rule handle it. | |
| exit 0 | |
| ;; | |
| 3) | |
| # Ask rule matched — rewrite the command but do NOT auto-allow so that | |
| # Claude Code prompts the user for confirmation. | |
| ;; | |
| *) | |
| exit 0 | |
| ;; | |
| esac | |
| # If rtk rewrite returned success/ask but produced no output, fall back to passthrough. | |
| if [ -z "$REWRITTEN" ]; then | |
| exit 0 | |
| fi | |
| ORIGINAL_INPUT=$(echo "$INPUT" | jq -c '.tool_input') |
|
|
||
| | Tool | Install | Replaces | Gain | | ||
| |------|---------|----------|------| | ||
| | **rtk** | `curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/refs/heads/master/install.sh \| sh` | — | -60/90% tokens on bash output | |
There was a problem hiding this comment.
issue (bug_risk): The backslash before | in the rtk install command will break copy-paste usage.
In inline code you don’t need to escape |. As written, \| will be copied literally and the shell pipeline will fail. Please drop the backslash so the command is curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/refs/heads/master/install.sh | sh for correct copy-paste behavior.
| | Find files | `fd -e ts src/` | `find src -name "*.ts"` | | ||
| | Search content | `rg 'pattern' src/ -t ts` | `grep -r` | | ||
| | Structural search | `ast-grep run --lang ts --pattern '...' src/` | complex regex | | ||
| | Query JSON | `jq '.key' file.json` | `cat file.json \| grep` | |
There was a problem hiding this comment.
issue (bug_risk): The cat/grep example unnecessarily escapes |, which would break the shell command.
Because this is inline code, | doesn’t need escaping in Markdown. Keeping the backslash will show up in the copied command and make it invalid shell syntax. Please change this to cat file.json | grep.
There was a problem hiding this comment.
Pull request overview
Adds repository-local developer tooling documentation and a Claude Code PreToolUse hook intended to rewrite Bash commands through rtk to reduce tool-output token usage.
Changes:
- Add
CLAUDE.mddeveloper guide (providers, recommended CLI tools, usage examples). - Add
AGENTS.mdcondensed tool preference rules for agent workflows. - Add
.claude/settings.json+.claude/hooks/rtk-rewrite.shto enable and implement anrtk-based Bash command rewrite hook.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| CLAUDE.md | New developer guide covering providers, tool recommendations, and common command patterns. |
| AGENTS.md | New concise agent-oriented tool preference/command reference. |
| .claude/settings.json | Enables a PreToolUse hook for Bash tool calls. |
| .claude/hooks/rtk-rewrite.sh | Implements the hook: reads Claude Code hook JSON, delegates rewrite to rtk rewrite, and returns updated input/permissions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| | Tool | Install | Replaces | Gain | | ||
| |------|---------|----------|------| | ||
| | **rtk** | `curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/refs/heads/master/install.sh \| sh` | — | -60/90% tokens on bash output | | ||
| | **rg** | `apt install ripgrep` / `brew install ripgrep` | grep | Fastest content search | | ||
| | **fd** | `apt install fd-find` / `brew install fd` | find | -99% output on targeted search | |
There was a problem hiding this comment.
The rtk install one-liner includes an escaped pipe (\|) inside inline code. When copied into a shell this becomes a literal | character (not a pipeline), so the command won’t work as intended. Consider rewriting the example to avoid a literal | in the table cell (e.g., use a bash -c "$(curl …)" form, or move the full install command into a fenced code block where an unescaped | can be shown correctly).
| ## Recommended Tools | ||
|
|
||
| All cross-platform (Linux / macOS / Windows). | ||
|
|
||
| | Tool | Install | Replaces | Gain | | ||
| |------|---------|----------|------| | ||
| | **rtk** | `curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/refs/heads/master/install.sh \| sh` | — | -60/90% tokens on bash output | | ||
| | **rg** | `apt install ripgrep` / `brew install ripgrep` | grep | Fastest content search | | ||
| | **fd** | `apt install fd-find` / `brew install fd` | find | -99% output on targeted search | | ||
| | **ast-grep** | `npm install -g @ast-grep/cli` | regex grep | Semantic TS/JS code search | | ||
| | **jq** | `apt install jq` / `brew install jq` | grep on JSON | Precise JSON queries | | ||
| | **sd** | `cargo install sd` / `brew install sd` | sed | Cross-platform safe replace | | ||
| | **tokei** | `cargo install tokei` / `brew install tokei` | wc/ls | -75% vs ls for project overview | |
There was a problem hiding this comment.
The statement “All cross-platform (Linux / macOS / Windows).” is followed by install commands that are Linux/macOS-specific (apt, brew, cargo, npm). This is likely to confuse Windows users. Please either soften the claim (e.g., “tools are cross-platform”) or add Windows installation options (winget/choco/Scoop) for the listed tools.
| | Find files | `fd -e ts src/` | `find src -name "*.ts"` | | ||
| | Search content | `rg 'pattern' src/ -t ts` | `grep -r` | | ||
| | Structural search | `ast-grep run --lang ts --pattern '...' src/` | complex regex | | ||
| | Query JSON | `jq '.key' file.json` | `cat file.json \| grep` | |
There was a problem hiding this comment.
In the “Query JSON” example, the table uses an escaped pipe (\|) inside inline code: cat file.json \| grep. Copy/pasting this into a shell won’t behave like a pipeline. Consider changing the example formatting (e.g., avoid | in a table cell, or use a fenced code block) so the command can be shown with a real |.
| | Query JSON | `jq '.key' file.json` | `cat file.json \| grep` | | |
| | Query JSON | `jq '.key' file.json` | `grep 'pattern' file.json` | |
| exit 0 | ||
| ;; | ||
| 2) | ||
| # Deny rule matched — let Claude Code's native deny rule handle it. |
There was a problem hiding this comment.
The header comment says exit code 2 means a “Deny rule matched”, but the implementation simply exits 0 and lets the original command run. That makes rtk deny rules ineffective unless Claude Code is separately configured to deny the same command. Consider returning a hook response that explicitly denies (if supported) or at least forces a prompt (ask) when rtk rewrite returns 2.
| # Deny rule matched — let Claude Code's native deny rule handle it. | |
| # Deny rule matched — explicitly deny the command via the hook response. | |
| jq -n '{ | |
| "hookSpecificOutput": { | |
| "hookEventName": "PreToolUse", | |
| "permissionDecision": "deny", | |
| "permissionDecisionReason": "RTK deny rule matched" | |
| } | |
| }' |
| # Version guard: rtk rewrite was added in 0.23.0. | ||
| # Older binaries: warn once and exit cleanly (no silent failure). | ||
| RTK_VERSION=$(rtk --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1) | ||
| if [ -n "$RTK_VERSION" ]; then | ||
| MAJOR=$(echo "$RTK_VERSION" | cut -d. -f1) | ||
| MINOR=$(echo "$RTK_VERSION" | cut -d. -f2) | ||
| # Require >= 0.23.0 | ||
| if [ "$MAJOR" -eq 0 ] && [ "$MINOR" -lt 23 ]; then | ||
| echo "[rtk] WARNING: rtk $RTK_VERSION is too old (need >= 0.23.0). Upgrade: cargo install rtk" >&2 | ||
| exit 0 |
There was a problem hiding this comment.
The version-guard comment says it will “warn once and exit cleanly”, but the script will print the warning on every hook invocation when an old rtk is installed. To reduce repeated noise, consider implementing a one-time warning (e.g., a sentinel file under $XDG_CACHE_HOME/$TMPDIR) or adjust the comment to match the current behavior.
| { | ||
| "hooks": { | ||
| "PreToolUse": [ | ||
| { | ||
| "matcher": "Bash", | ||
| "hooks": [ | ||
| { | ||
| "type": "command", | ||
| "command": ".claude/hooks/rtk-rewrite.sh" | ||
| } | ||
| ] | ||
| } |
There was a problem hiding this comment.
PR description says the hook is “opt-in”, but committing .claude/settings.json will enable the PreToolUse hook for all Claude Code users by default. If true opt-in is intended, consider shipping this as an example file (or gating execution on an env var / repo-local flag) so users must explicitly enable it.
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.claude/hooks/rtk-rewrite.sh:
- Around line 28-37: The script currently only checks parsed RTK_VERSION but
silently continues if parsing fails; update the version-guard block around
RTK_VERSION (the rtk --version parsing) to detect an empty/unparseable
RTK_VERSION (i.e., test -z "$RTK_VERSION"), and when it is empty print a clear
warning to stderr that the rtk version could not be determined (include the raw
output of `rtk --version` if possible) and exit (same exit behavior as the
old-version branch) so the script does not proceed to call `rtk rewrite`
silently; keep the existing MAJOR/MINOR logic unchanged.
In `@CLAUDE.md`:
- Around line 25-36: The header "All cross-platform (Linux / macOS / Windows)."
overstates Windows support because the install examples for tools (rtk, rg, fd,
ast-grep, jq, sd, tokei) only show apt/brew/npm/cargo; either add Windows
install equivalents (e.g., winget/choco/powershell commands for each tool row:
rtk, rg, fd, ast-grep, jq, sd, tokei) or change the header to only list "Linux /
macOS" and update any other mention at line 77 accordingly so the documentation
matches the shown install commands.
- Line 29: Update the CLAUDE.md table row for "**rtk**" to mention alternative
install methods instead of only the curl-pipe-to-shell command: add brief
entries for "brew install rtk", "cargo install --git
https://github.com/rtk-ai/rtk", and "pre-built binaries from GitHub releases",
and/or replace the single command cell with a short list or a link to RTK's
official installation docs (e.g., https://mintlify.com/rtk-ai/rtk/installation)
so readers see multiple supported installation approaches for the rtk entry.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: d8920649-c498-47b0-a594-46abac1f916c
📒 Files selected for processing (4)
.claude/hooks/rtk-rewrite.sh.claude/settings.jsonAGENTS.mdCLAUDE.md
| RTK_VERSION=$(rtk --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1) | ||
| if [ -n "$RTK_VERSION" ]; then | ||
| MAJOR=$(echo "$RTK_VERSION" | cut -d. -f1) | ||
| MINOR=$(echo "$RTK_VERSION" | cut -d. -f2) | ||
| # Require >= 0.23.0 | ||
| if [ "$MAJOR" -eq 0 ] && [ "$MINOR" -lt 23 ]; then | ||
| echo "[rtk] WARNING: rtk $RTK_VERSION is too old (need >= 0.23.0). Upgrade: cargo install rtk" >&2 | ||
| exit 0 | ||
| fi | ||
| fi |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
find . -name "rtk-rewrite.sh" -type fRepository: Leonxlnx/claw-dev
Length of output: 91
🏁 Script executed:
# Check if the file exists and read its content
if [ -f ".claude/hooks/rtk-rewrite.sh" ]; then
wc -l ".claude/hooks/rtk-rewrite.sh"
echo "---"
cat -n ".claude/hooks/rtk-rewrite.sh"
fiRepository: Leonxlnx/claw-dev
Length of output: 3909
Add warning when RTK version parsing fails.
The version guard comment (line 27) promises "no silent failure," but if rtk --version output doesn't match the expected semver format, the guard silently skips, and the script proceeds to call rtk rewrite with no diagnostic. Add an explicit check for unparseable version output.
Proposed fix
RTK_VERSION=$(rtk --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
-if [ -n "$RTK_VERSION" ]; then
+if [ -z "$RTK_VERSION" ]; then
+ echo "[rtk] WARNING: unable to parse rtk version; expected semver (>= 0.23.0)." >&2
+ exit 0
+else
MAJOR=$(echo "$RTK_VERSION" | cut -d. -f1)
MINOR=$(echo "$RTK_VERSION" | cut -d. -f2)
# Require >= 0.23.0
if [ "$MAJOR" -eq 0 ] && [ "$MINOR" -lt 23 ]; then
echo "[rtk] WARNING: rtk $RTK_VERSION is too old (need >= 0.23.0). Upgrade: cargo install rtk" >&2
exit 0
fi
fi📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| RTK_VERSION=$(rtk --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1) | |
| if [ -n "$RTK_VERSION" ]; then | |
| MAJOR=$(echo "$RTK_VERSION" | cut -d. -f1) | |
| MINOR=$(echo "$RTK_VERSION" | cut -d. -f2) | |
| # Require >= 0.23.0 | |
| if [ "$MAJOR" -eq 0 ] && [ "$MINOR" -lt 23 ]; then | |
| echo "[rtk] WARNING: rtk $RTK_VERSION is too old (need >= 0.23.0). Upgrade: cargo install rtk" >&2 | |
| exit 0 | |
| fi | |
| fi | |
| RTK_VERSION=$(rtk --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1) | |
| if [ -z "$RTK_VERSION" ]; then | |
| echo "[rtk] WARNING: unable to parse rtk version; expected semver (>= 0.23.0)." >&2 | |
| exit 0 | |
| else | |
| MAJOR=$(echo "$RTK_VERSION" | cut -d. -f1) | |
| MINOR=$(echo "$RTK_VERSION" | cut -d. -f2) | |
| # Require >= 0.23.0 | |
| if [ "$MAJOR" -eq 0 ] && [ "$MINOR" -lt 23 ]; then | |
| echo "[rtk] WARNING: rtk $RTK_VERSION is too old (need >= 0.23.0). Upgrade: cargo install rtk" >&2 | |
| exit 0 | |
| fi | |
| fi |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In @.claude/hooks/rtk-rewrite.sh around lines 28 - 37, The script currently only
checks parsed RTK_VERSION but silently continues if parsing fails; update the
version-guard block around RTK_VERSION (the rtk --version parsing) to detect an
empty/unparseable RTK_VERSION (i.e., test -z "$RTK_VERSION"), and when it is
empty print a clear warning to stderr that the rtk version could not be
determined (include the raw output of `rtk --version` if possible) and exit
(same exit behavior as the old-version branch) so the script does not proceed to
call `rtk rewrite` silently; keep the existing MAJOR/MINOR logic unchanged.
| All cross-platform (Linux / macOS / Windows). | ||
|
|
||
| | Tool | Install | Replaces | Gain | | ||
| |------|---------|----------|------| | ||
| | **rtk** | `curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/refs/heads/master/install.sh \| sh` | — | -60/90% tokens on bash output | | ||
| | **rg** | `apt install ripgrep` / `brew install ripgrep` | grep | Fastest content search | | ||
| | **fd** | `apt install fd-find` / `brew install fd` | find | -99% output on targeted search | | ||
| | **ast-grep** | `npm install -g @ast-grep/cli` | regex grep | Semantic TS/JS code search | | ||
| | **jq** | `apt install jq` / `brew install jq` | grep on JSON | Precise JSON queries | | ||
| | **sd** | `cargo install sd` / `brew install sd` | sed | Cross-platform safe replace | | ||
| | **tokei** | `cargo install tokei` / `brew install tokei` | wc/ls | -75% vs ls for project overview | | ||
|
|
There was a problem hiding this comment.
Cross-platform claim is broader than the shown commands.
Line [25] says Windows is supported, but examples are Linux/macOS-centric. Add Windows equivalents (e.g., winget/choco) or narrow the claim.
Also applies to: 77-77
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@CLAUDE.md` around lines 25 - 36, The header "All cross-platform (Linux /
macOS / Windows)." overstates Windows support because the install examples for
tools (rtk, rg, fd, ast-grep, jq, sd, tokei) only show apt/brew/npm/cargo;
either add Windows install equivalents (e.g., winget/choco/powershell commands
for each tool row: rtk, rg, fd, ast-grep, jq, sd, tokei) or change the header to
only list "Linux / macOS" and update any other mention at line 77 accordingly so
the documentation matches the shown install commands.
|
|
||
| | Tool | Install | Replaces | Gain | | ||
| |------|---------|----------|------| | ||
| | **rtk** | `curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/refs/heads/master/install.sh \| sh` | — | -60/90% tokens on bash output | |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# Check if CLAUDE.md exists and read the relevant section
git ls-files | grep -i claudeRepository: Leonxlnx/claw-dev
Length of output: 50374
🏁 Script executed:
# Read CLAUDE.md around line 29 to confirm the content
head -35 CLAUDE.md | tail -10Repository: Leonxlnx/claw-dev
Length of output: 836
🌐 Web query:
RTK RTK-AI installation official documentation best practices
💡 Result:
RTK (Rust Token Killer from rtk-ai/rtk) is a CLI proxy that reduces LLM token consumption by 60-90% on common dev commands for AI coding assistants like Claude Code. Official documentation is at https://mintlify.com/rtk-ai/rtk/ and GitHub https://github.com/rtk-ai/rtk (with INSTALL.md, TROUBLESHOOTING.md). Installation Best Practices: 1. Pre-check: Verify correct RTK (not Rust Type Kit): rtk --version rtk gain # Must show token savings or "No tracking data yet" 2. Preferred methods (choose one): - Homebrew (macOS/Linux recommended): brew install rtk - Quick script (Linux/macOS): curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/master/install.sh | sh - Cargo (specify repo to avoid wrong package): cargo install --git https://github.com/rtk-ai/rtk - Pre-built binaries from GitHub releases for all platforms. 3. Add to PATH if needed: export PATH="$HOME/.local/bin:$PATH" (add to ~/.bashrc or ~/.zshrc). 4. Verify: rtk --version && rtk gain && rtk ls . 5. Initialize for AI integration (recommended global): rtk init --global # Installs hook at ~/.claude/hooks/rtk-rewrite.sh, RTK.md, patches ~/.claude/settings.json (backs up first). Answer 'y' to patch. Platform notes: - macOS: Use aarch64 binary for Apple Silicon. - Linux: Script works universally; DEB/RPM packages available. - Windows: Extract binary, add to PATH; limited testing. Troubleshooting: - Wrong RTK: cargo uninstall rtk then reinstall from rtk-ai/rtk. - Command not found: Check/add ~/.cargo/bin or ~/.local/bin to PATH. - Hook issues: rtk init --show; restore from .bak if needed. Usage best practices: - Use rtk prefix manually: rtk git status, rtk cargo test (or auto with hooks). - Global hooks enable transparent rewriting. - Check savings: rtk gain. - Config at ~/.config/rtk/config.toml for tracking, tee (error logs), filters. - Always propagate exit codes; tee saves full output on failures. Uninstall: rtk init --global --uninstall; cargo uninstall rtk or brew uninstall rtk; rm -rf ~/.local/share/rtk ~/.config/rtk.
Citations:
- 1: https://mintlify.com/rtk-ai/rtk/installation
- 2: https://github.com/rtk-ai/rtk/blob/master/INSTALL.md
- 3: https://www.mintlify.com/rtk-ai/rtk/quickstart
- 4: https://mintlify.com/rtk-ai/rtk/troubleshooting
- 5: https://rtk-ai.app/
- 6: https://mintlify.com/rtk-ai/rtk/introduction
- 7: https://mintlify.com/rtk-ai/rtk/integration/configuration
- 8: https://github.com/pszymkowiak/rtk
- 9: https://www.mintlify.com/rtk-ai/rtk/installation
Consider documenting RTK installation alternatives in CLAUDE.md.
The curl-pipe-to-shell method on line 29 is officially supported by RTK, but the table could acknowledge that package managers (Homebrew, Cargo) and pre-built binaries offer equally valid alternatives. Per RTK's official documentation, recommended methods include:
brew install rtk(marked as macOS/Linux preferred)cargo install --git https://github.com/rtk-ai/rtk- Pre-built binaries from GitHub releases
If improving clarity is desired, consider updating the table to reference multiple installation approaches or linking to RTK's official installation docs.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@CLAUDE.md` at line 29, Update the CLAUDE.md table row for "**rtk**" to
mention alternative install methods instead of only the curl-pipe-to-shell
command: add brief entries for "brew install rtk", "cargo install --git
https://github.com/rtk-ai/rtk", and "pre-built binaries from GitHub releases",
and/or replace the single command cell with a short list or a link to RTK's
official installation docs (e.g., https://mintlify.com/rtk-ai/rtk/installation)
so readers see multiple supported installation approaches for the rtk entry.
|
Thanks for the tooling and documentation ideas here. I am not merging this PR as-is, but the contribution is acknowledged in CONTRIBUTORS.md so the work still gets visible credit in the repository. |
Adds three files for working on this codebase more efficiently.
What's added
CLAUDE.md— documents all supported providers, recommended CLI tools (fd, rg, ast-grep, jq, sd, tokei), and usage patterns that reduce noise when working through the codebaseAGENTS.md— short-form version of the same rules for AI agent consumption.claude/settings.json+.claude/hooks/rtk-rewrite.sh— opt-in PreToolUse hook that routes bash commands through rtk for 60–90% token reduction on common operations (git, grep, find, etc.)What's not changed
No source files are modified. The hook only fires on Claude Code Bash tool calls and is easy to remove.
Why
Tested on the codebase:
tokeigives an accurate line count in one shot,fdcuts file-search output by ~99% on targeted queries,ast-grepfinds semantic code patterns that regex cannot. Results are more precise and use less context.Summary by Sourcery
Add developer tooling documentation and an optional Claude Code RTK rewrite hook for more efficient local development and agent usage.
Enhancements:
Documentation:
Chores:
Summary by cubic
Adds developer tooling docs and an optional Claude Code PreToolUse hook that rewrites Bash commands via
rtkto cut token usage by 60–90%. No source files are changed; the hook only applies to Claude Code Bash tool calls.New Features
CLAUDE.md: supported providers, recommended CLIs (fd,rg,ast-grep,jq,sd,tokei), and usage tips.AGENTS.md: quick-reference rules and command examples..claude/settings.json+.claude/hooks/rtk-rewrite.sh: opt-in hook that routes commands throughrtk rewriteto reduce output; deny/ask/allow handled by the hook and Claude Code.Migration
rtk(>= 0.23.0) andjqto enable rewrites..claude/settings.jsonor delete the hook file.Written for commit c716770. Summary will update on new commits.
Summary by CodeRabbit
Documentation
Chores