Skip to content

Commit 49b9511

Browse files
authored
Merge pull request #485 from jknair/fix/strip-claudecode-env-from-child-processes
fix(adapter-utils): strip Claude Code env vars from child processes
2 parents ef978dd + 1a53567 commit 49b9511

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

packages/adapter-utils/src/server-utils.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,24 @@ export async function runChildProcess(
272272
const onLogError = opts.onLogError ?? ((err, id, msg) => console.warn({ err, runId: id }, msg));
273273

274274
return new Promise<RunProcessResult>((resolve, reject) => {
275-
const mergedEnv = ensurePathInEnv({ ...process.env, ...opts.env });
275+
const rawMerged: NodeJS.ProcessEnv = { ...process.env, ...opts.env };
276+
277+
// Strip Claude Code nesting-guard env vars so spawned `claude` processes
278+
// don't refuse to start with "cannot be launched inside another session".
279+
// These vars leak in when the Paperclip server itself is started from
280+
// within a Claude Code session (e.g. `npx paperclipai run` in a terminal
281+
// owned by Claude Code) or when cron inherits a contaminated shell env.
282+
const CLAUDE_CODE_NESTING_VARS = [
283+
"CLAUDECODE",
284+
"CLAUDE_CODE_ENTRYPOINT",
285+
"CLAUDE_CODE_SESSION",
286+
"CLAUDE_CODE_PARENT_SESSION",
287+
] as const;
288+
for (const key of CLAUDE_CODE_NESTING_VARS) {
289+
delete rawMerged[key];
290+
}
291+
292+
const mergedEnv = ensurePathInEnv(rawMerged);
276293
void resolveSpawnTarget(command, args, opts.cwd, mergedEnv)
277294
.then((target) => {
278295
const child = spawn(target.command, target.args, {

0 commit comments

Comments
 (0)