Before submitting
Problem
When using Claude Code's experimental agent teams (CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1), each spawned subagent inherits the global plugin configuration, meaning claude-mem injects its full context (recent observations, $CMEM block) into every subagent's context window.
This is wasteful for most subagent use cases:
- Subagents are typically focused, single-task workers (e.g. fix a specific file, run a search, apply a transformation). They don't benefit from cross-session memory.
- Each agent gets the full observation injection, multiplying token costs by the number of agents spawned in parallel.
- For agent teams with 3–5 simultaneous subagents, the context overhead scales linearly with no benefit.
The Agent tool in Claude Code has no env or mcpServers parameter to exclude plugins per-spawn, so there is currently no clean way to opt out.
Proposed Solution
Add a mechanism to skip context injection when claude-mem detects it is running inside a subagent. Claude Code sets environment variables that could serve as a detection signal (e.g. a parent agent ID or spawn depth indicator).
Two possible approaches:
Option A: Environment variable flag
Respect a CLAUDE_MEM_DISABLED=1 env var. Users could set this selectively in agent prompts once Claude Code exposes per-agent env injection, or globally when subagent-only workflows are in use.
Option B: Auto-detect subagent context
Check for a Claude Code env var that indicates the current process is a spawned subagent (e.g. CLAUDE_CODE_IS_SUBAGENT, agent depth, or a parent session ID). If detected, skip the SessionStart context injection automatically or reduce it to a minimal stub.
Option C: Configurable injection depth
Add a setting like CLAUDE_MEM_INJECT_DEPTH=0 (main session only) vs 1 (main + direct subagents) vs unlimited. Default could remain unlimited for backwards compatibility.
Workaround (current)
Users can tell the agent to ignore injected context in the spawn prompt:
Ignore any claude-mem context injected at the start of your context window.
Do not use the mem-search or timeline tools.
This is fragile and doesn't prevent the tokens from being consumed.
Environment
- claude-mem: 10.5.6
- Platform: macOS Darwin 25.3.0
- Claude Code: 2.1.74
- Feature flag:
CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1
Before submitting
Problem
When using Claude Code's experimental agent teams (
CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1), each spawned subagent inherits the global plugin configuration, meaning claude-mem injects its full context (recent observations,$CMEMblock) into every subagent's context window.This is wasteful for most subagent use cases:
The
Agenttool in Claude Code has noenvormcpServersparameter to exclude plugins per-spawn, so there is currently no clean way to opt out.Proposed Solution
Add a mechanism to skip context injection when claude-mem detects it is running inside a subagent. Claude Code sets environment variables that could serve as a detection signal (e.g. a parent agent ID or spawn depth indicator).
Two possible approaches:
Option A: Environment variable flag
Respect a
CLAUDE_MEM_DISABLED=1env var. Users could set this selectively in agent prompts once Claude Code exposes per-agent env injection, or globally when subagent-only workflows are in use.Option B: Auto-detect subagent context
Check for a Claude Code env var that indicates the current process is a spawned subagent (e.g.
CLAUDE_CODE_IS_SUBAGENT, agent depth, or a parent session ID). If detected, skip theSessionStartcontext injection automatically or reduce it to a minimal stub.Option C: Configurable injection depth
Add a setting like
CLAUDE_MEM_INJECT_DEPTH=0(main session only) vs1(main + direct subagents) vsunlimited. Default could remainunlimitedfor backwards compatibility.Workaround (current)
Users can tell the agent to ignore injected context in the spawn prompt:
This is fragile and doesn't prevent the tokens from being consumed.
Environment
CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1