#4332·rtk

`kubectl --no-headers` is compacted even though it requests parseable output, while every other output-format flag is passed through

Author: vinson-hkgiCreated Sep 28, 2026Updated Sep 28, 2026
Labelsbuggood first issuepriority:higharea:cli

Problem

rtk's kubectl filter passes output through untouched when an explicit output-format flag is present (-o json, -o name, -o wide, -o custom-columns=, -o jsonpath). It does not recognise --no-headers as such a flag, so kubectl get pods --no-headers falls into the compacting path and the raw rows are replaced by a one-line summary.

--no-headers is an explicit request for raw, parseable rows — the same class of request as -o name. The inconsistency is the bug: --no-headers -o wide is passed through, bare --no-headers is not.

Measured

rtk 0.50.0, staging cluster with 216 pods. Each shape run through plain kubectl and through rtk kubectl, output captured once and counted with wc -l:

Command plain rtk
kubectl get pods -A -o json 93044 93044 preserved
kubectl get pods -A -o name 216 216 preserved
kubectl get pods -A -o wide 217 217 preserved
kubectl get pods -A -o custom-columns=… 217 217 preserved
kubectl get pods -A --no-headers -o wide 216 216 preserved
kubectl get pods -A --no-headers 216 1 compacted

The compacted output is:

216 pods: 149, 1341 restarts

Impact

The failure is silent — the command exits 0 and looks successful. Any filter consuming the rows matches nothing and reports zero findings:

bash
# Author intends: "list pods whose status is Error"
kubectl get pods -A --no-headers | awk '$4 ~ /Error/'
# under rtk: prints nothing — awk sees one non-matching line

Observed consequences in a Kubernetes-platform repo:

  • A pod-health scan reported "0 unhealthy pods, 0 completed" on a 216-pod cluster because every awk filter silently matched nothing. It read as a clean all-clear.
  • A ReplicaSet cleanup of the shape kubectl get rs -n apisix --no-headers | awk '$2==0' | xargs -r kubectl delete rs silently deleted nothing.
  • A SOP assertion of the shape kubectl get pods -A --no-headers | wc -l returns 1, so a data-sanity diff against a real count is meaningless.

Blast radius is limited: the hook rewrites only the top-level Bash tool call, so shell scripts are unaffected (their internal kubectl calls run unwritten). The exposure is agent-typed inline pipelines and any pipeline documented for an agent to type.

Suggested fix

Treat --no-headers (and --no-headers=true) as an output-format flag, i.e. bypass the filter exactly as the -o family does. It is a small, well-scoped addition to the same predicate that already special-cases -o.

Related precedent in this repo

Same family — an output-shaping flag or an unhandled form should bypass filtering rather than silently transform results:

  • #3410 — find rewrite is unconditional, so find … -delete silently becomes a no-op
  • #4067 — gh pr view --json <field> fails silently
  • #927 — kubectl rewrite misses --context, exec, and variable-assignment forms
  • #3963 — generic TOML filter truncates silently

Note for the fix: --no-headers is not universally lossy. helm list -A --no-headers is passed through (28 rows → 29, raw rows intact), so scoping the bypass to the kubectl filter is preferable to a global rule.