claude-memory/graph/fixes/fix-claude-p-nested-session-failure-due-to-claudecode-env-va-250d2f.md
2026-03-01 16:02:49 -06:00

1.6 KiB

id type title tags importance confidence created updated relations
250d2fe0-5866-42f1-b83d-187b3a64fb84 fix Fix: claude -p nested session failure due to CLAUDECODE env var
claude-code
headless
nested-sessions
fix
claude-scheduled
subprocess
0.7 0.8 2026-03-01T06:21:07.380774+00:00 2026-03-01T22:02:48.109296+00:00
target type direction strength edge_id
eed91de9-f5fd-4804-be7c-480d01255ffd RELATED_TO outgoing 0.73 e1e8dcea-d240-438a-bf5b-c15bf04c8bb2
target type direction strength edge_id
ba189013-3890-4464-a22d-cdc3d68d8068 BUILDS_ON outgoing 0.73 e8e3d8cf-6ccf-4b39-a625-466151c1b392
target type direction strength edge_id
cb5e8814-f689-4de0-8854-823358706dec RELATED_TO outgoing 0.9 2cf0cf58-bef2-4ba9-a19d-05ce98b353c1

claude -p Nested Session Error Fix

Problem

claude -p fails with "cannot be launched inside another Claude Code session" when the CLAUDECODE environment variable is set in the calling shell.

Fix

Unset the variable before invoking:

unset CLAUDECODE
claude -p ...

In Python subprocess calls (e.g. from ai-assistant project):

env.pop('CLAUDECODE', None)
  • --permission-mode bypassPermissions cannot be used by root users — must run as non-root
  • --max-budget-usd is not an instant hard cutoff — it can overshoot (set $0.25, spent $0.37); use conservatively

Context

Discovered while building claude-scheduled task runner. Also applies to any project launching Claude Code as a subprocess.