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

rtk read [OPTIONS] <FILE>
cat <file> | rtk read -  # Read from stdin

Arguments

FILE
path
required
File to read, or - for stdin

Options

-l, --level
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)
-m, --max-lines
number
Maximum lines to show. Smart truncation preserves critical code sections.
-n, --line-numbers
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
rtk read src/main.rs
# Shows filtered Rust code

Output Format

With --line-numbers:
  1 │ use anyhow::Result;
  2 │ use std::path::PathBuf;
  3 │ 
  4 │ pub fn run(args: &[String]) -> Result<()> {
Without line numbers:
use anyhow::Result;
use std::path::PathBuf;

pub fn run(args: &[String]) -> Result<()> {

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