Skip to main content

What is Tee Recovery?

When RTK filters command output to save tokens, critical debugging information (stack traces, assertion messages) can be lost. If a command fails, LLM agents may re-run the same command multiple times to retrieve the full output. The tee recovery feature solves this by automatically saving raw, unfiltered output to a file when commands fail. Instead of re-executing the command, the agent reads the saved file — saving tokens and time.

How It Works

On command failure (exit code ≠ 0), RTK saves the full unfiltered output to ~/.local/share/rtk/tee/ and prints a one-line hint for the LLM to read.
Example workflow:
The agent can now read ~/.local/share/rtk/tee/1707753600_cargo_test.log directly instead of running cargo test again.

File Naming

Tee files use the format: {epoch}_{sanitized_command}.log
  • Epoch timestamp: Sorts files chronologically
  • Sanitized command: Alphanumeric/underscore/hyphen only, truncated at 40 chars
  • Example: 1707753600_cargo_test.log

Minimum Output Size

Tee skips outputs smaller than 500 bytes — these are short enough to re-run without significant overhead.

Configuration

Default Settings

Create or edit ~/.config/rtk/config.toml:

Tee Modes

mode = "always" can consume significant disk space. Use max_files to limit retention.

Environment Overrides

Environment variables take precedence over config.toml:
Priority: RTK_TEE / RTK_TEE_DIR > config.toml > defaults

File Rotation and Size Limits

Automatic Cleanup

Tee maintains a fixed number of files (default: 20). When this limit is exceeded:
  1. Files are sorted by timestamp (oldest first)
  2. Oldest files are deleted to maintain the limit
  3. Only .log files in the tee directory are affected
Example: With max_files = 20, if you run 25 failing commands, the first 5 tee files are automatically deleted.

Size Truncation

Outputs larger than max_file_size (default: 1MB) are truncated:
This prevents disk exhaustion from extremely verbose commands.

Supported Commands

Tee recovery is available for these RTK commands:
  • cargo build
  • cargo test
  • cargo clippy
  • cargo check
  • cargo install
  • cargo nextest
  • vitest run
  • pytest
  • go test
  • go build
  • go vet
  • lint (eslint/biome)
  • tsc
  • ruff check
  • ruff format
  • pylint
  • mypy
  • golangci-lint run
  • err <command> — errors/warnings only
  • test <command> — failures only

Examples

Example 1: Default Behavior (Failures Only)

Example 2: Always Save Output

Example 3: Disable Tee Temporarily

Example 4: Custom Tee Directory

Example 5: Large Output Truncation

Troubleshooting

Tee Files Not Created

Check tee is enabled:
Verify mode allows saving:
Check environment override:

Disk Space Issues

Reduce retention:
Change directory to larger partition:

Tee Hint Not Visible

Tee hints are printed to stdout after the filtered output. If you’re capturing output to a file, check both:

Implementation Details

Tee failures never affect command output or exit codes. If tee cannot write the file (permissions, disk full, etc.), RTK silently continues without interrupting the user workflow.
From src/tee.rs:
Key behaviors:
  • Checks RTK_TEE=0 first (fastest exit)
  • Skips outputs < 500 bytes (hardcoded MIN_TEE_SIZE)
  • Respects mode (failures/always/never)
  • Returns None on any error (graceful degradation)

See Also