Skip to content

Bug: rtk hook claude returns empty output when no rewrite available #1773

Closed as not planned

Description

@xikaos

Description

When rtk hook claude encounters a command that RTK cannot rewrite, it returns empty output (0 bytes) instead of valid JSON. This breaks Claude Code's hook system, which expects all hooks to return valid JSON responses.

Steps to Reproduce

  1. Create a test JSON input for a command RTK doesn't rewrite:
echo '{"tool_name":"Bash","tool_input":{"command":"head -c 100 /etc/hosts"}}' | rtk hook claude
  1. Observe: Empty output (0 bytes) with exit code 1

  2. Expected: Valid JSON response, even if no rewrite is available

Current Behavior

$ echo '{"tool_name":"Bash","tool_input":{"command":"head -c 100 file.txt"}}' | rtk hook claude
# Returns: empty (0 bytes)
# Exit code: 1

Expected Behavior

Should return valid JSON indicating passthrough:

{
  "hookSpecificOutput": {
    "hookEventName": "PreToolUse",
    "permissionDecisionReason": "no RTK rewrite available",
    "updatedInput": {
      "command": "head -c 100 file.txt"
    },
    "permissionDecision": "allow"
  }
}

Affected Commands

Commands that RTK doesn't have rewrites for:

  • head -c
  • wc -l
  • sed
  • yarn test (and other yarn subcommands)
  • npm run (and other npm subcommands)
  • And others...

Impact

  • Claude Code's hook system breaks when encountering these commands
  • Users implementing RTK integration must wrap the hook with error handling
  • Reduces reliability of the RTK ↔ Claude Code integration

Environment

  • RTK version: 0.37.1
  • Platform: macOS (arm64)
  • Integration: Claude Code PreToolUse hook

Root Cause

The rtk hook claude command checks if a rewrite is available and only outputs JSON when a rewrite exists. When no rewrite is found, it returns nothing instead of a passthrough response.

Suggested Fix

Always output valid JSON from rtk hook claude, even when no rewrite is available. Return a passthrough response that tells Claude Code to execute the command unchanged.

Workaround

Until this is fixed, use a wrapper script that detects empty output and generates valid JSON:

#!/bin/bash
input=$(cat)
output=$(rtk hook claude <<< "$input" 2>&1) || rtk_exit=$?
if [[ -z "$output" ]]; then
  command=$(echo "$input" | python3 -c "import json,sys; d=json.load(sys.stdin); print(d['tool_input']['command'])" 2>/dev/null)
  echo "{\"hookSpecificOutput\":{\"hookEventName\":\"PreToolUse\",\"permissionDecisionReason\":\"no rewrite\",\"updatedInput\":{\"command\":\"$command\"},\"permissionDecision\":\"allow\"}}"
else
  echo "$output"
fi

Then update Claude Code settings to use the wrapper instead of rtk hook claude directly.

Activity

  1. added a commit that references this issue on May 7, 2026
    0c71bdd
  2. pszymkowiak commented on May 27, 2026

    @pszymkowiak
    Collaborator

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟡 Priority medium
    🎯 Confidence 97%

    Summary

    rtk hook claude emits empty output instead of valid JSON passthrough when no rewrite is available, breaking Claude Code hooks; PR #1775 already open.

    This looks like a simple fix that could be auto-resolved. Repo maintainers can use /wshm fix to attempt it.


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

  3. KuSh commented on Sep 27, 2026

    @KuSh
    Collaborator

    This is the intended behaviour under Claude Code's hook protocol, not a defect. A PreToolUse hook that exits 0 with no output tells Claude Code to proceed with the tool call unchanged; hooks are not required to emit JSON, and rtk hook claude does exactly that for commands it has no rewrite for. On the current code the exit status in that case is 0 (the exit 1 from the report no longer reproduces). Emitting permissionDecision: "allow" for a command rtk did not rewrite would bypass the user's own permission rules, which the hook deliberately avoids: it only asserts allow when one of the user's explicit allow rules matches. Closing as working as intended.

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

    area:clibugpriority:medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions