rtk-ai/rtk

RTK proxy not used by Claude Code subagents — massive token leak in multi-agent workflows

Open

#1820 aperta il 9 mag 2026

Vedi su GitHub
 (5 commenti) (4 reazioni) (1 assegnatario)Rust (2914 fork)batch import
area:clibughelp wantedpriority:high

Metriche repository

Star
 (48.085 star)
Metriche merge PR
 (Merge medio 11g 1h) (45 PR mergiate in 30 g)

Descrizione

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:

  1. 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
  2. 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
  3. Claude Code hook inheritance — work with Anthropic to ensure PreToolUse hooks 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 rtk prefix 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: PreToolUse in .claude/settings.json

Guida contributor