Skip to content

fix(hook): pass -- to rtk rewrite in every delegate - #5133

Merged
KuSh merged 3 commits into
rtk-ai:developfrom
LeviReisJs:fix/hooks-rewrite-double-dash
Nov 28, 2026
Merged

KuSh merged 3 commits into
rtk-ai:developfrom
LeviReisJs:fix/hooks-rewrite-double-dash

Conversation

@LeviReisJs

Copy link
Copy Markdown
Contributor

Summary

Every delegate that hands a command to rtk rewrite now ends the option list with -- first, so a command that reads as an option of rtk rewrite itself (--help, -h) reaches it as the positional command instead of being parsed by clap.

Before, rtk rewrite "--help" printed usage text and exited 0, which is the "rewrite, allowed" answer, so the delegate handed the usage text to the shell as the command (and the Claude Code / Cursor shell hooks marked it auto-allowed). With --, the same command exits non-zero with no stdout, which every delegate already treats as pass-through.

The six call sites listed in the issue:

  • hooks/pi/rtk.ts (pi.exec)
  • hooks/hermes/rtk-rewrite/__init__.py (subprocess.run)
  • openclaw/index.ts (execFileSync)
  • hooks/claude/rtk-rewrite.sh, hooks/cursor/rtk-rewrite.sh, .claude/hooks/rtk-rewrite.sh

-- is clap's own end-of-options marker, so the change works on every rtk version that has rewrite (the hooks' 0.23.0 version guard is unaffected).

The Pi extension's content changed, so its new hash is appended to KNOWN_PI_PLUGIN_HASHES; earlier hashes stay, so installs of the previous stock extension are still recognised and upgraded.

Closes #5127

Test plan

New integration test tests/rewrite_delegates_test.rs:

  • every_rewrite_delegate_ends_options_before_the_command reads the six delegates and requires the -- form in each. Before the fix it failed listing all six files; after, it passes.

  • rewrite_after_double_dash_treats_an_option_as_the_command pins the contract the delegates rely on: rtk rewrite -- --help and rtk rewrite -- -h exit non-zero with empty stdout.

  • cargo fmt --all --check

  • cargo clippy --all-targets -- -D warnings

  • cargo test on Windows 11: the new tests and all 341 hooks::init tests pass. The full lib run has 21 failures, all in core::stream / core::shell / core::task_cmd process tests; the same 21 fail on a clean develop (8bb6096) on this machine, so none comes from this change. I could not run the suite on Linux locally; CI will.

  • Snapshot tests / ≥20% reduction: not applicable, no filter changed.

🤖 Generated with Claude Code

A command that reads as an option of `rtk rewrite` itself (`--help`, `-h`)
was parsed by clap, which printed usage text and exited 0, the "rewrite,
allowed" answer, so the delegate ran the usage text as the command. End
the option list with `--` at all six call sites (pi, hermes, openclaw and
the three rtk-rewrite.sh hooks) and register the new Pi extension hash.

Closes rtk-ai#5127

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@CLAassistant

CLAassistant commented Nov 16, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@rtk-wshm-sync-bot rtk-wshm-sync-bot Bot added bug Something isn't working hooks security labels Nov 16, 2026
@rtk-wshm-sync-bot

Copy link
Copy Markdown

wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟡 Risk medium

Summary

This PR fixes a security issue where commands starting with option-like flags (e.g. --help, -h) were misparsed by rtk rewrite's own argument parser instead of being treated as the command to evaluate, causing them to be wrongly auto-allowed. It adds -- before the command argument in all six delegate call sites (shell, Python, TypeScript) and adds a new integration test to pin this contract.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #5127


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

@TechWizard9999 TechWizard9999 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, the fix itself looks right. Root cause: rtk rewrite takes its command as a trailing arg with allow_hyphen_values, but a lone --help/-h still matches clap's built-in help flag, so it prints usage and exits 0, which every delegate reads as "rewrite and allow". A leading -- ends option parsing, and it works on both shapes Rewrite has had (cmd: String in 0.25-0.29, the trailing Vec<String> since). All six delegates are covered and the new test fails for each one if its -- is removed.

One thing needs updating before merge: the Hermes plugin's own unit test still expects the old argv. hooks/hermes/tests/test_rtk_rewrite_plugin.py:148-155 (test_rewrite_updates_payload_without_returning_a_directive) asserts run.assert_called_once_with(["rtk", "rewrite", "git status"], ...), but the plugin now calls ["rtk", "rewrite", "--", "git status"], so both subtests (exit 0 and 3) fail. CI doesn't run that suite, which is why it stayed green. Adding "--" to the expected list fixes it and gives the Hermes delegate a behavioural check too.

cc @KuSh

KuSh and others added 2 commits November 28, 2026 16:51
…d Pi extension

