diff --git a/plugins/codex/scripts/session-lifecycle-hook.mjs b/plugins/codex/scripts/session-lifecycle-hook.mjs index 778571e6c..e71aede92 100644 --- a/plugins/codex/scripts/session-lifecycle-hook.mjs +++ b/plugins/codex/scripts/session-lifecycle-hook.mjs @@ -32,11 +32,51 @@ function shellEscape(value) { return `'${String(value).replace(/'/g, `'\"'\"'`)}'`; } -function appendEnvVar(name, value) { - if (!process.env.CLAUDE_ENV_FILE || value == null || value === "") { +const MANAGED_ENV_VARS = [SESSION_ID_ENV, TRANSCRIPT_PATH_ENV, PLUGIN_DATA_ENV]; + +function isManagedExport(line) { + return MANAGED_ENV_VARS.some((name) => line.startsWith(`export ${name}=`)); +} + +// Rewrite this plugin's exports instead of appending them. SessionStart fires on +// startup, on resume and on every compaction, so appending grew CLAUDE_ENV_FILE by +// three lines every time and nothing ever pruned it. Only the last assignment of a +// name takes effect, so every earlier copy did nothing but grow the file. Claude Code +// inlines the whole file into the single `bash -c