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
string
default:"minimal"
Filter level:
none, minimal, aggressivenone: No filtering (raw file)minimal: Remove comments and blank linesaggressive: Strip function bodies, keep signatures only
number
Maximum lines to output (smart truncation)
flag
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
number
default:"120"
Maximum line length to display
number
default:"50"
Maximum results to show
flag
Show only surrounding context, not full lines
string
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
number
default:"50"
Maximum results to show
number
Maximum directory depth
string
default:"f"
File type:
f (file), d (directory)flag
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
Next Steps
Git Commands
Explore git operation optimizations
Testing
Learn about test output filtering
