mirror of
https://github.com/rtk-ai/rtk.git
synced 2026-09-19 07:33:17 +08:00
d0396da1ce
* fix: handle tail rewrites with read tail-lines * feat: add 32 TOML-filtered commands to hook rewrite rules (#475) Add rewrite rules for all TOML-filtered commands so the Claude Code hook automatically rewrites them to `rtk proxy <cmd>`. This ensures TOML filters apply transparently without manual `rtk` prefixing. Commands added: ansible-playbook, brew, composer, df, dotnet, du, fail2ban-client, gcloud, hadolint, helm, iptables, make, markdownlint, mix, mvn, ping, pio, poetry, pre-commit, ps, quarto, rsync, shellcheck, shopify, sops, swift, systemctl, terraform, tofu, trunk, uv, yamllint. Tests updated to use `htop` as unsupported command example since terraform is now supported via TOML filter. Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu> * fix: git log --oneline no longer silently truncated to 10 entries (#461) (#478) Only inject -10 limit when RTK applies its own compact format. When user provides --oneline/--pretty/--format, respect git's default behavior (no limit). Also detect -n and --max-count as user-provided limit flags. Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu> * fix: gh run view --job flag loses its value (#416) (#477) Add --job and --attempt to flags_with_value in extract_identifier_and_extra_args() so their values are not mistaken for the run identifier when placed before it. Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu> * fix: rtk read no longer corrupts JSON files with glob patterns (#464) (#479) Add Language::Data variant for JSON, YAML, TOML, XML, Markdown, CSV and other data formats. These files have no comment syntax, so the MinimalFilter skips comment stripping entirely. Previously, `packages/*` in package.json was treated as a block comment start (`/*`), causing everything until the next `*/` to be stripped — corrupting the JSON structure. Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu> * fix: npm routing, discover cat redirect, proxy quoted args (#480) * fix: npm routing, discover cat redirect, proxy quoted args (#470, #315, #388) #470: rtk npm now correctly routes npm subcommands (install, list, audit, etc.) without injecting "run". Previously, `rtk npm install` was executed as `npm run install`. #315: discover no longer counts `cat >`, `cat >>`, `cat |` as missed savings. These are write/pipe operations with no terminal output to compress. #388: rtk proxy now auto-splits a single quoted argument containing spaces. `rtk proxy 'head -50 file.php'` now works like `rtk proxy head -50 file.php`. Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu> * fix: proxy quote-aware split, redirect detection scan all tokens, npm test routing - Proxy: replace split_whitespace with shell_split() that respects quotes (#388) e.g. 'git log --format="%H %s"' no longer splits on space inside quotes - Discover: scan all tokens for redirect operators, not just nth(1) (#315) e.g. 'cat file.txt > output.txt' now correctly detected as write - npm: replace tautological test with actual routing logic verification Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu> --------- Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu> * feat: add 11 new TOML built-in filters (xcodebuild, jq, basedpyright, ty, skopeo, stat, biome, oxlint, jj, ssh, gcc) (#490) Closes #484, #483, #449, #448, #428, #283, #316, #195, #271, #333, #87, #376 Signed-off-by: Patrick <patrick@rtk.ai> Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu> * fix: rtk rewrite accepts multiple args without quotes (#504) * fix: rtk rewrite accepts multiple args without quotes `rtk rewrite ls -al` now works the same as `rtk rewrite "ls -al"`. Previously, args after the command were rejected or caused ENOENT. Also adds rewrite tests to benchmark.sh to prevent regression. Signed-off-by: Patrick Szymkowiak <patrick.szymkowiak@rtk-ai.app> Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu> * test: add Clap rewrite tests + fix benchmark false failures - Add 2 Clap try_parse_from tests for rewrite multi-args (catches the KuSh bug at unit test level, not just benchmark) - Fix git diff benchmark: use HEAD~1 on both sides for fair comparison - Skip cargo/rustc benchmarks when tools not in PATH instead of false FAIL - Benchmark: 0 fail, 4 skip (env-dependent), 52 green Signed-off-by: Patrick Szymkowiak <patrick.szymkowiak@rtk-ai.app> Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu> --------- Signed-off-by: Patrick Szymkowiak <patrick.szymkowiak@rtk-ai.app> Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu> * fix: use rtk <cmd> instead of rtk proxy for TOML-filtered commands (#507) - Replace all 32 `rtk proxy <cmd>` rules with `rtk <cmd>` so TOML filters actually apply (proxy bypasses filters, giving 0% real savings) - Extract NPM_SUBCOMMANDS to module-level const to prevent test/prod drift Reported-by: FlorianBruniaux Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu> * fix: warn when no hook installed + rtk gain hook status + PR #499 fixes - hook_check: detect missing hook (not just outdated), warn with ⚠️ Only warns if ~/.claude/ exists (Claude Code user) — once per day - gain: show hook status warning (missing/outdated) in rtk gain output - ssh.toml: bump max_lines 50→200, truncate_lines_at 120→200 (Florian review) - git.rs: mark integration test #[ignore] + assert binary exists (Florian review) - Add HookStatus enum for reuse across gain/diagnostics Fixes #508, Fixes #509 Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu> * fix: address code review — hook_check edge cases - status() checks .claude/ existence (no false warning for non-CC users) - Unreadable hook file returns Outdated not Missing - Swap marker/warning order (emit warning before touching rate-limit marker) - Rename misleading test, add end-to-end status() test Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu> * fix: review iteration 2 — double-warning, case-sensitive test, ssh truncate - Refactor check_and_warn to delegate to status() (single source of truth) - Fix double-warning: skip maybe_warn() for `rtk gain` (has its own inline warning) - Fix git test: case-insensitive assertion for cross-locale compatibility - ssh.toml: keep truncate_lines_at=120 (terminal width convention) - Robust mtime handling: unwrap_or(u64::MAX) instead of nested .ok()? - Test handles all CI environments (no hook, no .claude, hook present) Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu> * fix: detect and warn RTK_DISABLED=1 overuse (#508) - discover: count RTK_DISABLED= bypassed commands, report top 5 examples - gain: lightweight 7-day JSONL scan, warn if >10% commands bypassed - registry: add has_rtk_disabled_prefix() and strip_disabled_prefix() helpers - gitignore: add .fastembed_cache/ and .next/ Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu> * fix: preserve trailing newline in tail_lines + add missing test - apply_line_window() now preserves trailing newline when input has one - Add test for tail --lines N (space form) rewrite - Add test for tail_lines without trailing newline Signed-off-by: Patrick <patrick@rtk-ai.com> Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu> * fix: respect user-specified git log limits instead of silently truncating RTK was silently capping git log output in two ways: 1. `--oneline` without `-N` defaulted to 10 entries (now 50) 2. `filter_log_output()` re-truncated even when user explicitly set `-N` 3. Lines >80 chars were truncated, hiding PR numbers and author names This matters for LLM workflows: Claude needs full commit history for rebase, squash, and changelog operations. Silent truncation caused incomplete context and repeated re-runs. Changes: - User-explicit `-N` → no line cap, wider 120-char truncation - `--oneline`/`--pretty` without `-N` → default 50 (was 10) - No flags → unchanged (default 10) - Extract `truncate_line()` helper for clarity Fixes #461 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: handle -n N and --max-count=N forms in git log limit parsing - Extract parse_user_limit() to handle all 4 forms: -20, -n 20, --max-count=20, --max-count 20 - Add token savings test for filter_log_output (≥60%) - Add 5 tests for parse_user_limit edge cases Signed-off-by: Patrick <patrick@rtk-ai.com> Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu> * feat: add structured dotnet support (build/test/restore/format) Integrate PR #172 by @danielmarbach onto develop: - MSBuild binlog parser (binary format, gzip, 7-bit varint) - TRX test result parser (quick-xml) - Format report JSON parser - Subcommand routing: build, test, restore, format + passthrough - Sensitive env var scrubbing (GH_TOKEN, AWS_SECRET_ACCESS_KEY, etc.) - Fallback to text parsing when binlog unavailable - 86-93% token savings on real .NET projects Maintainer fixes applied: - Removed binlog temp path from output (wastes tokens) - Dropped hook file changes (incompatible with develop architecture) - Fixed unused variable warnings 888 tests pass. Signed-off-by: Patrick <patrick@rtk-ai.com> Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu> * feat: add OpenCode plugin support (#300) * feat(opencode): add OpenCode plugin support Add `--opencode` flag to `rtk init` for installing a global OpenCode plugin that rewrites Bash/shell commands through `rtk rewrite`. - New plugin: hooks/opencode-rtk.ts (thin delegator to rtk rewrite) - New init modes: --opencode (OpenCode only), combinable with Claude modes - Plugin install/update/remove lifecycle with idempotent writes - Uninstall cleans up OpenCode plugin alongside Claude Code artifacts - `rtk init --show` reports OpenCode plugin status - Replace unreachable!() with bail!() in match exhaustiveness guard * docs: add OpenCode plugin documentation - README: OpenCode plugin section, install flags, troubleshooting - TROUBLESHOOTING: OpenCode-specific checklist - Update init mode table to reflect Claude Code default --------- Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu> Signed-off-by: Patrick <patrick@rtk.ai> Signed-off-by: Patrick Szymkowiak <patrick.szymkowiak@rtk-ai.app> Signed-off-by: Patrick <patrick@rtk-ai.com> Co-authored-by: Qingyu Li <2310301201@stu.pku.edu.cn> Co-authored-by: Ousama Ben Younes <benyounes.ousama@gmail.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: José Almeida <57680069+zeval@users.noreply.github.com>
310 lines
6.0 KiB
Markdown
310 lines
6.0 KiB
Markdown
# RTK Troubleshooting Guide
|
|
|
|
## Problem: "rtk gain" command not found
|
|
|
|
### Symptom
|
|
```bash
|
|
$ rtk --version
|
|
rtk 1.0.0 # (or similar)
|
|
|
|
$ rtk gain
|
|
rtk: 'gain' is not a rtk command. See 'rtk --help'.
|
|
```
|
|
|
|
### Root Cause
|
|
You installed the **wrong rtk package**. You have **Rust Type Kit** (reachingforthejack/rtk) instead of **Rust Token Killer** (rtk-ai/rtk).
|
|
|
|
### Solution
|
|
|
|
**1. Uninstall the wrong package:**
|
|
```bash
|
|
cargo uninstall rtk
|
|
```
|
|
|
|
**2. Install the correct one (Token Killer):**
|
|
|
|
#### Quick Install (Linux/macOS)
|
|
```bash
|
|
curl -fsSL https://github.com/rtk-ai/rtk/blob/master/install.sh | sh
|
|
```
|
|
|
|
#### Alternative: Manual Installation
|
|
```bash
|
|
cargo install --git https://github.com/rtk-ai/rtk
|
|
```
|
|
|
|
**3. Verify installation:**
|
|
```bash
|
|
rtk --version
|
|
rtk gain # MUST show token savings stats, not error
|
|
```
|
|
|
|
If `rtk gain` now works, installation is correct.
|
|
|
|
---
|
|
|
|
## Problem: Confusion Between Two "rtk" Projects
|
|
|
|
### The Two Projects
|
|
|
|
| Project | Repository | Purpose | Key Command |
|
|
|---------|-----------|---------|-------------|
|
|
| **Rust Token Killer** ✅ | rtk-ai/rtk | LLM token optimizer for Claude Code | `rtk gain` |
|
|
| **Rust Type Kit** ❌ | reachingforthejack/rtk | Rust codebase query and type generator | `rtk query` |
|
|
|
|
### How to Identify Which One You Have
|
|
|
|
```bash
|
|
# Check if "gain" command exists
|
|
rtk gain
|
|
|
|
# Token Killer → Shows token savings stats
|
|
# Type Kit → Error: "gain is not a rtk command"
|
|
```
|
|
|
|
---
|
|
|
|
## Problem: cargo install rtk installs wrong package
|
|
|
|
### Why This Happens
|
|
If **Rust Type Kit** is published to crates.io under the name `rtk`, running `cargo install rtk` will install the wrong package.
|
|
|
|
### Solution
|
|
**NEVER use** `cargo install rtk` without verifying.
|
|
|
|
**Always use explicit repository URLs:**
|
|
|
|
```bash
|
|
# CORRECT - Token Killer
|
|
cargo install --git https://github.com/rtk-ai/rtk
|
|
|
|
# OR install from fork
|
|
git clone https://github.com/rtk-ai/rtk.git
|
|
cd rtk && git checkout feat/all-features
|
|
cargo install --path . --force
|
|
```
|
|
|
|
**After any installation, ALWAYS verify:**
|
|
```bash
|
|
rtk gain # Must work if you want Token Killer
|
|
```
|
|
|
|
---
|
|
|
|
## Problem: RTK not working in Claude Code
|
|
|
|
### Symptom
|
|
Claude Code doesn't seem to be using rtk, outputs are verbose.
|
|
|
|
### Checklist
|
|
|
|
**1. Verify rtk is installed and correct:**
|
|
```bash
|
|
rtk --version
|
|
rtk gain # Must show stats
|
|
```
|
|
|
|
**2. Initialize rtk for Claude Code:**
|
|
```bash
|
|
# Global (all projects)
|
|
rtk init --global
|
|
|
|
# Per-project
|
|
cd /your/project
|
|
rtk init
|
|
```
|
|
|
|
**3. Verify CLAUDE.md file exists:**
|
|
```bash
|
|
# Check global
|
|
cat ~/.claude/CLAUDE.md | grep rtk
|
|
|
|
# Check project
|
|
cat ./CLAUDE.md | grep rtk
|
|
```
|
|
|
|
**4. Install auto-rewrite hook (recommended for automatic RTK usage):**
|
|
|
|
**Option A: Automatic (recommended)**
|
|
```bash
|
|
rtk init -g
|
|
# → Installs hook + RTK.md automatically
|
|
# → Follow printed instructions to add hook to ~/.claude/settings.json
|
|
# → Restart Claude Code
|
|
|
|
# Verify installation
|
|
rtk init --show # Should show "✅ Hook: executable, with guards"
|
|
```
|
|
|
|
**Option B: Manual (fallback)**
|
|
```bash
|
|
# Copy hook to Claude Code hooks directory
|
|
mkdir -p ~/.claude/hooks
|
|
cp .claude/hooks/rtk-rewrite.sh ~/.claude/hooks/
|
|
chmod +x ~/.claude/hooks/rtk-rewrite.sh
|
|
```
|
|
|
|
Then add to `~/.claude/settings.json` (replace `~` with full path):
|
|
```json
|
|
{
|
|
"hooks": {
|
|
"PreToolUse": [
|
|
{
|
|
"matcher": "Bash",
|
|
"hooks": [
|
|
{
|
|
"type": "command",
|
|
"command": "/Users/yourname/.claude/hooks/rtk-rewrite.sh"
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
}
|
|
```
|
|
|
|
**Note**: Use absolute path in `settings.json`, not `~/.claude/...`
|
|
|
|
---
|
|
|
|
## Problem: RTK not working in OpenCode
|
|
|
|
### Symptom
|
|
OpenCode runs commands without rtk, outputs are verbose.
|
|
|
|
### Checklist
|
|
|
|
**1. Verify rtk is installed and correct:**
|
|
```bash
|
|
rtk --version
|
|
rtk gain # Must show stats
|
|
```
|
|
|
|
**2. Install the OpenCode plugin (global only):**
|
|
```bash
|
|
rtk init -g --opencode
|
|
```
|
|
|
|
**3. Verify plugin file exists:**
|
|
```bash
|
|
ls -la ~/.config/opencode/plugins/rtk.ts
|
|
```
|
|
|
|
**4. Restart OpenCode**
|
|
OpenCode must be restarted to load the plugin.
|
|
|
|
**5. Verify status:**
|
|
```bash
|
|
rtk init --show # Should show "OpenCode: plugin installed"
|
|
```
|
|
|
|
---
|
|
|
|
## Problem: "command not found: rtk" after installation
|
|
|
|
### Symptom
|
|
```bash
|
|
$ cargo install --path . --force
|
|
Compiling rtk v0.7.1
|
|
Finished release [optimized] target(s)
|
|
Installing ~/.cargo/bin/rtk
|
|
|
|
$ rtk --version
|
|
zsh: command not found: rtk
|
|
```
|
|
|
|
### Root Cause
|
|
`~/.cargo/bin` is not in your PATH.
|
|
|
|
### Solution
|
|
|
|
**1. Check if cargo bin is in PATH:**
|
|
```bash
|
|
echo $PATH | grep -o '[^:]*\.cargo[^:]*'
|
|
```
|
|
|
|
**2. If not found, add to PATH:**
|
|
|
|
For **bash** (`~/.bashrc`):
|
|
```bash
|
|
export PATH="$HOME/.cargo/bin:$PATH"
|
|
```
|
|
|
|
For **zsh** (`~/.zshrc`):
|
|
```bash
|
|
export PATH="$HOME/.cargo/bin:$PATH"
|
|
```
|
|
|
|
For **fish** (`~/.config/fish/config.fish`):
|
|
```fish
|
|
set -gx PATH $HOME/.cargo/bin $PATH
|
|
```
|
|
|
|
**3. Reload shell config:**
|
|
```bash
|
|
source ~/.bashrc # or ~/.zshrc or restart terminal
|
|
```
|
|
|
|
**4. Verify:**
|
|
```bash
|
|
which rtk
|
|
rtk --version
|
|
rtk gain
|
|
```
|
|
|
|
---
|
|
|
|
## Problem: Compilation errors during installation
|
|
|
|
### Symptom
|
|
```bash
|
|
$ cargo install --path .
|
|
error: failed to compile rtk v0.7.1
|
|
```
|
|
|
|
### Solutions
|
|
|
|
**1. Update Rust toolchain:**
|
|
```bash
|
|
rustup update stable
|
|
rustup default stable
|
|
```
|
|
|
|
**2. Clean and rebuild:**
|
|
```bash
|
|
cargo clean
|
|
cargo build --release
|
|
cargo install --path . --force
|
|
```
|
|
|
|
**3. Check Rust version (minimum required):**
|
|
```bash
|
|
rustc --version # Should be 1.70+ for most features
|
|
```
|
|
|
|
**4. If still fails, report issue:**
|
|
- GitHub: https://github.com/rtk-ai/rtk/issues
|
|
|
|
---
|
|
|
|
## Need More Help?
|
|
|
|
**Report issues:**
|
|
- Fork-specific: https://github.com/rtk-ai/rtk/issues
|
|
- Upstream: https://github.com/rtk-ai/rtk/issues
|
|
|
|
**Run the diagnostic script:**
|
|
```bash
|
|
# From the rtk repository root
|
|
bash scripts/check-installation.sh
|
|
```
|
|
|
|
This script will check:
|
|
- ✅ RTK installed and in PATH
|
|
- ✅ Correct version (Token Killer, not Type Kit)
|
|
- ✅ Available features (pnpm, vitest, next, etc.)
|
|
- ✅ Claude Code integration (CLAUDE.md files)
|
|
- ✅ Auto-rewrite hook status
|
|
|
|
The script provides specific fix commands for any issues found.
|