Skip to main content

Overview

Reads files with smart filtering based on language detection. Strips comments, empty lines, and optionally function bodies for aggressive token reduction.

Syntax

Arguments

path
required
File to read, or - for stdin

Options

string
default:"minimal"
Filter level:
  • none - No filtering, raw output
  • minimal - Remove comments and blank lines (40-60% reduction)
  • aggressive - Remove comments, blanks, and function bodies (70-80% reduction)
number
Maximum lines to show. Smart truncation preserves critical code sections.
flag
Show line numbers in output

Language Detection

Automatic detection by file extension:
  • Rust (.rs) - Comments, attributes, test modules
  • Python (.py) - Docstrings, comments, type hints
  • JavaScript/TypeScript (.js, .ts, .tsx, .jsx) - JSDoc, comments, imports
  • Java (.java) - Javadoc, comments, annotations
  • Go (.go) - Comments, build tags
  • C/C++ (.c, .cpp, .h, .hpp) - Comments, preprocessor
  • Unknown - Generic text filtering

Filter Levels

Minimal (Default)

  • Removes single-line comments (//, #)
  • Removes multi-line comments (/* */, ''', """)
  • Removes empty lines
  • Preserves all code and type signatures
  • 40-60% token reduction

Aggressive

  • Everything from minimal
  • Removes function bodies (keeps signatures)
  • Removes test code blocks
  • Preserves interfaces, types, constants
  • 70-80% token reduction
  • Use when you only need API signatures

Token Savings

60% reduction (minimal) - preserves code structure 80% reduction (aggressive) - API overview only

Output Format

With --line-numbers:
Without line numbers:

Exit Codes

  • 0 - Success
  • 1 - File not found or permission denied
  • rtk grep - Search file contents
  • rtk ls - List directory contents
  • rtk json - View JSON structure