Skip to content

hook check dry-run does not expose the actual host permission decision #3476

Open

Description

@pavelbe

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 claude

The 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 claude

The 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 permissionDecision that 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

  1. JSON dry-run and actual rtk hook claude agree on rewritten input and
    permission decision.
  2. Tests cover fully rewritten, mixed rewritten/passthrough, no-rewrite and
    substitution/deny cases.
  3. No command is executed by the dry-run.
  4. 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

  1. pszymkowiak commented on Aug 8, 2026

    @pszymkowiak
    Collaborator

    wshm · Automated triage by AI

    🔍 Automated Triage

    ✨ Category feature
    🟡 Priority medium
    🎯 Confidence 85%

    Summary

    Add a --json diagnostic mode to rtk hook check that surfaces the actual permissionDecision (and rewrite details) so dry-run output matches real rtk hook claude behavior.

    📁 Relevant files
    • src/hook/check.rs
    • src/hook/claude.rs

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

  2. KuSh commented on Sep 9, 2026

    @KuSh
    Collaborator

    Half of this is addressed by #3955, which routes rtk hook check through the same hooks::decision the hooks use, so it consults the host's real permission rules (and honours --agent, which it previously discarded) instead of calling rewrite_command directly.

    What that PR does not do is the part this issue is actually about: it still collapses AllowRewrite and AskRewrite into 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:

    Discarded today Question it answers
    AllowRewrite vs AskRewrite "why am I still prompted?" — this issue
    Which of four causes produced a defer "why no rewrite?" — each has a different fix
    Which rule matched, and for a chain which segment blocked the allow "I allowed that, why does it ask?"
    Which settings files were read, and whether they existed a missing ~/.gemini/settings.json is indistinguishable from "no rule matched"
    The response the host actually receives Copilot IDE renders a rewrite as a deny-with-suggestion; nothing connects that to "rewrite"

    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 own hooks.exclude_commands. The last is the most opaque, because it was configured once and forgotten.

    Suggested shape

    $ rtk hook check --agent claude "git push origin main && cargo test"
    agent     claude — in-process (rtk hook claude), hook installed
    rules     ~/.claude/settings.json + .claude/settings.local.json (5 Bash rules)
    decision  rewrite, ask
    rewrite   rtk git push origin main && rtk cargo test
    why       segment 2/2 `cargo test` matches allow Bash(cargo *)
              segment 1/2 `git push origin main` matches no allow rule -> the chain asks (#1213)
    host sees {"hookSpecificOutput":{...,"updatedInput":{"command":"rtk git push …"}}}
    

    with named defer causes, and a --json mode so it is pasteable into bug reports. Exit codes could mirror rtk rewrite's 0/3/1/2 so the diagnostic and the CLI speak one language — nothing in the repo consumes hook 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 check is 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_rules returns a bare verdict and would have to report which pattern matched (and, for a compound, which segment failed to match an allow rule).
    • "excluded by config" and "no rewrite rule" are indistinguishable today, because rewrite_command returns Option<String> for both.

    Best done after #3955 lands, since it touches the shared decision that PR introduces.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions