rtk icon indicating copy to clipboard operation
rtk copied to clipboard

PreToolUse hook: permissionDecision works but updatedInput is ignored by Claude Code

Open sokol-matija opened this issue 8 months ago • 2 comments

Summary

The RTK PreToolUse hook fires correctly and outputs valid JSON with updatedInput, but Claude Code applies permissionDecision while silently ignoring updatedInput. Commands are never rewritten.

Environment

  • Claude Code: v2.1.72
  • RTK: latest (rtk init --show shows all green)
  • OS: macOS 14
  • Tested in: both bypassPermissions mode AND normal permission mode

What happens

  1. Hook fires ✅ (confirmed via debug log — input JSON received correctly)
  2. Hook outputs valid JSON with updatedInput ✅
  3. permissionDecision: "allow" is honored ✅ — commands run without permission prompts
  4. updatedInput is ignored ❌ — commands execute as original, not rewritten

Example: Running git status via Claude Code Bash tool:

  • Hook receives: {"tool_input": {"command": "git status", ...}}
  • Hook outputs: {"hookSpecificOutput": {"permissionDecision": "allow", "updatedInput": {"command": "rtk git status"}}}
  • Actual command executed: git status (raw verbose output, not RTK compressed)

Debug confirmation

Added temporary debug log to hook:

echo "[rtk-debug] hook called, input: $INPUT" >> /tmp/rtk-hook-debug.log

Log confirmed hook is being called with correct input. permissionDecision: "allow" works (no prompts). updatedInput does nothing.

Why most users don't notice

The auto-approve behavior (no permission prompts) works, so users assume the hook is fully functional. The rewriting is silently broken.

Workaround

Manually prefix all commands with rtk in CLAUDE.md instructions to Claude.

Question

Has anyone found a workaround or different hook response format that makes updatedInput work? Is this a known Claude Code limitation?

sokol-matija avatar Mar 11 '26 12:03 sokol-matija

Additional testing confirms this affects all commands, not just git. Tested ls -la and cat — both execute as raw commands instead of being rewritten to rtk ls / rtk read. The updatedInput field is universally ignored by Claude Code regardless of command type.

sokol-matija avatar Mar 11 '26 12:03 sokol-matija

Root Cause Found + Fix

After deeper investigation, the issue is not a Claude Code bug with updatedInput itself — it's a known Claude Code bug when multiple PreToolUse hooks are registered.

The Bug (Claude Code issue #15897)

When multiple PreToolUse hooks run, the last hook's result overwrites previous ones. If the last hook outputs nothing (exit 0), it sets updatedInput: undefined, wiping out RTK's rewrite.

How to reproduce

In ~/.claude/settings.json, if you have a "*" matcher hook registered after the RTK "Bash" matcher hook:

"PreToolUse": [
  { "matcher": "Bash", "hooks": [{ "command": "rtk-rewrite.sh" }] },
  { "matcher": "*",    "hooks": [{ "command": "some-other-hook.py" }] }
]

The some-other-hook.py runs after RTK, returns no updatedInput, and wipes RTK's rewrite.

Fix

Either remove the conflicting hook, or ensure RTK hook runs last:

"PreToolUse": [
  { "matcher": "*",    "hooks": [{ "command": "some-other-hook.py" }] },
  { "matcher": "Bash", "hooks": [{ "command": "rtk-rewrite.sh" }] }
]

Recommendation for RTK docs

Add a warning to TROUBLESHOOTING.md: if users have multiple PreToolUse hooks, RTK must be last in the list, otherwise its updatedInput gets wiped by subsequent hooks that return no output.

sokol-matija avatar Mar 11 '26 12:03 sokol-matija