52 lines
1.6 KiB
Markdown
52 lines
1.6 KiB
Markdown
---
|
|
id: 250d2fe0-5866-42f1-b83d-187b3a64fb84
|
|
type: fix
|
|
title: "Fix: claude -p nested session failure due to CLAUDECODE env var"
|
|
tags: [claude-code, headless, nested-sessions, fix, claude-scheduled, subprocess]
|
|
importance: 0.7
|
|
confidence: 0.8
|
|
created: "2026-03-01T06:21:07.380774+00:00"
|
|
updated: "2026-03-01T22:02:48.109296+00:00"
|
|
relations:
|
|
- target: eed91de9-f5fd-4804-be7c-480d01255ffd
|
|
type: RELATED_TO
|
|
direction: outgoing
|
|
strength: 0.73
|
|
edge_id: e1e8dcea-d240-438a-bf5b-c15bf04c8bb2
|
|
- target: ba189013-3890-4464-a22d-cdc3d68d8068
|
|
type: BUILDS_ON
|
|
direction: outgoing
|
|
strength: 0.73
|
|
edge_id: e8e3d8cf-6ccf-4b39-a625-466151c1b392
|
|
- target: cb5e8814-f689-4de0-8854-823358706dec
|
|
type: RELATED_TO
|
|
direction: outgoing
|
|
strength: 0.9
|
|
edge_id: 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:
|
|
```bash
|
|
unset CLAUDECODE
|
|
claude -p ...
|
|
```
|
|
|
|
In Python subprocess calls (e.g. from ai-assistant project):
|
|
```python
|
|
env.pop('CLAUDECODE', None)
|
|
```
|
|
|
|
## Additional related gotchas
|
|
- `--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.
|
|
|