Skip to content

rtk hook check disagrees with rtk hook claude on commands containing a file redirect #3936

Closed

Description

@jensechterling

Summary

rtk hook check reports a rewrite for commands containing a file redirect (>, >>, 2>, <), but rtk hook claude — the real hook — proposes no rewrite for those same commands. The dry-run and the thing it is a dry run of disagree.

The pass-through behaviour itself looks deliberate and fine (redirects and pipes are both left alone). The bug is that hook check doesn't model it, so the one tool available for "will this command be rewritten?" gives the wrong answer for a common command shape.

Reproduction

$ mkdir /tmp/hcrepro && cd /tmp/hcrepro && printf 'alpha\nbeta\n' > f.txt

$ rtk hook check "grep -rn alpha f.txt > out.txt"
rtk grep -rn alpha f.txt > out.txt          # claims a rewrite, exit 0

$ echo '{"tool_name":"Bash","tool_input":{"command":"grep -rn alpha f.txt > out.txt"}}' | rtk hook claude
                                            # (empty — no rewrite proposed), exit 0

$ echo '{"tool_name":"Bash","tool_input":{"command":"grep -rn alpha f.txt"}}' | rtk hook claude
{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecisionReason":"RTK auto-rewrite","updatedInput":{"command":"rtk grep -rn alpha f.txt"}}}

Scope

Tested 12 command shapes against both entry points. The disagreement is exactly the file-redirect cases; pipes are handled consistently by both.

Command shape rtk hook check rtk hook claude
grep -rn X f rewrites rewrites agree
grep -rn X f | head -3 no rewrite no rewrite agree
git log --oneline | wc -l no rewrite no rewrite agree
grep -rn X f 2>&1 rewrites rewrites agree
grep -rn X f && echo done rewrites rewrites agree
grep -rn X f > out.txt rewrites no rewrite disagree
grep -rn X f >> out.txt rewrites no rewrite disagree
grep -rn X f 2> err.txt rewrites no rewrite disagree
grep -rn X f < in.txt rewrites no rewrite disagree
git log --oneline > out.txt rewrites no rewrite disagree
python3 -m pytest tests -q > out.txt rewrites no rewrite disagree

2>&1 is a file-descriptor duplication rather than a file redirect and is correctly rewritten by both, which suggests the real hook's rule is specifically "contains a redirect to/from a file".

Why it matters

rtk hook check is the only way to answer "will RTK rewrite this?" without running the command, and it is the natural tool to reach for when deciding whether an exclude_commands entry has taken effect. We rely on it in a project rules file for exactly that. Getting a confident wrong answer from the verification tool is worse than not having it: a user who checks rtk hook check "pytest x > log.txt", sees a rewrite, and concludes their exclusion is missing will add an entry that does nothing.

Suggested fix

Route hook check through the same predicate the hook uses to decide whether to emit updatedInput, so the two cannot drift. If the pass-through is intentional, having hook check print something explicit would be ideal, e.g.:

No rewrite for: grep -rn alpha f.txt > out.txt  (contains a file redirect)

Minor, related

hook check reports "no rewrite" on stderr with exit 1, and the rewrite on stdout with exit 0. That is defensible, but it is undocumented in --help and easy to get wrong: a script capturing stdout only sees an empty string and can misread it as "rewrites". Worth a line in the help text.

Environment

  • rtk 0.48.0 (Homebrew)
  • macOS 26.4.1, arm64

Activity

  1. rtk-wshm-sync-bot commented on Sep 8, 2026

    @rtk-wshm-sync-bot

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟡 Priority medium
    🎯 Confidence 94%

    Summary

    rtk hook check fails to model the file-redirect pass-through rule that rtk hook claude applies, so the two disagree on whether a command like grep ... > out.txt will be rewritten; should route through the same predicate and clarify no-rewrite output/help text.

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

    📁 Relevant files
    • src/hook/check.rs
    • src/hook/claude.rs

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

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