Skip to content

PreToolUse rewrite misses find ... | wc -l and never maps standalone head -n <file> to rtk read #4072

Closed

Description

@krzysztofAbramQuality

Environment

rtk 0.49.0 (also reproduced the head -n issue on 0.43.0 before upgrading)

Bug 1: find ... | wc -l is not rewritten

$ rtk hook check 'find . | wc -l'
No rewrite for: find . | wc -l

Expected: rtk find . | wc -l (or at least the find part rewritten), matching
the behavior of every other pipe target I tested:

$ rtk hook check 'find . | head -20'
rtk find . | head -20
$ rtk hook check 'find . | grep foo'
find . | rtk grep foo
$ rtk hook check 'find . | cat'
rtk find . | cat

find | head, find | grep, and find | cat all rewrite correctly (the
find | head case was fixed between 0.43.0 and 0.49.0). Only wc as the
pipe target breaks it — for both find . | wc -l and
find . -type f -name "*.php" | wc -l.

Bug 2: standalone head -n <file> is never rewritten to rtk read

$ rtk hook check 'head -n 50 foo.txt'
No rewrite for: head -n 50 foo.txt

rtk read (per rtk --help) is described as handling exactly this case, and
cat file.txt does correctly rewrite:

$ rtk hook check 'cat file.txt'
rtk read file.txt

Impact

Found via rtk discover on a real project: it flagged head -n (55
occurrences, ~19.8K tokens) and find . (56 occurrences) as "missed savings
— existing" capability, meaning real Claude Code sessions were silently
bypassing the PreToolUse hook for these exact patterns despite the hook
being active and correctly configured. Adoption measured by discover was
only 2.2% of Bash commands over 30 days, and these two blind spots (plus
the already-fixed find | head) account for a meaningful share of that gap.

Expected

Both patterns should rewrite the same way their non-piped / cat-based
equivalents already do.

Activity

  1. added
    bug
    good first issue
    on Sep 15, 2026
  2. rtk-wshm-sync-bot commented on Sep 15, 2026

    @rtk-wshm-sync-bot

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟡 Priority medium
    🎯 Confidence 90%

    Summary

    PreToolUse hook fails to rewrite find ... | wc -l and standalone head -n <file> (should map to rtk read); fix rewrite rule coverage for these two patterns.

    This looks like a simple fix that could be auto-resolved. Repo maintainers can use /wshm fix to attempt it.

    📁 Relevant files
    • src/rewrite.rs
    • src/hook.rs

    Triaged automatically by wshm · This is an automated analysis, not a human review.

  3. KuSh commented on Sep 27, 2026

    @KuSh
    Collaborator

    Both halves are settled on the current release, so closing. head -n 50 foo.txt is rewritten to rtk read foo.txt --head-lines 50 since #3941, which shipped in v0.50.0 (also head -50 file and plain head file). find ... | wc -l is left alone on purpose: rtk find prints a condensed listing whose line count can differ from native find's (filtered entries, hint lines), so rewriting the producer would change what wc -l reports, and the same holds for any pipeline that ends in wc. That is why | head, | cat and | grep rewrite (they only trim or filter what they are shown) and | wc does not; a test pins that behaviour. If you see a wc pipeline where the rewritten count would be correct and worth having, open a new issue for that shape.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:clibuggood first issuepriority:medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions