Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ flate2 = "1.0"
quick-xml = "0.37"
which = "8"
automod = "1"
encoding_rs = "0.8"

[target.'cfg(unix)'.dependencies]
libc = "0.2"
Expand Down
78 changes: 75 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
<a href="README_zh.md">中文</a> &bull;
<a href="README_ja.md">日本語</a> &bull;
<a href="README_ko.md">한국어</a> &bull;
<a href="README_es.md">Espanol</a> &bull;
<a href="README_pt.md">Português</a>
<a href="README_es.md">Espanol</a>
</p>

---
Expand Down Expand Up @@ -119,6 +118,36 @@ git status # Automatically rewritten to rtk git status

Hook-based agents rewrite Bash commands (e.g., `git status` -> `rtk git status`) before execution. Plugin-based agents, including Hermes, use their plugin API to rewrite commands before execution. The agent receives compact output without needing to call `rtk` explicitly.

## Grep (agent-friendly)

```bash
rtk grep "Foo" . --files-only
rtk grep "Foo" . --count-by-file
rtk grep "Foo" . --top-files 10
rtk grep "Foo" . --agent-safe
rtk grep "Foo" . --agent-safe --max-per-file 30
rtk grep "Foo" . --json
rtk grep "Foo" . --agent-safe --json
rtk grep "Foo" . --all --full-lines

# Opt-in preset for agents (grep only in this slice):
RTK_AGENT_SAFE=1 rtk grep "Foo" .
```

Notes:
- `--files-only`: locator mode (paths only)
- `--count-by-file`: counts per file
- `--top-files N`: ranked file summary (top N files)
- `--agent-safe`: caps match spam + adds summary/hints (flags override env/config)
- `--json`: machine-readable JSON only (no human text)
- `--all`: disables match caps
- `--full-lines`: disables line clipping

PowerShell:
```powershell
$env:RTK_AGENT_SAFE="1"; rtk grep "Foo" src
```

**Important:** the hook only runs on Bash tool calls. Claude Code built-in tools like `Read`, `Grep`, and `Glob` do not pass through the Bash hook, so they are not auto-rewritten. To get RTK's compact output for those workflows, use shell commands (`cat`/`head`/`tail`, `rg`/`grep`, `find`) or call `rtk read`, `rtk grep`, or `rtk find` directly.

## How It Works
Expand Down Expand Up @@ -146,9 +175,15 @@ Four strategies applied per command type:
rtk ls . # Token-optimized directory tree
rtk read file.rs # Smart file reading
rtk read file.rs -l aggressive # Signatures only (strips bodies)
rtk read file.rs --lines 430:540 # Inclusive line range (1-based)
rtk smart file.rs # 2-line heuristic code summary
rtk find "*.rs" . # Compact find results
rtk grep "pattern" . # Grouped search results
rtk grep "pattern" . # Grouped search results (legacy defaults)
rtk grep "Foo" . --files-only # Unique matching file paths
rtk grep "Foo" . --count-by-file # Counts per file
rtk grep "Foo" . --agent-safe # Token-safe preset (caps + clipping + summary)
rtk grep "Foo" . --agent-safe --max-per-file 30
rtk grep "Foo" . --all --full-lines # Legacy full output (uncapped + unclipped)
rtk diff file1 file2 # Condensed diff
```

Expand Down Expand Up @@ -208,6 +243,26 @@ rtk bundle install # Ruby gems (strip Using lines)
rtk prisma generate # Schema generation (no ASCII art)
```

### C++ / CMake / MSBuild
```bash
rtk cmake --build <dir> # Build errors only (-85%)
rtk cmake -B <dir> # Configure: errors + key settings only (-70%)
rtk make [-j<N>] # Make errors only (-80%)
rtk ninja [-C <dir>] # Ninja build errors only (-80%)
rtk ctest [--test-dir dir] # Failed tests only (-85%)
rtk msbuild [sln] [flags] # MSVC/LNK errors only, no project noise (-80%)
rtk codegraph index <path> # Summary only, no per-file progress (-90%)
```

### PowerShell
```powershell
Select-String -Path f -Pattern p # auto-rewritten -> rtk grep
Get-Content <file> # auto-rewritten -> rtk read
GC <file> # auto-rewritten -> rtk read
rtk read <file> --lines 430:540 # Prefer over Get-Content line-range loops
Remove-Item <path> -Force # -> ok <basename>
```

### AWS
```bash
rtk aws sts get-caller-identity # One-line identity
Expand Down Expand Up @@ -237,6 +292,7 @@ rtk json config.json # Structure without values
rtk deps # Dependencies summary
rtk env -f AWS # Filtered env vars
rtk log app.log # Deduplicated logs
rtk log ERRORLOG.TXT --events 20 # Tail key error/assert events (deduped)
rtk curl <url> # Truncate + save full output
rtk wget <url> # Download, strip progress bars
rtk summary <long command> # Heuristic summary
Expand Down Expand Up @@ -313,6 +369,22 @@ rtk init --show # Verify installation

After install, **restart Claude Code**.

### Commands Rewritten

Selected entries (full set covered by the hook):

| Raw Command | Rewritten To |
|---|---|
| `cmake --build / cmake -B` | `rtk cmake ...` |
| `ctest` | `rtk ctest` |
| `make` (non-lifecycle targets) | `rtk make` |
| `ninja` | `rtk ninja` |
| `msbuild` | `rtk msbuild` |
| `codegraph index/update/search/...` | `rtk codegraph ...` |
| `Select-String -Path f -Pattern p` | `rtk grep p f` |
| `Get-Content / GC` | `rtk read` |
| `Remove-Item` | `rtk remove-item` |

## Windows

RTK works on Windows with some limitations. The auto-rewrite hook (`rtk-rewrite.sh`) requires a Unix shell, so on native Windows RTK falls back to **CLAUDE.md injection mode** — your AI assistant receives RTK instructions but commands are not rewritten automatically.
Expand Down
Loading