Problem
Starting with Claude Code v2.1.71+, launching subtask send from within a Claude Code session fails immediately with:
Error: Claude Code cannot be launched inside another Claude Code session.
Nested sessions share runtime resources and will crash all active sessions.
Root Cause
Claude Code now sets CLAUDECODE=1 in its process environment. When subtask spawns a worker (which runs claude), the child process inherits this env var and hits the nesting guard:
if (process.env.CLAUDECODE && !process.argv.includes("--team-name")) {
// prints error and exits
}
Workaround
Clearing the env var before spawning the worker process works:
CLAUDECODE="" subtask send <task> "prompt"
Suggested Fix
When subtask spawns worker processes, explicitly unset CLAUDECODE from the child process environment:
const env = { ...process.env };
delete env.CLAUDECODE;
// spawn worker with this env
Context
Environment
- macOS (Darwin 25.3.0)
- Node.js
- subtask latest (installed via skill)
Problem
Starting with Claude Code v2.1.71+, launching
subtask sendfrom within a Claude Code session fails immediately with:Root Cause
Claude Code now sets
CLAUDECODE=1in its process environment. When subtask spawns a worker (which runsclaude), the child process inherits this env var and hits the nesting guard:Workaround
Clearing the env var before spawning the worker process works:
Suggested Fix
When subtask spawns worker processes, explicitly unset
CLAUDECODEfrom the child process environment:Context
--team-nameflag is an internal exception used by Claude's own agent teams featureclaude plugin validateanthropics/claude-code#25803, Bug: Subprocess inherits CLAUDECODE=1 env var, preventing SDK usage from Claude Code hooks/plugins anthropics/claude-agent-sdk-python#573Environment