Skip to content

bug: rtk-rewrite.sh doesn't translate POSIX find arguments to rtk find syntax #170

@aros3rg3d

Description

@aros3rg3d

Description

The rtk-rewrite.sh hook blindly prefixes rtk to find commands without translating POSIX find syntax to the rtk find CLI format. This causes errors for common find invocations used by Claude Code.

Steps to reproduce

Original command executed by Claude Code:

find /root/git/my-project/tests -name "*.py" -type f | head -20

The hook rewrites it to:

rtk find /root/git/my-project/tests -name "*.py" -type f | head -20

Error

error: unexpected argument '-n' found

tip: to pass '-n' as a value, use '-- -n'

Usage: rtk find [OPTIONS] <PATTERN> [PATH]

For more information, try '--help'.

Root cause

In rtk-rewrite.sh, the find rewrite rule is a simple sed substitution:

elif echo "$MATCH_CMD" | grep -qE '^find[[:space:]]+'; then
  REWRITTEN="${ENV_PREFIX}$(echo "$CMD_BODY" | sed 's/^find /rtk find /')"

This just prepends rtk without any argument translation. But rtk find (defined in main.rs) expects a completely different syntax than POSIX find:

  POSIX find rtk find
Pattern -name "*.py" First positional arg: "*.py"
Path First positional arg: /path Second positional arg: /path
Type filter -type f -t f

So rtk find /path -name "*.py" -type f fails because Clap tries to parse -name as a flag, interprets -n as an unknown short option, and errors out.

Expected behavior

Either:

  1. Translate POSIX arguments — parse -name, -type from the original command and remap them to rtk find <PATTERN> [PATH] [-t type] format, or
  2. Skip rewriting when the find command uses POSIX-style arguments (-name, -type, -maxdepth, etc.) that rtk find doesn't understand

Environment

  • rtk version: 0.20.0
  • Hook: rtk-rewrite.sh (Claude Code PreToolUse:Bash)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions