Skip to content

Nested Sessions and Auth

Spawning claude inside an existing Claude Code session or agent harness triggers nested-session guards. Both one-shot and daemon modes strip those parent markers through driver.buildChildEnv() while leaving authentication and cloud-provider variables untouched.

Parent env buildChildEnv() shared by one-shot and daemon modes STRIPPED (nested-session markers only) CLAUDECODE · AI_AGENT · CLAUDE_CODE_ENTRYPOINT · SSE_PORT CLAUDE_CODE_CHILD_SESSION · SESSION_* · PARENT_* · SUBAGENT_* PRESERVED (auth, cloud backends, user env) CLAUDE_CODE_OAUTH_TOKEN · CLAUDE_CONFIG_DIR · ANTHROPIC_API_KEY CLAUDE_CODE_USE_BEDROCK · USE_VERTEX · USE_FOUNDRY · PATH INJECTED / DEFAULTED TERM=xterm-256color · CLAUDE_P_FIFO dropped CLAUDE_CODE_FORCE_SESSION_PERSISTENCE=1 (if unset) child `claude` receives clean env without nested-session rejection
driver.buildChildEnv() strips only nested-session markers. Auth and cloud backend variables pass straight through to the child claude process.
Action Environment variables
Stripped (exact) CLAUDECODE, AI_AGENT, CLAUDE_CODE_ENTRYPOINT, CLAUDE_CODE_SSE_PORT, CLAUDE_CODE_CHILD_SESSION, CLAUDE_CODE_SESSION_ID
Stripped (prefix) CLAUDE_CODE_SESSION_*, CLAUDE_CODE_PARENT_*, CLAUDE_CODE_SUBAGENT_*
Preserved CLAUDE_CODE_OAUTH_TOKEN, CLAUDE_CODE_USE_BEDROCK, CLAUDE_CODE_USE_VERTEX, CLAUDE_CODE_USE_FOUNDRY, CLAUDE_CONFIG_DIR, ANTHROPIC_API_KEY, and all other caller variables
Injected / defaulted TERM=xterm-256color, CLAUDE_CODE_FORCE_SESSION_PERSISTENCE=1 (when unset)
Dropped An inherited CLAUDE_P_FIFO. hook.sh embeds the FIFO path, so claude-p exports no FIFO variable.

Because CLAUDE_CODE_* is never blanket-stripped, OAuth, Bedrock, Vertex, and Foundry configurations work without wrapper-specific flags:

Terminal window
CLAUDE_CODE_USE_VERTEX=1 \
CLOUD_ML_REGION=us-east5 \
ANTHROPIC_VERTEX_PROJECT_ID=my-gcp-project \
npx claude-p --dangerously-skip-permissions "Reply OK."

claude-p does not forward interactive tool-approval prompts to your terminal. For unattended runs, pick one permission policy:

Flag Effect
--dangerously-skip-permissions Bypasses tool permission prompts; claude-p auto-accepts the startup confirmation modal.
--permission-mode <mode> Sets acceptEdits, auto, bypassPermissions, manual, default, dontAsk, or plan.
--allowedTools / --disallowedTools Restricts which tools claude may run without prompting. Repeatable and variadic; every rule is forwarded in order.
Terminal window
npx claude-p \
--permission-mode dontAsk \
--allowedTools "Read,Grep,Glob" \
--output-format json \
"Find all TODO comments in src/."

If a tool still needs approval, Claude Code fires PermissionRequest and claude-p fails fast instead of hanging until --timeout: one-shot exits 2 (PermissionPromptBlocked), and the daemon emits a permission_prompt_blocked result frame and returns to idle.