SessionStart hook appends duplicate exports to $CLAUDE_ENV_FILE on every resume - breaks Claude Code Bash tool on Windows (long-lived sessions)
What happens
The plugin's SessionStart hook emits env exports (CODEX_COMPANION_SESSION_ID, CODEX_COMPANION_TRANSCRIPT_PATH, CLAUDE_PLUGIN_DATA). On every session resume/compact, the same 3 lines are appended again to the session's env file (~/.claude/session-env/<session-id>/sessionstart-hook-N.sh) with no deduplication.
Observed damage
On a long-lived session (30+ resumes/compacts) we measured the same 3 exports appended 15 and 16 times across two hook files (~15 KB). Claude Code concatenates these files into every bash -c invocation, which is silently truncated at ~8 KB on Windows/MSYS — the truncation landed inside an open quote and every Bash call died with:
/usr/bin/bash: -c: line 83: unexpected EOF while looking for matching `''
(even echo ok). Full analysis: https://github.com/anthropics/claude-code/issues/83243
Repro: keep a session alive across ~15+ resumes with the plugin enabled on Windows, then run any Bash command.
Fix verified: removing the accumulated sessionstart-hook-*.sh + restarting the session host restores Bash immediately (same session, no data loss).
Suggested fix in the plugin
Make the hook idempotent — e.g. check whether the exports are already present (last-wins) before appending, or write a single stable block per variable instead of appending on every SessionStart event.
Environment: Windows 11 Pro (26200), Claude Code v2.1.310.