rtk compacts machine-bound git output (--porcelain / --name-only / piped), silently corrupting consumers
Summary
The Claude Code rewrite hook turns git X into rtk git X and rtk git
compacts the output. That's the right behavior when the model reads
the output. But rtk also rewrites git commands whose output is bound for
a program — piped into another command, or carrying an explicit
machine-readable format flag — and there its compacted, non-byte-exact
output silently corrupts the consumer.
This is not a request to weaken compaction. rtk already draws a model-vs-machine line (see below); it's just drawing it in the wrong place for a few cases.
Evidence that rtk already distinguishes machine output
git rev-parse is treated as machine data and passed through unchanged:
$ rtk rewrite 'git rev-parse HEAD' # exit 1 → pass through
$ rtk rewrite 'git rev-parse HEAD | head -1' # exit 1 → pass throughSo "don't rewrite this git command" is already a first-class outcome in the registry. The bug is that the same courtesy isn't extended to other machine-output cases.
The mis-drawn cases
rtk rewrites (and thus compacts) commands that explicitly request parseable output or feed a parser:
$ rtk rewrite 'git status --porcelain | wc -l' → rtk git status --porcelain | wc -l
$ rtk rewrite 'git log --format=%H | sort' → rtk git log --format=%H | sort
$ rtk rewrite 'git diff | wc -l' → rtk git diff | wc -l--porcelain is literally git's stable machine-readable contract;
--format=%H / --name-only / -z are the same intent. Compacting
them overrides an explicit "this output is for a program" signal.
Concrete corruption — rtk appends a --- Changes --- footer to diff
output, so a file-list count is wrong:
$ rtk proxy git diff --name-only HEAD~1..HEAD | grep -c . # raw git
17
$ rtk git diff --name-only HEAD~1..HEAD | grep -c . # via rtk
20
$ diff <(rtk proxy git diff --name-only HEAD~1..HEAD) \
<(rtk git diff --name-only HEAD~1..HEAD)
17a18,20
>
> --- Changes ---
>Secondary, intermittent: the first rtk git diff ... in a fresh
shell sometimes returns empty output (looks like a cold-cache miss);
repeated identical calls then return the full (footer-decorated) result.
... | wc -l → 1 when the truth is 17.
All of these fail silently — a plausible wrong number, no error. Anything scripted that counts/parses git output gets bad data.
Environment
- rtk 0.36.0, git 2.53.0, macOS (Darwin 25.5.0)
- Hook:
rtk-rewrite.sh→rtk rewriteprependsrtkto git commands
Proposed fix
Extend rtk's existing pass-through logic (the rev-parse exit-1 path)
to decline rewriting when the command signals a machine consumer:
- an explicit machine-format flag is present —
--porcelain,--format=/--pretty=format:,--name-only,--name-status,-z,--no-color; or - the git command's stdout is piped into another command or redirected
into a file (
rtk rewritealready has the full command string, so a trailing| <cmd>/> fileafter the git call is detectable).
In those cases, emit the command as raw git. Keep compaction fully on
for the common, high-token, model-facing case (a bare git diff /
git status / git log whose output the model reads directly). Token
savings are essentially unchanged; correctness for programmatic
consumers is restored.
Separately, the intermittent empty-output-on-first-call should be fixed regardless — empty is never a valid compaction of a non-empty diff.
Workaround (current)
rtk proxy git ... to bypass the wrapper, or append | cat.
Source: rtk-ai/rtk