Compare commits

...
Author SHA1 Message Date
Patrick szymkowiak 76d6508f9e fix(hook): omit permissionDecision on allow to fix bypassPermissions mode (#893)
When Claude Code runs in bypassPermissions mode, it skips the
hookPermissionResult path entirely — discarding updatedInput that
accompanies a permissionDecision. This caused RTK rewrites to be
silently ignored.

Fix: for Allow verdict, omit permissionDecision from hook output.
Omitting = allow by default, AND updatedInput is processed correctly
in bypassPermissions mode. Ask verdict still includes
permissionDecision: "ask" explicitly.

Applied to both rtk-rewrite.sh (Claude Code) and hook_cmd.rs
(Copilot VS Code).

Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu>
2026-04-03 09:01:48 +02:00
2 changed files with 26 additions and 18 deletions

No files matched your search

+8 -4
View File
@@ -83,24 +83,28 @@ ORIGINAL_INPUT=$(echo "$INPUT" | jq -c '.tool_input')
UPDATED_INPUT=$(echo "$ORIGINAL_INPUT" | jq --arg cmd "$REWRITTEN" '.command = $cmd')
if [ "$EXIT_CODE" -eq 3 ]; then
# Ask: rewrite the command, omit permissionDecision so Claude Code prompts.
# Ask/Default: rewrite the command, include permissionDecision "ask"
# so Claude Code prompts the user for confirmation.
# In bypassPermissions mode this is ignored (command still rewrites correctly).
jq -n \
--argjson updated "$UPDATED_INPUT" \
'{
"hookSpecificOutput": {
"hookEventName": "PreToolUse",
"permissionDecision": "ask",
"permissionDecisionReason": "RTK: no explicit allow rule",
"updatedInput": $updated
}
}'
else
# Allow: output the rewrite instruction in Claude Code hook format.
# Allow (explicit rule matched): rewrite without permissionDecision.
# Omitting permissionDecision = allow by default, AND works correctly
# in bypassPermissions mode (updatedInput is not discarded). Fixes #893.
jq -n \
--argjson updated "$UPDATED_INPUT" \
'{
"hookSpecificOutput": {
"hookEventName": "PreToolUse",
"permissionDecision": "allow",
"permissionDecisionReason": "RTK auto-rewrite",
"updatedInput": $updated
}
}'
+18 -14
View File
@@ -119,21 +119,25 @@ fn handle_vscode(cmd: &str) -> Result<()> {
return Ok(());
}
// Allow (explicit rule matched): auto-allow the rewritten command.
// Ask/Default (no allow rule matched): rewrite but let the host tool prompt.
let decision = match verdict {
PermissionVerdict::Allow => "allow",
_ => "ask",
// Allow (explicit rule matched): omit permissionDecision so updatedInput
// works in bypassPermissions mode (#893). Omitting = allow by default.
// Ask/Default: include permissionDecision "ask" to prompt the user.
let output = match verdict {
PermissionVerdict::Allow => json!({
"hookSpecificOutput": {
"hookEventName": PRE_TOOL_USE_KEY,
"updatedInput": { "command": rewritten }
}
}),
_ => json!({
"hookSpecificOutput": {
"hookEventName": PRE_TOOL_USE_KEY,
"permissionDecision": "ask",
"permissionDecisionReason": "RTK: no explicit allow rule",
"updatedInput": { "command": rewritten }
}
}),
};
let output = json!({
"hookSpecificOutput": {
"hookEventName": PRE_TOOL_USE_KEY,
"permissionDecision": decision,
"permissionDecisionReason": "RTK auto-rewrite",
"updatedInput": { "command": rewritten }
}
});
println!("{output}");
Ok(())
}