Skip to content

add dev tooling guide and RTK token-saving hook#10

Closed
GlamgarOnDiscord wants to merge 1 commit intoLeonxlnx:mainfrom
GlamgarOnDiscord:feat/dev-tooling
Closed

add dev tooling guide and RTK token-saving hook#10
GlamgarOnDiscord wants to merge 1 commit intoLeonxlnx:mainfrom
GlamgarOnDiscord:feat/dev-tooling

Conversation

@GlamgarOnDiscord
Copy link
Copy Markdown

@GlamgarOnDiscord GlamgarOnDiscord commented Apr 1, 2026

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 codebase
  • AGENTS.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: tokei gives an accurate line count in one shot, fd cuts file-search output by ~99% on targeted queries, ast-grep finds 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:

  • Introduce an optional Claude Code PreToolUse hook script that rewrites common shell commands through RTK to reduce token usage.

Documentation:

  • Document recommended local tooling, providers, and usage patterns in CLAUDE.md for working with the codebase.
  • Add AGENTS.md as a concise set of command and tool preferences optimized for AI agents.

Chores:

  • Add Claude workspace settings configuration under .claude/ to support the new RTK hook integration.

Summary by cubic

Adds developer tooling docs and an optional Claude Code PreToolUse hook that rewrites Bash commands via rtk to 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 through rtk rewrite to reduce output; deny/ask/allow handled by the hook and Claude Code.
  • Migration

    • Optional: install rtk (>= 0.23.0) and jq to enable rewrites.
    • To disable, remove the PreToolUse hook entry in .claude/settings.json or delete the hook file.

Written for commit c716770. Summary will update on new commits.

Summary by CodeRabbit

  • Documentation

    • Added developer setup guide with environment variable configuration and tool recommendations
    • Added agent rules documentation outlining preferred command-line workflows
  • Chores

    • Added configuration for command-line tool integration hooks

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.
Copilot AI review requested due to automatic review settings April 1, 2026 10:34
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Apr 1, 2026

Reviewer's Guide

Adds developer-facing documentation for efficient CLI usage in this repo and introduces an optional Claude Code PreToolUse hook that rewrites bash commands through the rtk CLI to reduce token usage for common operations, without touching application source code.

Sequence diagram for Claude Code PreToolUse RTK rewrite hook

sequenceDiagram
  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
Loading

Flow diagram for RTK rewrite hook decision logic

flowchart 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
Loading

File-Level Changes

Change Details Files
Introduce an RTK-based Claude Code PreToolUse hook that rewrites bash commands for token-efficient equivalents while preserving safety and compatibility.
  • Add a bash hook script that reads Claude Code tool input JSON, extracts the requested shell command, and conditionally rewrites it via rtk rewrite.
  • Implement environment and version checks for jq and rtk, including a minimum required rtk version and clear, non-fatal warnings when prerequisites are missing.
  • Honor rtk rewrite exit codes to decide whether to pass commands through, rewrite and auto-allow, or rewrite and require explicit user confirmation.
  • Rebuild the updated tool invocation payload as JSON, injecting the rewritten command and, when appropriate, an auto-allow permission decision for Claude Code.
.claude/hooks/rtk-rewrite.sh
Add human- and agent-oriented documentation for recommended CLI tools and usage patterns tailored to this codebase.
  • Document supported model providers, environment variables, and default models for the project.
  • Describe recommended CLI tools (rtk, rg, fd, ast-grep, jq, sd, tokei), including installation hints, what they replace, and their benefits for token and output reduction.
  • Provide concrete example commands for project overview, file finding, content search, structural search, JSON querying, and safe string replacement.
  • Create a concise ruleset for AI agents that encodes preferred tools and command patterns for typical tasks in this repo.
CLAUDE.md
AGENTS.md
Register Claude-specific configuration to enable the new RTK hook within the repository’s Claude workspace settings.
  • Add a Claude settings JSON file to opt-in the PreToolUse hook for bash commands (exact configuration not shown in diff but implied by the new hook).
.claude/settings.json

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 1, 2026

📝 Walkthrough

Walkthrough

New 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

Cohort / File(s) Summary
RTK Hook Infrastructure
.claude/hooks/rtk-rewrite.sh, .claude/settings.json
New hook script that validates RTK availability and version, reads Claude Code commands from stdin, delegates rewrite decisions to rtk rewrite, and emits JSON responses for permission handling. Configuration file registers the hook as a PreToolUse handler for Bash tool invocations.
Developer Documentation
AGENTS.md, CLAUDE.md
New guides documenting preferred CLI tools for development tasks (e.g., rg, fd, ast-grep, jq, sd, rtk), provider/model configuration setup, example command patterns, and test execution instructions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A rabbit's hook now guards the gate,
Rewriting commands, never too late,
RTK flows through Claude's bright mind,
With tools galore, the best kind to find! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main changes: adding a developer tooling guide (CLAUDE.md, AGENTS.md) and an RTK token-saving hook (.claude/settings.json and .claude/hooks/rtk-rewrite.sh).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 4 issues, and left some high level feedback:

  • 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.
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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +28 to +33
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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +50 to +73
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')
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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 |
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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` |
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.md developer guide (providers, recommended CLI tools, usage examples).
  • Add AGENTS.md condensed tool preference rules for agent workflows.
  • Add .claude/settings.json + .claude/hooks/rtk-rewrite.sh to enable and implement an rtk-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.

Comment on lines +27 to +31
| 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 |
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Comment on lines +23 to +35
## 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 |
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
| 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` |
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 |.

Suggested change
| Query JSON | `jq '.key' file.json` | `cat file.json \| grep` |
| Query JSON | `jq '.key' file.json` | `grep 'pattern' file.json` |

Copilot uses AI. Check for mistakes.
exit 0
;;
2)
# Deny rule matched — let Claude Code's native deny rule handle it.
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
# 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"
}
}'

Copilot uses AI. Check for mistakes.
Comment on lines +26 to +35
# 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
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +12
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": ".claude/hooks/rtk-rewrite.sh"
}
]
}
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between bf9b138 and c716770.

📒 Files selected for processing (4)
  • .claude/hooks/rtk-rewrite.sh
  • .claude/settings.json
  • AGENTS.md
  • CLAUDE.md

Comment on lines +28 to +37
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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

find . -name "rtk-rewrite.sh" -type f

Repository: 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"
fi

Repository: 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.

Suggested change
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.

Comment on lines +25 to +36
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 |

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

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 |
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# Check if CLAUDE.md exists and read the relevant section
git ls-files | grep -i claude

Repository: Leonxlnx/claw-dev

Length of output: 50374


🏁 Script executed:

# Read CLAUDE.md around line 29 to confirm the content
head -35 CLAUDE.md | tail -10

Repository: 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:


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.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

@Leonxlnx
Copy link
Copy Markdown
Owner

Leonxlnx commented Apr 1, 2026

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.

@Leonxlnx Leonxlnx closed this Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants