Skip to main content

Crate rtk_cc_hook

Crate rtk_cc_hook 

Source
Expand description

rtk-cc-hook — the plugin’s PreToolUse hook.

Claude Code runs this binary before every Bash / PowerShell tool call, hands it the event as JSON on stdin, and reads a JSON verdict from stdout. The verdict is produced by rtk hook claude, which already speaks this exact schema; this file only moves bytes between the two.

Two rules govern the whole file:

  1. The hook always exits 0. Exit 2 would feed stderr back to Claude as a blocking error — an absurd outcome for “I could not optimize your command”. Every failure degrades to silence instead.
  2. Empty stdout means “no opinion”. Claude Code then runs the command the model actually wrote. That is also rtk’s own signal for “nothing to rewrite”, so the fail-open path and the no-op path are the same path.

Functions§

main 🔒
print_help 🔒
run_rtk 🔒
Spawn rtk, write payload to its stdin, and return its stdout on a clean exit.