rtk-ai/rtk

rtk read: add --strip-ansi flag and auto-detect ANSI-heavy files

Open

#972 ouverte le 2 avr. 2026

Voir sur GitHub
 (1 commentaire) (1 réaction) (0 assignés)Rust (2 914 forks)batch import
area:clieffort-mediumenhancementfilter-qualityhelp wantedpriority:high

Métriques du dépôt

Stars
 (48 085 stars)
Métriques de merge PR
 (Merge moyen 11j 1h) (45 PRs mergées en 30 j)

Description

Problem

When Claude Code reads subagent task outputs and MCP tool results via rtk read, files containing ANSI escape sequences pass through completely unfiltered — regardless of --level setting.

Data from real usage (3365 commands analyzed)

Of 665 rtk read calls:

  • 378 reads (57%) had 0% savings — totaling 6.4M wasted tokens
  • The largest category: subagent .output files with terminal progress bars

Example: a single ollama pull task output:

  • 3,439 lines / 600KB raw
  • After ANSI strip + dedup: 776 unique lines / 98KB (−84%)
  • Actual meaningful content: 2 lines (success, writing manifest)

Breakdown of 0% reads by source

Category Count Tokens wasted % of waste
Task outputs (subagents) 48 2.4M 38.1%
MCP tool results 46 1.9M 29.4%
.claude internal (session JSONL) 140 1.5M 23.4%
Code files 114 220K 3.5%

Current behavior

rtk read file.output          → 600KB (no filtering)
rtk read --level minimal      → 600KB (no effect on ANSI)
rtk read --level aggressive   → 600KB (no effect on ANSI)
rtk log file.output           → 102 bytes (too aggressive — only errors/warnings)

Proposed solution

1. --strip-ansi flag for rtk read

rtk read --strip-ansi file.output
# Strips ANSI escape sequences + deduplicates near-identical lines (progress bars)

2. Auto-detection (ideal)

rtk read could detect files with high ANSI density (>30% escape sequences) and automatically strip them, similar to how it detects code files for comment stripping.

3. Integration with filters.toml

Allow filters.toml rules to apply to rtk read based on file path patterns (not just match_command):

[filters.claude-task-outputs]
description = "Strip ANSI from Claude Code subagent outputs"
match_file = "*/tasks/*.output"
strip_ansi = true
deduplicate_lines = true

[filters.claude-tool-results]
description = "Compact MCP tool results"
match_file = "*/tool-results/*"
strip_ansi = true

This relates to #624 (ollama ANSI) and #820/#821 (user TOML filters for rewrite), but is broader — it affects rtk read on static files, not just command output.

Environment

  • rtk 0.34.1
  • macOS Darwin 25.4.0
  • Claude Code 2.x with PreToolUse hook (rtk-rewrite.sh)

Guide contributeur