Repository navigation
docs(hook): document all four rtk rewrite exit codes in --help - #4204
Conversation
`rtk rewrite --help` still described a two-code protocol (0 rewritten, 1 no equivalent) and suggested `$(rtk rewrite "$CMD") || exit 0`. The command returns four codes, and with no permission rules it exits 3 by design (rtk-ai#1155), so a hook following the help text drops every default rewrite. List all four codes in the help, note that the no-rule default is 3, and align the table on `rewrite_cmd::run` with the protocol tests. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01WcTsSr2cKxstnvgXk2bP88
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Correct the shell example, referenced protocol comments, and host-specific handling description before approval.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (2)
What changed in this PR
Documentation-only update to align rtk rewrite --help and protocol documentation with all four exit codes.
Changes:
- Documents all four rewrite exit codes and default behavior.
- Corrects the
rewrite_cmdexit-code table. - No runtime behavior changes.
| File | Summary |
|---|---|
src/main.rs |
Updates CLI help text. |
src/hooks/rewrite_cmd.rs |
Corrects exit-code documentation. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Exit 0 needs allow rules covering every command of a chain, only RTK_REWRITE_HOST=openclaw relaxes the default 3, and exit 1 also covers excluded commands, `$(...)` and file redirects. Say so in --help and on the rewrite_cmd::run table, update the outdated FEATURES.md section, and test that --help gives each exit code its own paragraph. Co-authored-by: tandede <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
KuSh
left a comment
There was a problem hiding this comment.
Round 1 — APPROVED
Claim: rtk rewrite --help documents all four exit codes, and the table on rewrite_cmd::run matches them.
Scope: accept.
Ran: develop merge-base vs this head merged onto develop e12ca86, built separately: exit-code matrix over allow / ask / deny / no rules, chains (&&, ;, |), $(...), redirects, excluded commands, already-rtk commands and RTK_REWRITE_HOST values (16 rows, then 75 cases by a second run); exit codes and output identical on both sides. REWRITTEN=$(rtk rewrite "$CMD") || exit 0 and hooks/claude/rtk-rewrite.sh run against the new binary. Docs only, no savings change.
Pins: no runtime decision added; the new help layout is pinned by test_rewrite_help_documents_each_exit_code (4 of 4 mutations of the help text fail it).
CI @d0abeebf0: all green (12 checks, tests on macOS, Ubuntu and Windows).
Checked and correct — no need to re-verify
- Each code and its stdout as stated: 0 rewrite + allow, 1 nothing, 2 nothing + deny, 3 rewrite + ask or default.
REWRITTEN=$(rtk rewrite "$CMD") || exit 0drops an exit-3 rewrite (default, no rules).- With
RTK_REWRITE_HOST, explicit ask stays 3 and deny stays 2. - The two Copilot threads: the example keeps its
REWRITTEN=assignment, andhooks/claude/rtk-rewrite.shdescribes 0 and 3 the same way since your develop merge. Resolved.
Filed as follow-ups
- #4500 openclaw docs say
RTK_REWRITE_HOSTrelaxes only commands no rule matched; it relaxes every default ask, partial allow included — outside this PR's hunks. rtk rewrite "-h"/"--help"prints the help on stdout with exit 0 — absorbed by #4351, comment added.
Fixup d0abeeb — what it changed
Running chains and host values showed the text was narrower than the code in four places; the fixup states them in --help, on the run table and in the paragraph under it:
- exit 0 needs allow rules covering every command of a chain:
git status && cargo testwith onlyBash(git status)allowed exits 3; - only
RTK_REWRITE_HOST=openclawrelaxes (pi, hermes and unknown names stay 3), and it turns every 3 but an ask rule's into 0, so a hook that auto-allows on 0 runs rtk with the variable unset, ashooks/claude/rtk-rewrite.shdoes; - exit 1 also covers nothing left to rewrite, a command excluded in config and constructs RTK does not rewrite (
$(...), file redirects), and deny is checked before all of them; - a command already in RTK form can come back as itself under 0 or 3, so a hook compares the rewrite with the original.
It also carries in, co-authored by @tandede from #3639, the docs/usage/FEATURES.md section (it still described two codes and terraform plan as unsupported) and a test that each code renders as its own paragraph in --help.
Next
Nothing — fixup d0abeeb pushed and code-reviewed; approving.


What
rtk rewrite --helpstill describes the original two-code protocol:The command actually returns four codes (the table on
rewrite_cmd::run, checked end to end bytests/hook_decision_protocol_test.rs), and with no permission rules configured it exits 3, not 0 — deliberately, per #1155, so a machine without rules never auto-allows. A hook author who follows the help text and writes$(rtk rewrite "$CMD") || exit 0therefore discards every default rewrite.This PR:
Rewritevariant's doc comment (which is what--helpprints) to list all four codes, say that no-rule falls into 3, and point athooks/claude/rtk-rewrite.shas the reference handlingrewrite_cmd::runmatch the tests: 0 is "allow rule matched" (not just "rewrite allowed"), and 3 also covers the no-rule defaultNo behaviour change. The shipped hook scripts already branch on all four codes, so they are left untouched.
New
--helpVerification
cargo fmt --all,cargo clippy --all-targetsandcargo test --allpass locally.