diff --git a/plugins/rtk/.apm/hooks/hooks.json b/plugins/rtk/.apm/hooks/hooks.json new file mode 100644 index 0000000..4e763e9 --- /dev/null +++ b/plugins/rtk/.apm/hooks/hooks.json @@ -0,0 +1,16 @@ +{ + "hooks": { + "PreToolUse": [ + { + "hooks": [ + { + "command": "${CLAUDE_PLUGIN_ROOT}/.apm/hooks/route-through-rtk.sh", + "timeout": 10, + "type": "command" + } + ], + "matcher": "Bash" + } + ] + } +} diff --git a/plugins/rtk/.apm/hooks/route-through-rtk.sh b/plugins/rtk/.apm/hooks/route-through-rtk.sh new file mode 100755 index 0000000..f6119f6 --- /dev/null +++ b/plugins/rtk/.apm/hooks/route-through-rtk.sh @@ -0,0 +1,16 @@ +#!/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 +# 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 + +exec rtk hook claude diff --git a/plugins/rtk/README.md b/plugins/rtk/README.md new file mode 100644 index 0000000..9eee8c5 --- /dev/null +++ b/plugins/rtk/README.md @@ -0,0 +1,84 @@ +# 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`: + +```yaml +dependencies: + apm: + - git: https://git.rkdr.net/Mortis/Holocron.git + path: plugins/rtk +``` + +Then: + +```bash +apm install +``` + +The entry above is unpinned and tracks the remote's default branch. To pin a release, add `ref: rtk-v` after `path:`; see [Pinning a plugin to a release](../../README.md#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](#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: + +```bash +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 run `apm install` and commit the `executables` entry: + - `apm approve` writes 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: + + ```yaml + 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 diff --git a/plugins/rtk/apm.yml b/plugins/rtk/apm.yml new file mode 100644 index 0000000..9ca6a32 --- /dev/null +++ b/plugins/rtk/apm.yml @@ -0,0 +1,29 @@ +name: rtk +version: 0.1.0 +description: A Claude Code hook that routes Bash tool calls through rtk, the token-saving command wrapper, when rtk is installed. +author: + name: Mortis + url: https://git.rkdr.net/Mortis/ +license: MIT +homepage: https://git.rkdr.net/Mortis/Holocron/src/branch/main/plugins/rtk +repository: https://git.rkdr.net/Mortis/Holocron/src/branch/main/plugins/rtk +keywords: + - rtk + - hooks + - tokens +# Which agent platforms to deploy to. +# Resolution order: --target flag > this field > auto-detect from filesystem. +# Accepted values: agent-skills, antigravity, claude, codex, copilot, cursor, gemini, grok-build, kiro, opencode, windsurf +# Claude only: the hook speaks `rtk hook claude`. The script also refuses to act +# outside .claude/hooks/, in case a consumer forces another target. +targets: + - claude +type: hybrid + +dependencies: + apm: [] + mcp: [] +includes: auto +devDependencies: + apm: [] +scripts: {}