RTK proxy not used by Claude Code subagents — massive token leak in multi-agent workflows
#1,820 opened on 2026年5月9日
Repository metrics
- Stars
- (48,085 stars)
- PR merge metrics
- (平均マージ 11d 1h) (30d で 45 merged PRs)
説明
Problem
When Claude Code spawns subagents (via the Task/Agent tool), those subagent sessions use raw CLI commands (git, grep, mongosh, curl, cat) instead of going through RTK proxy. The RTK hook that rewrites commands only applies in the main agent context — subagent shell environments do not inherit it.
This means RTK's token compression is completely bypassed in the exact scenario where it matters most: multi-agent workflows that generate massive CLI output.
Evidence from real session (2026-05-10)
Main agent correctly uses RTK for git commands (hook rewrite works). Three background agents were spawned — none used RTK:
| Subagent | Raw commands used | Tokens consumed |
|---|---|---|
dodo-researcher |
raw curl, web searches |
34,585 tokens |
scenario-scanner |
raw grep, cat |
48,557 tokens |
db-scanner |
raw mongosh commands |
29,854 tokens |
| Total subagent waste | ~113K tokens |
All of these commands would have been compressed 60-90% by RTK if the proxy had been active. In a typical agent swarm (4-10 agents per task), this multiplies further.
Steps to Reproduce
# In Claude Code main context, RTK works:
git status → rtk git status ✓
# In subagent context (Task tool), RTK is bypassed:
git status → git status ✗ (raw, no RTK compression)
The subagent spawned by Claude Code's Task tool gets a fresh shell environment. The RTK hook (configured in .claude/settings.json as a PreToolUse hook) fires only for the parent agent's tool calls — child agent tool calls do not trigger the parent's hooks.
Expected Behavior
RTK hook should be inherited by subagent contexts, or RTK should provide a mechanism to inject itself into subagent shell environments. Possible approaches:
- Shell-level injection — RTK installs shell aliases/functions (
git() { rtk git "$@"; }) in the user's shell profile so any Bash invocation (including subagent shells) automatically routes through RTK - Environment variable propagation — RTK sets an env var (e.g.,
RTK_ACTIVE=1) that a lightweight shell wrapper checks, so subagent shells inherit the proxy behavior - Claude Code hook inheritance — work with Anthropic to ensure
PreToolUsehooks propagate to subagent contexts (this may be an upstream Claude Code issue)
Impact
- Agent swarm workflows (4-10 agents): Token savings from RTK are completely lost — the primary use case where efficiency matters most
- Real cost: ~113K wasted tokens in a single 3-agent session; extrapolates to 200-500K+ for larger swarms
- User workaround: Manually adding
rtkprefix instructions to every subagent prompt, which is fragile and error-prone
Environment
- RTK version: 0.39.x
- OS: macOS (Darwin 25.3.0)
- Claude Code: latest (claude-opus-4-6 model)
- Hook type:
PreToolUsein.claude/settings.json