With develop merged in, hooks/pi/rtk.ts carries both the 0.25.0 floor and
the `--`, a revision no earlier hash covers: allowlist it. The Hermes plugin
tests and the shell-hook version-floor test still expected
`rtk rewrite <command>`; they now expect the `--` form, so they check the
argv the Hermes, Claude Code and Cursor delegates actually pass. The hook
traces in TECHNICAL.md and supported-agents.md, the Hermes snippet in
hooks/README.md, the `<command>` example in what-rtk-covers.md and the
`rtk rewrite` help text show the call the delegates make and get the `--`
too. The delegate list in the new test is sorted by path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@KuSh KuSh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 1 — APPROVED

Claim: every delegate that hands a command to rtk rewrite passes -- first, so a command that reads as an option of rtk rewrite (--help, -h) is looked up as a command instead of coming back as rtk's usage text with exit 0.
Scope: accept (round 1, frozen); maintainer PRs: checked against #3763 and #4269, which touch the same files: neither changes the rtk rewrite call or the Pi hash list.
Ran: the six delegates driven the way their host drives them (the three shell hooks with a PreToolUse payload on stdin, the Pi extension and the OpenClaw plugin under Node with a stand-in host, the Hermes _pre_tool_call) × 10 commands (--help, -h, --version, -V, -v, git status, an ask rule, a deny rule, git log -- src, -- git status) × before/after, against rtk 0.25.0, 0.48.0, 1.1.0, 1.2.1 and this branch merged onto develop; rtk init --agent pi over every earlier stock extension, over an edited one, with --uninstall, and into a symlinked extensions directory; the full suite and the Hermes plugin tests on the head and on the merge with develop. Invariants: every decision (rewrite, ask, deny, pass-through), oldest release the version floor admits. Savings: n/a, no filter changed.
Pins: 7 decisions, 8 mutated, 0 survived. The fixup: 4 mutated, 0 survived.
Matrix: executed this round; pin check: executed this round
CI @d5195f9d: all green (16/16, on the merge with develop 5c61b87)

Blocks merge (0)

Follow-ups

  • #4588 CI does not run the plugin test suites that live outside cargo: outside this PR's hunks; the Hermes failures here are a new instance, comment added.

Checked and correct — no need to re-verify

  • Before: all six delegates replaced --help and -h with the usage text, and the Claude Code, repo-local Claude Code and Cursor hooks marked it allowed. After: all six pass the command through. The other 108 of 120 rows are byte-identical. Same on 0.25.0, 0.48.0, 1.1.0 and 1.2.1.
  • On 0.25.0, the -- also stops OpenClaw from blocking --version, -V, -v and -- git status as a deny (clap's usage error exits 2 there).
  • rtk init --agent pi upgrades every earlier stock extension, keeps an edited one and uninstalls only the stock one.
  • No other code calls rtk rewrite as a subprocess; the in-process hosts never parse the command as rtk's own arguments.
  • Removing the -- from any of the six delegates turns every_rewrite_delegate_ends_options_before_the_command red, and removing the hash turns both Pi hash tests red.

Next

Fixup d5195f9 pushed and code-reviewed, approving. It merges develop into the branch (no conflict) and adds one commit. With #5131 merged, hooks/pi/rtk.ts is a new revision whose hash was not listed, so test_known_pi_plugin_hashes_are_sha256 and test_all_git_pi_plugin_revisions_are_allowlisted failed on the merge. #5131's version_floor test and the Hermes plugin tests still expected the argv without --. The commit allowlists the merged extension, makes those tests expect -- (so they now check the Hermes, Claude Code and Cursor argv by running them), adds -- to the call examples in hooks/README.md, TECHNICAL.md, supported-agents.md, what-rtk-covers.md and the rtk rewrite help, and sorts the delegate list in the new test. The Hermes test update asked for in the earlier review is included.
Threads: 0 open.

@KuSh
KuSh merged commit f1d17e7 into rtk-ai:develop Nov 28, 2026
16 checks passed
@rtk-release-bot rtk-release-bot Bot mentioned this pull request Nov 28, 2026
yungSNAT added a commit to yungSNAT/PascalsLetter that referenced this pull request Nov 29, 2026
…run as usage text (#255)

* fix(hook): pass `--` to rtk rewrite in every delegate

A command that reads as an option of rtk rewrite (--help, -h) was parsed
by clap, which printed usage text and exited 0, so the delegate ran the
usage text as the command. Ported from rtk-ai#5133.

* test(bench): the fake rtk expects -- before the command

* rewrite --: finish the double-dash port (docs, Pi stock hashes, OpenCode hook)

* test(pi): upstream's stock extension before its rewrite -- fix is a known hash

* test(hook): rtk hook opencode takes an option-shaped command after --

* docs: show rtk rewrite -- in the remaining examples

* fix(pi): recognise upstream's stock extension from before its rewrite -- fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working hooks security

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

4 participants