#4091·rtk

rtk wc does not read stdin — silent false zero on redirect and pipe

Author: BankCurfewCreated Sep 17, 2026Updated Sep 17, 2026
Labelsbuggood first issuepriority:higharea:cli

Description

rtk wc does not read stdin at all — neither via redirect (<) nor pipe (|). When no file operand is given, it prints 0 and exits 0, making it indistinguishable from a real empty file.

This is the same class as #4084 (rtk curl drops stdin body), but worse: wc is a counting instrument, and 0 is a fully plausible answer to nearly every question it gets pointed at. A false zero from wc reads as "nothing there", not as an error.

Reproduction

Each command must be alone and first in its block (see "position-dependent" note below):

bash
# Setup
printf 'a\nb\nc\n' > /tmp/wc-test.txt

# BUG: redirect stdin — should be 3, returns 0
rtk wc -l < /tmp/wc-test.txt
# Output: 0 (rc=0)

# BUG: pipe stdin — should be 3, returns 0
printf 'a\nb\nc\n' | rtk wc -l
# Output: 0 (rc=0)

# CORRECT: file argument
rtk wc -l /tmp/wc-test.txt
# Output: 3 (rc=0)

# CORRECT: native wc
/usr/bin/wc -l < /tmp/wc-test.txt
# Output: 3 (rc=0)

Position-dependent trigger (why it looks intermittent)

rtk rewrite rewrites only the first matched command in a block. So:

  • wc -l < f alone → rewritten → 0 (wrong)
  • wc -l f; wc -l < f → first wc absorbs the rewrite → second runs native → 75 (correct)

This means a "characterization re-run" that adds the suspect command to an existing block will defeat reproduction. The command must be isolated.

Environment

  • rtk 0.38.0
  • Linux 6.6.87.2 (WSL2), x86-64

Expected behavior

Either:

  1. rtk wc should forward stdin to native wc when no file arguments are given, OR
  2. rtk wc should exit non-zero when stdin would be needed but isn't handled

Never: print 0 with rc=0.

Workaround

We guard this in our hook (rtk-rewrite.sh) by matching on $REWRITTEN to skip rewriting standalone wc commands while preserving pipeline upstream savings (e.g., rtk ls | wc -l still works because only ls is rewritten).