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.
This commit is contained in:
Kevin Turcios 2026-04-21 05:07:03 -05:00
parent 42b855899f
commit de6046df8d
3 changed files with 27 additions and 2 deletions

View file

@ -10,7 +10,7 @@
},
{
"type": "command",
"command": "node \"${CLAUDE_PLUGIN_ROOT}/vendor/codex/scripts/session-lifecycle-hook.mjs\" SessionStart",
"command": "bash \"${CLAUDE_PLUGIN_ROOT}/vendor/codex/scripts/session-start-env.sh\"",
"timeout": 5
}
]

View file

@ -5,7 +5,7 @@
"hooks": [
{
"type": "command",
"command": "node \"${CLAUDE_PLUGIN_ROOT}/vendor/codex/scripts/session-lifecycle-hook.mjs\" SessionStart",
"command": "bash \"${CLAUDE_PLUGIN_ROOT}/vendor/codex/scripts/session-start-env.sh\"",
"timeout": 5
}
]

View file

@ -0,0 +1,25 @@
#!/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