Skip to content

fix(hook): emit explicit allow for non-rewritten commands (#1033)#2479

Open
ousamabenyounes wants to merge 1 commit into
rtk-ai:developfrom
ousamabenyounes:fix/issue-1033
Open

fix(hook): emit explicit allow for non-rewritten commands (#1033)#2479
ousamabenyounes wants to merge 1 commit into
rtk-ai:developfrom
ousamabenyounes:fix/issue-1033

Conversation

@ousamabenyounes

Copy link
Copy Markdown
Contributor

Fixes #1033.

When the hook had no rewrite to apply it exited 0 with no output. Claude Code treats "hook exits 0 with no output" differently from "no hook installed": under --dangerously-skip-permissions the silent exit still produced an unexpected permission prompt for non-rewritten commands.

Fix

Bump the hook to version 4 and emit an explicit {"permissionDecision":"allow"} on every passthrough path via a small _rtk_allow_passthrough helper (plain printf, no jq dependency on the early-exit paths), so Claude Code honours --dangerously-skip-permissions for commands RTK does not rewrite.

Test verification (RED → GREEN)

Section 5b of hooks/claude/test-rtk-rewrite.sh ("Passthrough must emit allow").

RED — hook reverted to develop (bare exit 0):

--- Passthrough must emit allow (issue #1033) ---
  FAIL which rtk (no rewrite)

GREEN — with the explicit allow:

--- Passthrough must emit allow (issue #1033) ---
  PASS which rtk (no rewrite) → permissionDecision=allow

(Re-proposes the accidentally-closed #1218, rebased onto current develop.)

When the PreToolUse hook exits 0 with no stdout output, Claude Code
treats it differently from having no hook installed and falls through to
its default permission prompt — making --dangerously-skip-permissions
ineffective for any command RTK has no rewrite rule for.

Add _rtk_allow_passthrough() that emits:
  {"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"allow"}}

and call it in all "no opinion" exit paths (exit codes 1, 0-no-change,
unknown, and the early guards for missing jq/rtk/old version).  The
deny-rule path (exit 2) retains bare exit 0 so Claude Code can apply
its own deny semantics.

Update test-rtk-rewrite.sh:
- test_rewrite now verifies permissionDecision=allow + no updatedInput
  for passthrough cases (replaces the empty-output check)
- Add test_passthrough_allows() section that directly reproduces the
  three commands from the bug report: which rtk, rtk --version,
  claude mcp list

Bump hook-version comment to 4.

Generated by Claude Code
Vibe coded by ousamabenyounes

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hook produces unexpected permission prompts in --dangerously-skip-permissions mode for non-rewritten commands

1 participant