Skip to content

Hook doesn't rewrite ls when piped or chained with other commands #3442

Closed as duplicate

Description

@romejay

Environment

  • rtk 0.44.2
  • Claude Code PreToolUse hook (rtk hook claude)

Bug
The Claude Code hook correctly rewrites a bare ls <path> to rtk ls <path>, but skips rewriting when the command is piped or chained:

# rewritten fine:
$ ls /some/path
-> rtk ls /some/path

# NOT rewritten (runs raw ls, no filtering/tracking):
$ ls /some/path | head -5
$ echo hi; ls /some/path | head -5

Meanwhile in the same compound command, cat does get rewritten to rtk read even inside a ;-chained command, so the compound-command handling isn't uniformly broken — it looks specific to how ls (possibly piped ls) is matched.

Repro

echo '{"tool_name":"Bash","tool_input":{"command":"ls /tmp 2>&1 | head -5"}}' | rtk hook claude
# -> no output / no rewrite

echo '{"tool_name":"Bash","tool_input":{"command":"ls /tmp"}}' | rtk hook claude
# -> correctly rewrites to `rtk ls /tmp`

Impact
rtk discover flags these as missed savings after the fact, but the hook silently lets the raw, unfiltered command execute in the moment — so the token savings are lost for any piped/chained ls.

Expected
Hook should rewrite ls to rtk ls (or otherwise route through rtk's filter) even when piped or part of a compound ;-chained command, consistent with how cat/read is already handled in that context.

Activity

  1. pszymkowiak commented on Aug 5, 2026

    @pszymkowiak
    Collaborator

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟡 Priority medium
    🎯 Confidence 88%

    Summary

    PreToolUse hook fails to rewrite ls to rtk ls when piped or ;-chained (unlike cat→read), so filtering/tracking silently skips those invocations; fix ls-matching logic in compound-command parsing.

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

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

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

  2. KuSh commented on Sep 13, 2026

    @KuSh
    Collaborator

    Closing as a duplicate of #3722, which covers the same hook behaviour: a command in the producer position of a pipeline is left unrewritten. Please follow up there.

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:clibugpriority:medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions