Repository navigation
Description
Summary
rtk hook check shows the rewritten command but not the host decision that
rtk hook claude will emit. On rtk 0.45.0, two inputs that both look
successfully rewritten in the dry-run have materially different hook outputs:
one includes permissionDecision: "allow"; the other does not.
This makes the current dry-run insufficient for diagnosing host integration
and permission/rewrite behavior (see also #3018). The request is not to
auto-allow mixed blocks. It is to expose the actual decision faithfully.
Environment
- RTK:
0.45.0 - Linux x86_64 / WSL2
- target agent: Claude Code
- checked: 2026-08-08
Reproduction
Fully rewritten block:
rtk hook check --agent claude $'git status\ngit diff --stat'
printf '%s' '{"tool_name":"Bash","tool_input":{"command":"git status\ngit diff --stat"}}' \
| rtk hook claudeThe check prints only:
rtk git status
rtk git diff --stat
The host response includes:
{"updatedInput":{"command":"rtk git status\nrtk git diff --stat"},"permissionDecision":"allow"}Mixed rewritten/passthrough block:
rtk hook check --agent claude $'git status\ntrue'
printf '%s' '{"tool_name":"Bash","tool_input":{"command":"git status\ntrue"}}' \
| rtk hook claudeThe check again prints a successful-looking rewrite:
rtk git status
true
But the host response has updatedInput and no permissionDecision:
{"updatedInput":{"command":"rtk git status\ntrue"}}The human dry-run cannot distinguish these outcomes.
Expected
Add a stable machine-readable diagnostic mode, for example:
rtk hook check --agent claude --json $'git status\ntrue'The payload should expose at least:
- target agent/host;
- original and rewritten command;
- whether any rewrite occurred;
- the exact
permissionDecisionthat the host adapter would emit (nullable); - a bounded reason/pass-through classification.
Human output may remain compact, but should not imply equivalent runtime
behavior for these two cases.
Acceptance
- JSON dry-run and actual
rtk hook claudeagree on rewritten input and
permission decision. - Tests cover fully rewritten, mixed rewritten/passthrough, no-rewrite and
substitution/deny cases. - No command is executed by the dry-run.
- Existing text output and exit behavior remain compatible unless an explicit
documented change is intended.
Impact
Low runtime severity, medium integration/debugging value. This removes guesswork
from hook verification and lets wrappers/tests compare host behavior without
synthesizing and reverse-parsing full hook envelopes.
Activity
pszymkowiak commentedon Aug 8, 2026
🔍 Automated Triage
featuremediumSummary
Add a --json diagnostic mode to
rtk hook checkthat surfaces the actual permissionDecision (and rewrite details) so dry-run output matches realrtk hook claudebehavior.📁 Relevant files
src/hook/check.rssrc/hook/claude.rsTriaged automatically by wshm · This is an automated analysis, not a human review.
KuSh commentedon Sep 9, 2026
Half of this is addressed by #3955, which routes
rtk hook checkthrough the samehooks::decisionthe hooks use, so it consults the host's real permission rules (and honours--agent, which it previously discarded) instead of callingrewrite_commanddirectly.What that PR does not do is the part this issue is actually about: it still collapses
AllowRewriteandAskRewriteinto exit 0 with identical stdout. So the report here stands — two commands that both "look rewritten" in the dry-run still produce materially different host responses, and the dry-run gives no signal about which.What a complete diagnostic would report
The decision already computes all of this and the diagnostic discards it:
AllowRewritevsAskRewrite~/.gemini/settings.jsonis indistinguishable from "no rule matched"The defer collapse is the sharpest of these: four different situations print the same
No rewrite for:line — an unattestable construct, no matching rewrite rule, an already-rtk-prefixed command, and excluded by the user's ownhooks.exclude_commands. The last is the most opaque, because it was configured once and forgotten.Suggested shape
with named defer causes, and a
--jsonmode so it is pasteable into bug reports. Exit codes could mirrorrtk rewrite's 0/3/1/2 so the diagnostic and the CLI speak one language — nothing in the repo consumeshook check's current codes.Implementation note
The reason should be carried in the decision itself rather than computed by a separate explainer. A second function walking the same gates would be a second implementation of the gate order — exactly the duplication #3955 removes. Most callers ignore the field;
rtk hook checkis the one that reads it, so the diagnostic cannot drift from the decision it describes.Two things need more than threading a fieldless enum:
check_command_with_rulesreturns a bare verdict and would have to report which pattern matched (and, for a compound, which segment failed to match an allow rule).rewrite_commandreturnsOption<String>for both.Best done after #3955 lands, since it touches the shared decision that PR introduces.