#!/usr/bin/env bash # PreToolUse hook: route a Bash tool call through `rtk hook claude`, which may # rewrite the command to its rtk-prefixed form. rtk's output is passed through # when rtk succeeds. The hook always exits 0: a PreToolUse exit 2 blocks the tool # call, and rtk exits 2 on a usage error (e.g. an rtk without `hook claude`), so # any rtk failure is swallowed and the call proceeds unchanged. Without rtk on # PATH it does nothing. Limits: the rtk plugin's README. set -euo pipefail # apm could deploy this file to other runtimes, where it must do nothing. here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/" case "$here" in */.claude/hooks/*) ;; *) exit 0 ;; esac command -v rtk > /dev/null 2>&1 || exit 0 # stdin (the hook payload) is inherited by rtk inside the substitution. out="$(rtk hook claude)" || exit 0 [[ -z "$out" ]] || printf '%s\n' "$out" exit 0