Overview
RTK provides token-optimized alternatives to common file operations:ls, cat, grep/rg, and find. These commands achieve 70-80% token savings by filtering noise, grouping results, and intelligent truncation.
rtk ls
Compact directory listing with tree format and aggregate counts.Usage
Examples
Features
- Tree format: Hierarchical directory structure
- Aggregate counts: Shows file counts for directories
- Noise filtering: Automatically excludes
.git,node_modules,target, etc. - Smart truncation: Shows most relevant files first
Implementation Details
Fromsrc/ls.rs:
- Filters noise directories (30+ common patterns)
- Groups files by directory
- Shows permissions, size, and modification time only when relevant
- Preserves exit codes for error handling
rtk read
Smart file reading with language-aware filtering.Usage
Options
Filter level:
none, minimal, aggressivenone: No filtering (raw file)minimal: Remove comments and blank linesaggressive: Strip function bodies, keep signatures only
Maximum lines to output (smart truncation)
Show line numbers
Examples
Supported Languages
Fromsrc/filter.rs, RTK detects and filters:
- Rust:
.rs- Strip comments, docstrings, attributes - Python:
.py- Remove docstrings, comments, decorators - JavaScript/TypeScript:
.js,.ts,.jsx,.tsx- Strip comments, JSDoc - Go:
.go- Remove comments, build tags - C/C++:
.c,.cpp,.h- Strip comments, preprocessor directives - Java:
.java- Remove comments, annotations - JSON:
.json- Preserve structure, optional value stripping
Token Savings
- Minimal (default)
- Aggressive
70% savings - Removes comments, blank lines, docstrings
rtk grep
Grouped search results with context and smart truncation.Usage
Options
Maximum line length to display
Maximum results to show
Show only surrounding context, not full lines
File type filter (e.g.,
rust, js, py)Examples
Features
- Grouped by file: Results organized by file path
- Context highlighting: Shows surrounding context for matches
- Smart truncation: Long lines trimmed with ellipsis
- Regex support: Full regex pattern matching (uses
rgunder the hood)
Implementation Details
Fromsrc/grep_cmd.rs:
- Uses
ripgrep(rg) for speed, falls back togrep - Converts BRE alternation
\|to PCRE|for compatibility - Groups results by file with counts
- Strips ANSI color codes for token optimization
rtk find
Compact file finding with gitignore awareness.Usage
Options
Maximum results to show
Maximum directory depth
File type:
f (file), d (directory)Case-insensitive matching
Examples
Native find Compatibility
RTK supports native find syntax:-name <pattern>: File name pattern-type <f|d>: File or directory-maxdepth <n>: Maximum depth-iname <pattern>: Case-insensitive name
find directly):
- Compound predicates:
-not,-or,-and - Actions:
-exec,-delete - Advanced filters:
-regex,-perm,-size,-mtime
Features
- Gitignore awareness: Automatically respects
.gitignore - Smart grouping: Groups results by directory
- Glob patterns: Supports
*and?wildcards - Performance: Uses
ignorecrate for fast traversal
Token Savings Summary
| Command | Standard Tokens | RTK Tokens | Savings |
|---|---|---|---|
ls -la | 800 | 150 | -81% |
cat file.rs | 4,000 | 1,200 | -70% |
grep "TODO" . | 2,000 | 400 | -80% |
find . -name "*.rs" | 1,500 | 300 | -80% |
Next Steps
Git Commands
Explore git operation optimizations
Testing
Learn about test output filtering
