rtk-ai/rtk
View on GitHubbug(rewrite): hook rewrites left-hand side of piped commands, breaking downstream filters
Open
#1560 opened on Apr 27, 2026
P1-criticalbugeffort-smallfilter-qualitygood first issue
Description
Summary
rtk rewrite (and rtk hook claude) rewrites piped commands like ps aux | grep foo | grep -v grep into rtk ps aux | grep foo | grep -v grep. Since rtk ps aux compresses/reformats output, the downstream grep no longer matches — the pipe silently returns empty results.
Reproduction
$ rtk rewrite 'ps aux | grep python | grep -v grep'
rtk ps aux | grep python | grep -v grep # exit 0 — rewrite applied
$ ps aux | grep python | grep -v grep # returns matching processes
$ rtk ps aux | grep python | grep -v grep # returns nothing
Also confirmed via hook:
$ echo '{"tool_input":{"command":"ps aux | grep python | grep -v grep"}}' | rtk hook claude
{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecisionReason":"RTK auto-rewrite","updatedInput":{"command":"rtk ps aux | grep python | grep -v grep"}}}
Expected behavior
rtk rewrite should detect pipes in the command string and either:
- Skip rewriting entirely for piped commands, or
- Only rewrite if downstream stages are rtk-compatible
Workaround
Wrapper script around rtk hook claude that skips piped commands:
#!/usr/bin/env bash
INPUT=$(cat)
CMD=$(echo "$INPUT" | jq -r '.tool_input.command // empty' 2>/dev/null)
case "$CMD" in
*"|"*) exit 0 ;;
esac
echo "$INPUT" | rtk hook claude
Wire in settings.json:
"command": "~/.claude/hooks/rtk-hook-wrapper.sh"
Environment
- rtk 0.37.2 (also reproduced on 0.34.2)
- Hook:
rtk hook claude(v0.37.2 built-in) - OS: Linux x86_64