Skip to main content

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

rtk ls [path] [flags]

Examples

$ ls -la
drwxr-xr-x  15 user  staff    480 Jan 23 10:00 .
drwxr-xr-x   5 user  staff    160 Jan 23 09:00 ..
-rw-r--r--   1 user  staff   1234 Jan 23 10:00 Cargo.toml
-rw-r--r--   1 user  staff   5678 Jan 23 10:00 README.md
drwxr-xr-x   8 user  staff    256 Jan 23 10:00 src
...
# 45 lines, ~800 tokens

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

From src/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

rtk read <file> [options]

Options

-l, --level
string
default:"minimal"
Filter level: none, minimal, aggressive
  • none: No filtering (raw file)
  • minimal: Remove comments and blank lines
  • aggressive: Strip function bodies, keep signatures only
-m, --max-lines
number
Maximum lines to output (smart truncation)
-n, --line-numbers
flag
Show line numbers

Examples

$ rtk read src/main.rs
# Removes comments, blank lines (70% savings)

Supported Languages

From src/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

70% savings - Removes comments, blank lines, docstrings

rtk grep

Grouped search results with context and smart truncation.

Usage

rtk grep <pattern> <path> [options]

Options

-m, --max-line-len
number
default:"120"
Maximum line length to display
-n, --max-results
number
default:"50"
Maximum results to show
-c, --context-only
flag
Show only surrounding context, not full lines
-t, --type
string
File type filter (e.g., rust, js, py)

Examples

$ grep -rn "TODO" .
src/main.rs:42:    // TODO: implement feature
src/lib.rs:18:    // TODO: add tests
tests/integration.rs:91:    // TODO: fix edge case
...
# 50+ lines, ~2000 tokens

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 rg under the hood)

Implementation Details

From src/grep_cmd.rs:
  • Uses ripgrep (rg) for speed, falls back to grep
  • 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

rtk find <pattern> [path] [options]

Options

-m, --max-results
number
default:"50"
Maximum results to show
-d, --max-depth
number
Maximum directory depth
-t, --type
string
default:"f"
File type: f (file), d (directory)
-i, --case-insensitive
flag
Case-insensitive matching

Examples

$ find . -name "*.rs"
./src/main.rs
./src/lib.rs
./src/git.rs
./src/grep_cmd.rs
...
# 50+ lines

Native find Compatibility

RTK supports native find syntax:
rtk find . -name "*.rs" -type f -maxdepth 3
Supported flags:
  • -name <pattern>: File name pattern
  • -type <f|d>: File or directory
  • -maxdepth <n>: Maximum depth
  • -iname <pattern>: Case-insensitive name
Unsupported flags (use 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 ignore crate for fast traversal

Token Savings Summary

CommandStandard TokensRTK TokensSavings
ls -la800150-81%
cat file.rs4,0001,200-70%
grep "TODO" .2,000400-80%
find . -name "*.rs"1,500300-80%

Next Steps

Git Commands

Explore git operation optimizations

Testing

Learn about test output filtering