Nesting detection env vars block legitimate automation (CLAUDECODE, CLAUDE_CODE_ENTRYPOINT)
Problem
When spawning Claude Code from a script that itself runs inside a Claude Code session (e.g., an autonomous task runner), the CLAUDECODE and CLAUDE_CODE_ENTRYPOINT environment variables cause the child process to refuse to launch.
Reproduction
# Inside a Claude Code session, try to spawn another:
claude -p "hello" --output-format json
# Fails because CLAUDECODE env var is set
Current Workaround
unset CLAUDECODE CLAUDE_CODE_ENTRYPOINT 2>/dev/null || true
claude -p "$prompt" --output-format json
Use Case
I run an autonomous task runner that polls a queue and executes tasks via headless claude -p sessions. The runner itself is often launched from within a Claude Code session (e.g., ./taskrunner.sh --max 5). The nesting guard blocks this legitimate use case.
Proposal
Add an explicit flag to opt out of nesting detection:
claude -p "prompt" --allow-nested
Or scope the nesting detection to interactive sessions only, since --dangerously-skip-permissions + --output-format json already signals non-interactive intent.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