Files
Holocron/plugins/rtk/.apm/hooks/route-through-rtk.sh
T
Defame1297andClaude Opus 5.5 cc1d396d47 fix(rtk): never block a Bash call when rtk itself fails
The hook ran `exec rtk hook claude`, so rtk's exit code became the hook's.
Claude Code treats a PreToolUse exit 2 as "block this tool call", and rtk
(clap) exits 2 on a usage error, e.g. an older rtk without `hook claude`.
On such a machine every Bash call would have been blocked.

The hook now captures rtk's stdout and always exits 0. On any non-zero rtk
exit it prints nothing, so the call proceeds unchanged. On success it prints
rtk's output only when non-empty, with no stray blank line. stdin still
reaches rtk.

Tests cover a stub rtk exiting 2 with stderr, exiting 1, and exiting 0 with
no output, and note that the real-rtk pass-through case depends on rtk
0.42.4's built-in rules.

Refs: #179

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
2026-12-06 07:55:22 +00:00

23 lines
882 B
Bash
Executable File

#!/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