rtk-ai/rtk

feat(rewrite): strip trailing stderr redirects before pattern matching

Open

#530 aperta il 12 mar 2026

Vedi su GitHub
 (5 commenti) (0 reazioni) (0 assegnatari)Rust (2914 fork)batch import
area:clieffort-smallenhancementgood first issuepriority:highresolved-pending-close

Metriche repository

Star
 (48.085 star)
Metriche merge PR
 (Merge medio 11g 1h) (45 PR mergiate in 30 g)

Descrizione

Description

rtk rewrite doesn't match commands that have trailing 2>&1 or 2>/dev/null, because the redirect suffix is part of the string passed to pattern matching.

Reproduction

# These match:
rtk rewrite "git status"        # -> rtk git status ✓
rtk rewrite "find . -name '*.ts'"  # -> rtk find . -name '*.ts' ✓

# These don't match (exit 1):
rtk rewrite "git status 2>&1"              # -> no match ✗
rtk rewrite "find . -name '*.ts' 2>&1"     # -> no match ✗
rtk rewrite "ls -la 2>/dev/null"           # -> no match ✗

Impact

Claude Code appends 2>&1 to the vast majority of Bash commands. This means the hook-based rewrite misses most commands that would otherwise match.

From rtk discover on my project: ~975K tokens missed, many from commands that would match if not for the 2>&1 suffix.

Suggested fix

In rtk rewrite, strip trailing 2>&1 / 2>/dev/null before pattern matching, then re-append to the rewritten output.

Workaround: I've added pre-processing to my hook script to strip these before calling rtk rewrite.

Environment

  • rtk 0.28.2
  • macOS Darwin 25.3.0

Guida contributor