1.6 KiB
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 |
|
0.7 | 0.8 | 2026-03-01T06:21:07.380774+00:00 | 2026-03-01T22:02:48.109296+00:00 |
|
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)
Additional related gotchas
--permission-mode bypassPermissionscannot be used by root users — must run as non-root--max-budget-usdis 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.