pool icon indicating copy to clipboard operation
pool copied to clipboard

Document RTK (Rust Token Killer) integration via PreToolUse hook

Open czoli1976 opened this issue 2 months ago • 0 comments

Summary

RTK (Rust Token Killer, https://github.com/rtk-ai/rtk) is a transparent CLI proxy that filters, summarizes, and trims command output to reduce LLM token consumption by 60–90% on common dev commands. It's already integrated with Claude Code via rtk hook claude. I'd like to propose documenting a Poolside equivalent so other pool users can get the same benefit.

What RTK does

rtk cargo test runs cargo test but strips compilation noise, groups warnings, and collapses verbose output. It uses rtk rewrite as a single source of truth for which commands to optimize (cargo, git, ls, gh, etc.); commands it doesn't optimize (echo, cd, rm, pwd, pipes) are left untouched — so the overhead is negligible.

The hook

A small POSIX shell script that uses rtk rewrite to decide whether to rewrite a shell command, then emits a Poolside PreToolUse decision JSON:

#!/bin/sh
# Route shell commands through RTK (Rust Token Killer) for token-efficient output.
# Mirrors what `rtk hook claude` does for Claude Code.
# Uses `rtk rewrite` as the single source of truth — only rewrites commands
# RTK actually optimizes (cargo, git, ls, …). Others pass through silently.
input=$(cat)
cmd=$(printf '%s' "$input" | jq -r '.tool_input.cmd // empty' 2>/dev/null) || cmd=""
[ -z "$cmd" ] && exit 0

rewritten=$(rtk rewrite "$cmd" 2>/dev/null) || true
[ -z "$rewritten" ] && exit 0
[ "$rewritten" = "$cmd" ] && exit 0

printf '%s' "$input" | jq -c --arg new_cmd "$rewritten" \
  '{hook_specific_output: {updated_input: ((.tool_input // {}) | .cmd = $new_cmd)}}'

Settings config

# in .poolside/settings.yaml or ~/.config/poolside/settings.yaml
tools:
    shell:
        allow:
            - "rtk *"               # auto-approve RTK-wrapped commands

hooks:
    PreToolUse:
        - name: rtk-rewrite
          matcher: shell
          command: "/absolute/path/to/rtk-rewrite.sh"
          timeout: 10

How it works

  1. Model proposes cargo test via the shell tool
  2. PreToolUse hook fires, extracts tool_input.cmd
  3. rtk rewrite "cargo test" → prints rtk cargo test (RTK exits non-zero but with stdout; hook checks output, not exit code)
  4. Hook emits decision JSON rewriting cmd to rtk cargo test (preserving cwd/env/etc.)
  5. Pool runs rtk cargo test → filtered output

Commands RTK doesn't optimize (echo, cd, pwd, rm) → rtk rewrite produces empty stdout → hook stays silent → command runs as-is through normal allow/deny checks.

Security note

rtk * in the allow list auto-approves any RTK-wrapped command. This is mitigated because rtk rewrite only rewrites a known set of commands — rm, sudo, etc. are not rewritten and still go through the normal allow/deny check. For stricter control, use specific patterns like rtk cargo *, rtk git * instead of the wildcard.

Proposal

Add this as a documented example in the Hooks guide, possibly in an "integrations" or "examples" subsection. It would help users who use output-filtering proxies get the same benefit in Poolside that they get in Claude Code.

Happy to submit the script and config as a PR if there's a preferred location (README examples, a hooks/examples dir, or the docs site).

czoli1976 avatar Sep 16 '26 07:09 czoli1976