codeflash-agent/plugin/vendor/codex/scripts/session-start-env.sh
Kevin Turcios de6046df8d Replace Node.js SessionStart hook with bash (106ms → 5ms)
The codex session-lifecycle-hook.mjs SessionStart path only appends
two env vars to CLAUDE_ENV_FILE. Rewrite that as a bash script to
avoid ~100ms V8 startup overhead. SessionEnd stays in Node.js since
it needs async broker teardown and process tree management.
2026-04-21 05:07:03 -05:00

25 lines
716 B
Bash
Executable file

#!/bin/bash
# Codex companion SessionStart: export session ID and plugin data dir.
# Replaces the Node.js session-lifecycle-hook.mjs for the SessionStart path
# to avoid ~100ms V8 startup overhead.
set -uo pipefail
INPUT=$(cat)
SESSION_ID=$(echo "$INPUT" | jq -r '.session_id // empty' 2>/dev/null)
[ -z "$CLAUDE_ENV_FILE" ] && exit 0
shell_escape() {
printf "'%s'" "$(printf '%s' "$1" | sed "s/'/'\"\\'\"'/g")"
}
if [ -n "$SESSION_ID" ]; then
printf 'export CODEX_COMPANION_SESSION_ID=%s\n' "$(shell_escape "$SESSION_ID")" >> "$CLAUDE_ENV_FILE"
fi
if [ -n "${CLAUDE_PLUGIN_DATA:-}" ]; then
printf 'export CLAUDE_PLUGIN_DATA=%s\n' "$(shell_escape "$CLAUDE_PLUGIN_DATA")" >> "$CLAUDE_ENV_FILE"
fi
exit 0