Skip to content

Hook silently skips rewriting piped commands and 'gh pr ... --json ...' #3696

Closed as duplicate

Description

@sguness

Summary

rtk hook claude (the Claude Code PreToolUse:Bash auto-rewrite hook) silently declines to rewrite two very common command shapes, leaving them running uncompressed with no RTK savings and no indication anything was skipped:

  1. Piped commands, e.g. git show HEAD | head -50 — passes through unchanged. The same command without a pipe (git show HEAD, git show --name-only HEAD, git show origin/main:file.txt) rewrites fine to rtk git show ....
  2. gh pr with --json, e.g. gh pr view 123 --json body — passes through unchanged. Without --json (gh pr view 123, gh pr diff 123, gh pr checks 123, gh pr list --state open) it rewrites fine to rtk gh pr ....

Why this matters

Ran rtk discover over 30 days / 950 sessions / ~30K Bash commands in a real project. git show (5,936 calls) and gh pr (2,824 calls) were the two single biggest sources of missed savings — an estimated ~1.8M and ~1.4M tokens respectively — almost entirely because real-world usage of both commands very commonly involves a pipe (| head, | grep) or --json (the standard way to get structured, scriptable output from gh). So the hook is technically "working" but silently opts out on exactly the highest-value, highest-frequency real usage patterns for these two commands.

Reproduction

$ echo '{"tool_name":"Bash","tool_input":{"command":"git show HEAD | head -50"}}' | rtk hook claude
# (no output — command passes through unmodified)

$ echo '{"tool_name":"Bash","tool_input":{"command":"git show HEAD"}}' | rtk hook claude
{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecisionReason":"RTK auto-rewrite","updatedInput":{"command":"rtk git show HEAD"}}}

$ echo '{"tool_name":"Bash","tool_input":{"command":"gh pr view 123 --json body"}}' | rtk hook claude
# (no output — command passes through unmodified)

$ echo '{"tool_name":"Bash","tool_input":{"command":"gh pr view 123"}}' | rtk hook claude
{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecisionReason":"RTK auto-rewrite","updatedInput":{"command":"rtk gh pr view 123"}}}

(rtk 0.42.4, Windows/Git Bash)

Ask

  • For the piped case: consider whether rtk git show HEAD | head -50 would actually preserve correct semantics (rtk's compression happening before the pipe, same as today just with the RTK-processed stream feeding into head) — if so, this may just need the hook's pipe-detection to stop bailing out entirely and instead rewrite only the first command in the pipeline.
  • For gh pr --json: if the concern is not wanting to reformat/break parseable JSON, that's reasonable — but it'd help to have this be a documented, discoverable behavior (e.g. rtk discover or rtk gain flagging "N commands skipped due to --json/pipe, by design") rather than a silent pass-through that looks identical to "not installed."

Happy to provide more repro data from rtk discover output if useful.

Activity

  1. pszymkowiak commented on Aug 24, 2026

    @pszymkowiak
    Collaborator

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟠 Priority high
    🎯 Confidence 72%

    Summary

    PreToolUse hook silently passes through piped commands (e.g. 'git show HEAD | head -50') and 'gh pr ... --json ...' without rewriting or reporting skip, losing RTK savings on two of the highest-frequency command patterns; overlaps with #3578's piped-command report but adds the gh --json case and quantified impact data.


    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 tracks the same problem with the more complete discussion. Please follow up there; if your case differs in a way that issue does not cover, comment here and it can be reopened.

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:high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions