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:| Approach | Adoption Rate | Context Overhead | Works with Subagents |
|---|---|---|---|
| CLAUDE.md instructions | ~60-70% | 2000 tokens | β Often ignored |
| PreToolUse hook | 100% | 10 tokens | β Always active |
- 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
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
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.| Command | Scope | Hook | RTK.md | CLAUDE.md | Tokens in Context | Use Case |
|---|---|---|---|---|---|---|
rtk init -g | Global | β | β (10 lines) | @RTK.md | ~10 | Recommended: All projects |
rtk init -g --claude-md | Global | β | β | Full (137 lines) | ~2000 | Legacy compatibility |
rtk init -g --hook-only | Global | β | β | Nothing | 0 | Hook only, no docs |
rtk init | Local | β | β | Full (137 lines) | ~2000 | Single project |
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
