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.mdvs 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)
- Hook script at
~/.claude/hooks/rtk-rewrite.sh - Slim awareness doc at
~/.claude/RTK.md(10 lines) - Reference
@RTK.mdin~/.claude/CLAUDE.md - Registration in
~/.claude/settings.json
2
Legacy mode (compatibility)
~/.claude/CLAUDE.md. No hook, Claude must follow instructions manually.Installation Walkthrough
Step 1: Check Prerequisites
Verify RTK is installed:Step 2: Run Global Init
The default mode installs the hook and minimal context:- ✅ Create
~/.claude/hooks/rtk-rewrite.sh(executable) - ✅ Create
~/.claude/RTK.md(10 lines, meta command reference) - ✅ Add
@RTK.mdto~/.claude/CLAUDE.md(or create if missing) - ⚙️ 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:
~/.claude/settings.json.bak before making changes.
Step 4: Restart Claude Code
Critical: The hook only activates after a restart.- Close Claude Code completely
- Reopen Claude Code
- Test in any conversation:
rtk git status.
Step 5: Verify Installation
Check the hook is active: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
./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
How to verify:- Close Claude Code completely (quit the application)
- Reopen Claude Code
- Open any conversation
- Type:
git status - Inspect output — should be ultra-compact (3-5 lines, not 20+ lines)
Verification Steps
1. Check Hook Status
- ✅ Hook exists and is executable
- ✅ RTK.md present (slim mode)
- ✅ settings.json configured
2. Test Command Rewriting
In a Claude Code conversation, type:3. Check Token Savings
After a session, verify tracking:rtk git status, rtk cargo test, etc. with token savings percentages.
4. Audit Hook Activity (Optional)
Enable audit logging to see every rewrite:timestamp | action | original | rewritten
Example:
Troubleshooting
Hook Not Working
Symptom: Commands still show raw output after restart. Checks:-
Verify hook is registered:
Should show the hook path.
-
Verify hook is executable:
Should show
-rwxr-xr-x(executable). -
Verify dependencies:
Both must be available.
-
Re-run setup:
Settings.json Patching Failed
Symptom:rtk init --global reports error during settings.json patch.
Solutions:
-
Check if settings.json is valid JSON:
-
Restore from backup:
-
Use manual patching:
Windows Users
Symptom: Hook installation fails on Windows. Solution: Use legacy mode instead:Migration from Legacy Mode
If you previously usedrtk init --global --claude-md, you can migrate to hook-first:
- ✅ Install hook and RTK.md
- ✅ Remove 137-line RTK block from CLAUDE.md
- ✅ Replace with
@RTK.mdreference (10 lines) - ✅ Patch settings.json
Uninstalling
To completely remove RTK integration:- Hook script (
~/.claude/hooks/rtk-rewrite.sh) - RTK.md (
~/.claude/RTK.md) - @RTK.md reference from CLAUDE.md
- Hook entry from settings.json
Next Steps
Hook Architecture
Learn how the auto-rewrite hook works
Configuration
Customize RTK behavior and settings
