rtk-ai/rtk

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

Open

#530 ouverte le 12 mars 2026

Voir sur GitHub
 (5 commentaires) (0 réactions) (0 assignés)Rust (2 914 forks)batch import
area:clieffort-smallenhancementgood first issuepriority:highresolved-pending-close

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

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

Guide contributeur