> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/rtk-ai/rtk/llms.txt
> Use this file to discover all available pages before exploring further.

# rtk read

> Intelligent file reading with language-aware filtering

## Overview

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

## Syntax

```bash theme={null}
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

```bash Example: Basic usage theme={null}
rtk read src/main.rs
# Shows filtered Rust code
```

```bash Example: Aggressive filtering theme={null}
rtk read --level aggressive src/lib.rs
# Shows only function signatures and types
```

```bash Example: With line numbers theme={null}
rtk read -n --max-lines 50 src/config.rs
# First 50 lines with line numbers
```

```bash Example: From stdin theme={null}
cat large_file.py | rtk read - --level minimal
# Filter piped input
```

## 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:

```rust theme={null}
use anyhow::Result;
use std::path::PathBuf;

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

## Exit Codes

* `0` - Success
* `1` - File not found or permission denied

## Related Commands

* `rtk grep` - Search file contents
* `rtk ls` - List directory contents
* `rtk json` - View JSON structure


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.