Skip to content

rtk hook check ignores pipeline rules: it reports a rewrite for commands the hook denies or passes through #4629

Open

Description

@alfredopons

Summary

Since 1.0, rtk hook claude evaluates pipeline rules (hook.before_tool.shell) before the rewrite. rtk hook check, described as "Check how a command would be rewritten by the hook engine (dry-run)", does not: for a command that a pipeline rule denies or passes through, it prints the default rewrite and exits 0.

As a result, none of the dry-run commands shows the decision the hook actually makes:

  • rtk hook check sees permission rules but not pipeline rules.
  • rtk pipeline explain sees pipeline rules but not permission rules.
  • rtk rewrite ignores pipeline rules, although its help says that exit 2 with a printed message means "an rtk pipeline rule denied or routed the command". If pipeline rules act on Claude Code only by design (1.0.0 changelog: "pipeline hook rules act on Claude Code only"), the help text should say so.

Related: #3476 (rtk hook check does not expose the host permission decision) and #4518 (rtk hook check --agent opencode judges differently from the OpenCode plugin).

Environment

  • rtk 1.0.1, default edition (with rtk-engine), on Windows 11 with Git Bash and on Ubuntu 24.04 x86_64
  • Same results with the develop prerelease dev-1.0.2-rc.551 (commit 7bff768) on Ubuntu 24.04
  • No user pipeline file

Steps to reproduce

mkdir -p hc && cd hc
mkdir -p .claude .rtk && git init -q
printf '{"permissions":{"deny":["Bash(git push:*)"]}}' > .claude/settings.json
cat > .rtk/pipeline.toml <<'EOF'
schema_version = 1
[pipeline]
name = "repro"
extends = "rtk:default"

[[hook.before_tool.shell]]
name = "deny-git-status"
when = { command_matches = '''^\s*git\s+status\b''' }
action = "deny"
message = "project pipeline: git status denied"

[[hook.before_tool.shell]]
name = "keep-git-log"
when = { command_matches = '''^\s*git\s+log\b''' }
action = "passthrough"
EOF
rtk trust --yes > /dev/null 2>&1
payload() { printf '{"hook_event_name":"PreToolUse","tool_name":"Bash","cwd":"%s","tool_input":{"command":"%s"}}' "$PWD" "$1"; }
for c in "git status" "git log -n 1" "git push" "echo hi"; do
  echo "== $c"
  echo "   pipeline explain: $(rtk pipeline explain --tool Bash --command "$c" | sed -n 2p)"
  echo "   hook claude:      $(payload "$c" | rtk hook claude)"
  echo "   rewrite:          $(rtk rewrite "$c" 2>&1) [exit $?]"
  echo "   hook check:       $(rtk hook check "$c" 2>&1) [exit $?]"
done
rtk untrust

Observed

Command rtk hook claude (the real decision) rtk pipeline explain rtk hook check rtk rewrite
git status (pipeline deny) "permissionDecision":"deny" rule deny-git-status -> action deny rtk git status, exit 0 rtk git status, exit 3
git log -n 1 (pipeline passthrough) no output: runs unchanged rule keep-git-log -> action passthrough rtk git log -n 1, exit 0 rtk git log -n 1, exit 3
git push (permission deny) no output: defers to the host deny rule rtk-rewrite -> action rewrite Denied by a permission rule: git push, exit 1 no output, exit 2
echo hi (nothing to rewrite) no output rule rtk-rewrite -> action rewrite No rewrite for: echo hi, exit 1 no output, exit 1

rtk hook check also exits 1 both for "Denied by a permission rule" and for "No rewrite", so a script cannot tell them apart.

Expected

rtk hook check follows the same decision path as rtk hook claude (pipeline rules, then the permission gate, then the rewrite) and prints the resulting decision with its source (pipeline rule name or permission rule), with exit codes that distinguish deny, passthrough or no rewrite, and rewrite; for example the same 0/1/2/3 scheme as rtk rewrite, as also suggested in #3476.

Why it matters

Someone debugging a pipeline, for example a passthrough added so git log reaches the agent unfiltered, gets a misleading answer from the documented dry-run command and may conclude that the rule does not work.


Reported by Alfredo Pons Menargues (GitHub: alfredopons).

Activity

  1. rtk-wshm-sync-bot commented on Oct 17, 2026

    @rtk-wshm-sync-bot

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟠 Priority high
    🎯 Confidence 88%

    Summary

    rtk hook check and rtk rewrite skip pipeline rules and conflate deny/no-rewrite exit codes, giving a misleading dry-run of the actual hook decision; align with rtk hook claude's decision path and distinct exit codes.

    Suggested Actions

    1. Make rtk hook check evaluate pipeline rules before the rewrite, matching rtk hook claude's decision path
    2. Give rtk hook check/rtk rewrite distinct exit codes for deny/passthrough/no-rewrite/rewrite (0/1/2/3 scheme)
    3. Cross-reference hook check dry-run does not expose the actual host permission decision #3476 and OpenCode: rtk hook check --agent opencode judges differently from the plugin #4518 — overlapping root cause of hook-check decision mismatch
    4. If pipeline rules are Claude-Code-only by design, update rtk rewrite --help text to state that explicitly

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

  2. alponme commented on Oct 28, 2026

    @alponme

    One more divergence on 1.1.0: the Claude Code worktree exclusion from #3879 is applied only in rtk hook claude, from the payload cwd. Inside <repo>/.claude/worktrees/<name>, rtk hook check 'git status' still prints rtk git status (exit 0) and rtk pipeline explain --tool Bash --command 'git status' reports the rtk-rewrite rule, while rtk hook claude with that cwd leaves the command untouched. Seen on Windows 11 (Git Bash). Today the only way to see the real decision there is feeding the PreToolUse JSON with cwd to rtk hook claude.

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