rtk-ai/rtk
在 GitHub 查看feat(rewrite): strip trailing stderr redirects before pattern matching
Open
#530 创建于 2026年3月12日
effort-smallenhancementgood first issueresolved-pending-close
描述
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