A Claude Code PreToolUse hook on Bash execs `rtk hook claude` when rtk is on PATH and passes its answer through unchanged; without rtk it exits 0 silently. It acts only from .claude/hooks/, like git's push guard. Refs: #179 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
3.9 KiB
rtk
A Claude Code hook that routes Bash tool calls through rtk, the token-saving command wrapper, when rtk is installed.
Install
apm is the only supported install path (ADR-0024). Declare this package in the consuming project's apm.yml:
dependencies:
apm:
- git: https://git.rkdr.net/Mortis/Holocron.git
path: plugins/rtk
Then:
apm install
The entry above is unpinned and tracks the remote's default branch. To pin a release, add ref: rtk-v<x.y.z> after path:; see Pinning a plugin to a release.
The plugin is opt-in: nothing else in the marketplace depends on it. It does not run rtk init and changes no rtk configuration.
Native plugin installs do not work. This package ships no per-plugin manifest and no flat content directories, so a host that installs it natively gets nothing — and Claude Code raises no error while doing it (ADR-0024).
Contents
| Component | Path | Description |
|---|---|---|
| Hooks | .apm/hooks/ |
route-through-rtk.sh, see Routing hook |
.apm/ is the authoring source and the only thing apm deploys (ADR-0024).
Routing hook
On Claude Code, a PreToolUse hook on the Bash tool passes each call to rtk hook claude. rtk decides whether to rewrite the command, for example git status to rtk git status, and the hook passes rtk's answer back to Claude Code unchanged. A command rtk does not handle runs as written.
- Without rtk on
PATH, the hook exits 0 and prints nothing, so the command runs as written. - Claude Code only. The package targets
claude, and the script does nothing unless it runs from a.claude/hooks/path. - Tested with rtk 0.42.4. Older versions may lack
rtk hook claude.
Rewritten commands may come back pre-approved
rtk's answer can carry permissionDecision: allow, which skips Claude Code's permission prompt for the rewritten command. The hook passes that through. Hooks here are guardrails, not the safety boundary (ADR-0032); if you rely on the permission prompt for Bash, do not install this plugin.
Overlap with a global rtk hook
rtk init -g installs rtk's own hook into ~/.claude/settings.json. Check for one with:
rtk init --show
Running both is harmless: rtk leaves a command that already starts with rtk alone, so the second hook does nothing. It still runs rtk twice per Bash call, so keep one of the two — this plugin for a per-project install that apm keeps up to date, or the global hook for every project on the machine.
Approval
The hook is an executable primitive, so whether it deploys depends on the executables: block in the consuming project's apm.yml:
- No
executables:block: hooks deploy without approval. - With an
executables:block: the hook is parked until it is granted. Grant it in one of two ways, then runapm installand commit theexecutablesentry:-
apm approvewrites the entry and pins it to the hook's content, so a later change to the script needs approval again. -
A hand-written entry under the full package identity is not pinned:
executables: allow: git.rkdr.net/Mortis/Holocron/plugins/rtk: hooks: true
-
The first apm approve in a project creates the block and so turns the gate on. The next install then parks every other package's unapproved executables.
This repo hand-writes its grant in the root apm.yml and does not run apm approve.
"ambiguous duplicate APM-owned hook entry"
apm raises this error when .claude/settings.json holds more byte-identical copies of an APM-owned hook entry than .claude/apm-hooks.json records. It happens when the same hook entry is pasted in by hand or merged in twice. To fix it, remove the duplicate entries from .claude/settings.json, keeping none of the hand-added copies, then run apm install again.
Author
Defame1297