Problem
The SessionStart hook injects the full <context_window_protection> block into every Claude Code session, including subagents spawned via the Agent tool.
The <ctx_commands> section (~400 tokens) contains instructions for user-facing commands (ctx doctor, ctx purge, ctx upgrade, ctx stats) that are useless in subagent contexts — users cannot type these commands in a subagent session.
This wastes ~400 tokens per subagent spawn. In workflows that use multiple agents (e.g., plan-mode with Explore + Plan agents), this adds up quickly.
Where
hooks/routing-block.mjs, lines 64-78 — the <ctx_commands> section
hooks/sessionstart.mjs, line 35 — additionalContext = ROUTING_BLOCK (always the full block, no conditional logic)
Suggested fix
- Detect subagent context — either via an environment variable (e.g.,
CLAUDE_PARENT_SESSION_ID) or a field in the stdin JSON that Claude Code passes to hooks
- When in a subagent session, omit the
<ctx_commands> section from the routing block (or omit the entire routing block if MCP tools aren't available to subagents anyway)
A simple approach would be to split createRoutingBlock() into core guidance + user commands, and only include the user commands section for root sessions.
Environment
- context-mode version: 1.0.75
- Claude Code CLI
Problem
The
SessionStarthook injects the full<context_window_protection>block into every Claude Code session, including subagents spawned via theAgenttool.The
<ctx_commands>section (~400 tokens) contains instructions for user-facing commands (ctx doctor,ctx purge,ctx upgrade,ctx stats) that are useless in subagent contexts — users cannot type these commands in a subagent session.This wastes ~400 tokens per subagent spawn. In workflows that use multiple agents (e.g., plan-mode with Explore + Plan agents), this adds up quickly.
Where
hooks/routing-block.mjs, lines 64-78 — the<ctx_commands>sectionhooks/sessionstart.mjs, line 35 —additionalContext = ROUTING_BLOCK(always the full block, no conditional logic)Suggested fix
CLAUDE_PARENT_SESSION_ID) or a field in the stdin JSON that Claude Code passes to hooks<ctx_commands>section from the routing block (or omit the entire routing block if MCP tools aren't available to subagents anyway)A simple approach would be to split
createRoutingBlock()into core guidance + user commands, and only include the user commands section for root sessions.Environment