Skip to content

delegates call rtk rewrite <cmd> without --, so a command of --help or -h comes back as rtk's help text with exit 0 #5127

Open

Description

@KuSh

rtk rewrite takes the command as one positional argument. When that argument reads as an option of rtk rewrite itself, clap handles it as one (rtk 1.2.0 and develop):

$ rtk rewrite "--help"; echo " -> exit $?"     # 1789 bytes of usage text on stdout
 -> exit 0
$ rtk rewrite "-h"; echo " -> exit $?"         # 453 bytes of usage text
 -> exit 0
$ rtk rewrite -- "--help"; echo " -> exit $?"
 -> exit 1
$ rtk rewrite -- "git status"; echo " -> exit $?"
rtk git status -> exit 3

Exit 0 with non-empty stdout is the "rewrite, allowed" answer, so a delegate hands the usage text to the shell as the command to run. The Claude Code and Cursor shell hooks also mark it auto-allowed, since exit 0 is their allow case. Six call sites pass the command without --:

  • hooks/pi/rtk.ts:46 — pi.exec("rtk", ["rewrite", cmd], …)
  • hooks/hermes/rtk-rewrite/__init__.py:63 — ["rtk", "rewrite", command]
  • openclaw/index.ts:85 — execFileSync("rtk", ["rewrite", command], …)
  • hooks/claude/rtk-rewrite.sh:59, hooks/cursor/rtk-rewrite.sh:48, .claude/hooks/rtk-rewrite.sh:54 — rtk rewrite "$CMD"

--help or -h is not a valid shell command on its own, so the practical harm is small: the agent gets "command not found" errors from usage lines instead of the same error for --help. The fix is to pass -- before the command at each site. rtk rewrite -- "<cmd>" works on 1.1.0, 1.2.0 and develop. The embedding guide (#3918) now documents the -- form.

Activity

  1. rtk-wshm-sync-bot commented on Nov 16, 2026

    @rtk-wshm-sync-bot

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟡 Priority medium
    🎯 Confidence 93%

    Summary

    rtk rewrite <cmd> passes the command without a -- separator, so clap parses --help/-h as rtk's own help flags and exits 0 with usage text, which delegates misread as an allowed-rewrite result.

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

    📁 Relevant files
    • hooks/pi/rtk.ts
    • hooks/hermes/rtk-rewrite/__init__.py
    • openclaw/index.ts
    • hooks/claude/rtk-rewrite.sh
    • hooks/cursor/rtk-rewrite.sh
    • .claude/hooks/rtk-rewrite.sh

    Suggested Actions

    1. Add -- before the command argument at all six call sites listed in the issue
    2. Cross-check Filter the command behind an exec boundary in one place #5051 ('Filter the command behind an exec boundary in one place') for a shared fix location
    3. Add a regression test invoking rtk rewrite with --help/-h as the literal command string
    4. Note overlap with Hardening (retracted as a bug): bundled hook calls rtk rewrite without a deadline from PreToolUse — see correction, rtk was NOT the cause of our timeouts #3589's PreToolUse hook-call hardening discussion for context

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

  2. LeviReisJs commented on Nov 16, 2026

    @LeviReisJs
    Contributor

    I'd like to take this one. Plan: pass -- before the command at the six call sites you listed (pi, hermes, openclaw and the three rtk-rewrite.sh hooks), and add a test per site that a command of --help / -h reaches rtk rewrite as the positional argument (non-zero exit, no usage text on stdout) while git status still rewrites. I'll send the PR against develop.

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions