From 40bf9da8d306c5965576ef61d4c3cf9b2b3ba42b Mon Sep 17 00:00:00 2001 From: Manav Agarwal Date: Sun, 23 Aug 2026 01:45:46 +0530 Subject: [PATCH 1/2] Fix duplicate SessionStart exports in CLAUDE_ENV_FILE --- plugins/codex/scripts/session-lifecycle-hook.mjs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/plugins/codex/scripts/session-lifecycle-hook.mjs b/plugins/codex/scripts/session-lifecycle-hook.mjs index 778571e6c..0e3def730 100644 --- a/plugins/codex/scripts/session-lifecycle-hook.mjs +++ b/plugins/codex/scripts/session-lifecycle-hook.mjs @@ -36,7 +36,19 @@ function appendEnvVar(name, value) { if (!process.env.CLAUDE_ENV_FILE || value == null || value === "") { return; } - fs.appendFileSync(process.env.CLAUDE_ENV_FILE, `export ${name}=${shellEscape(value)}\n`, "utf8"); + + const line = `export ${name}=${shellEscape(value)}\n`; + + try { + const existing = fs.readFileSync(process.env.CLAUDE_ENV_FILE, "utf8"); + if (existing.includes(line)) { + return; + } + } catch { + // File doesn't exist yet + } + + fs.appendFileSync(process.env.CLAUDE_ENV_FILE, line, "utf8"); } function cleanupSessionJobs(cwd, sessionId) { From 77d09cf6fd662db7ca5faee3a39e7984bfac4aea Mon Sep 17 00:00:00 2001 From: Manav Agarwal Date: Sun, 23 Aug 2026 02:13:06 +0530 Subject: [PATCH 2/2] Handle repeated SessionStart environment updates --- .../codex/scripts/session-lifecycle-hook.mjs | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/plugins/codex/scripts/session-lifecycle-hook.mjs b/plugins/codex/scripts/session-lifecycle-hook.mjs index 0e3def730..34a22646b 100644 --- a/plugins/codex/scripts/session-lifecycle-hook.mjs +++ b/plugins/codex/scripts/session-lifecycle-hook.mjs @@ -37,18 +37,27 @@ function appendEnvVar(name, value) { return; } - const line = `export ${name}=${shellEscape(value)}\n`; + const line = `export ${name}=${shellEscape(value)}`; + + let lines = []; try { - const existing = fs.readFileSync(process.env.CLAUDE_ENV_FILE, "utf8"); - if (existing.includes(line)) { - return; - } + lines = fs + .readFileSync(process.env.CLAUDE_ENV_FILE, "utf8") + .split("\n") + .filter(Boolean) + .filter((l) => !l.startsWith(`export ${name}=`)); } catch { - // File doesn't exist yet + // File doesn't exist yet. } - fs.appendFileSync(process.env.CLAUDE_ENV_FILE, line, "utf8"); + lines.push(line); + + fs.writeFileSync( + process.env.CLAUDE_ENV_FILE, + lines.join("\n") + "\n", + "utf8" + ); } function cleanupSessionJobs(cwd, sessionId) {