Skip to main content

Overview

RTK integrates with Claude Code to automatically optimize command outputs, reducing token consumption by 60-90% across all your coding sessions. The integration uses a PreToolUse hook that transparently rewrites commands before execution.
What’s a hook? Claude Code hooks are scripts that run before/after tool execution. RTK’s hook intercepts Bash commands (like git status) and rewrites them to rtk git status before the shell sees them. This is completely transparent to Claude.

Why Hooks > CLAUDE.md Instructions

There are two ways to tell Claude Code about RTK: The hook-first approach is superior because:
  • Guaranteed execution: Commands are rewritten automatically, regardless of whether Claude follows instructions
  • Minimal context: Only 10 lines in RTK.md vs 137 lines of instruction boilerplate
  • Subagent-proof: Works in nested conversations where CLAUDE.md may be ignored
  • Zero friction: Claude never needs to “remember” to use rtk
1

Hook-first mode (recommended)

Installs:
  • Hook script at ~/.claude/hooks/rtk-rewrite.sh
  • Slim awareness doc at ~/.claude/RTK.md (10 lines)
  • Reference @RTK.md in ~/.claude/CLAUDE.md
  • Registration in ~/.claude/settings.json
2

Legacy mode (compatibility)

Injects 137-line instruction block into ~/.claude/CLAUDE.md. No hook, Claude must follow instructions manually.

Installation Walkthrough

Step 1: Check Prerequisites

Verify RTK is installed:
Name collision: There are two different “rtk” packages. If rtk gain doesn’t work, you installed the wrong one (Rust Type Kit instead of Rust Token Killer). See Installation Guide.

Step 2: Run Global Init

The default mode installs the hook and minimal context:
This will:
  1. ✅ Create ~/.claude/hooks/rtk-rewrite.sh (executable)
  2. ✅ Create ~/.claude/RTK.md (10 lines, meta command reference)
  3. ✅ Add @RTK.md to ~/.claude/CLAUDE.md (or create if missing)
  4. ⚙️ Prompt: “Patch existing settings.json? [y/N]“

Step 3: Settings.json Patching

Claude Code needs to know the hook exists. RTK can patch ~/.claude/settings.json automatically:
What gets added to settings.json:
RTK creates a backup at ~/.claude/settings.json.bak before making changes.

Step 4: Restart Claude Code

Critical: The hook only activates after a restart.
  1. Close Claude Code completely
  2. Reopen Claude Code
  3. Test in any conversation:
You should see ultra-compact output instead of the raw git output. The command was transparently rewritten to rtk git status.

Step 5: Verify Installation

Check the hook is active:
Expected output:

Installation Modes Comparison

All modes support both global (--global) and local (no flag) scope. Global applies to all Claude Code sessions, local applies to the current project only.

Hook-first Mode (Default)

  • ✅ 100% command adoption
  • ✅ 10 tokens in context
  • ✅ Works with all subagents
  • ⚠️ Requires Unix (macOS/Linux)

Legacy Mode

  • ⚠️ 60-70% adoption (depends on Claude following instructions)
  • ⚠️ 2000 tokens in context
  • ❌ Subagents may ignore instructions
  • ✅ Works on Windows

Hook-only Mode

  • ✅ Zero context footprint
  • ⚠️ Claude won’t know about meta commands (rtk gain, rtk discover, rtk proxy)
  • Use case: Minimal setup, hook-only automation

Local Project Mode

Injects full instructions into ./CLAUDE.md (current directory). No hook, no global config. Use for single-project setup or when you don’t have write access to ~/.claude/.

Restart Required

Claude Code must be restarted after installation for the hook to activate. Without a restart, commands will not be rewritten.
How to verify:
  1. Close Claude Code completely (quit the application)
  2. Reopen Claude Code
  3. Open any conversation
  4. Type: git status
  5. Inspect output — should be ultra-compact (3-5 lines, not 20+ lines)

Verification Steps

1. Check Hook Status

Look for:
  • ✅ Hook exists and is executable
  • ✅ RTK.md present (slim mode)
  • ✅ settings.json configured

2. Test Command Rewriting

In a Claude Code conversation, type:
Expected: Compact output like:
Unexpected (hook not working): Full git output with 20+ lines.

3. Check Token Savings

After a session, verify tracking:
Should show commands like rtk git status, rtk cargo test, etc. with token savings percentages.

4. Audit Hook Activity (Optional)

Enable audit logging to see every rewrite:
Check logs:
Format: timestamp | action | original | rewritten Example:

Troubleshooting

Hook Not Working

Symptom: Commands still show raw output after restart. Checks:
  1. Verify hook is registered:
    Should show the hook path.
  2. Verify hook is executable:
    Should show -rwxr-xr-x (executable).
  3. Verify dependencies:
    Both must be available.
  4. Re-run setup:

Settings.json Patching Failed

Symptom: rtk init --global reports error during settings.json patch. Solutions:
  1. Check if settings.json is valid JSON:
  2. Restore from backup:
  3. Use manual patching:

Windows Users

Symptom: Hook installation fails on Windows. Solution: Use legacy mode instead:
Hooks require Unix (macOS/Linux). Windows users should use WSL or legacy CLAUDE.md injection.

Migration from Legacy Mode

If you previously used rtk init --global --claude-md, you can migrate to hook-first:
This will:
  • ✅ Install hook and RTK.md
  • ✅ Remove 137-line RTK block from CLAUDE.md
  • ✅ Replace with @RTK.md reference (10 lines)
  • ✅ Patch settings.json
The migration is automatic and preserves any custom content in CLAUDE.md.

Uninstalling

To completely remove RTK integration:
Removes:
  • Hook script (~/.claude/hooks/rtk-rewrite.sh)
  • RTK.md (~/.claude/RTK.md)
  • @RTK.md reference from CLAUDE.md
  • Hook entry from settings.json
Restart Claude Code after uninstalling. To restore from backup if needed:

Next Steps

Hook Architecture

Learn how the auto-rewrite hook works

Configuration

Customize RTK behavior and settings