Skip to content

SessionStart hook appends its exports to CLAUDE_ENV_FILE on every start, so the file grows with each resume or compaction #810

Open

Description

@gathda

scripts/session-lifecycle-hook.mjs (plugin codex 1.0.6) writes its three variables with fs.appendFileSync(process.env.CLAUDE_ENV_FILE, "export NAME='value' ") on every SessionStart. Claude Code fires SessionStart on startup, resume, clear, and compaction and keeps one environment file per session, so the file accumulates one copy of the three lines per event. After one long day the file held 16 copies (4,538 bytes), and because Claude Code prepends the whole file to every Bash tool command as part of a single bash -c string that Windows cuts at about 8,191 characters, Bash commands above about 3 KB began failing with unexpected EOF while looking for matching and the budget kept shrinking. Expected: the hook writes each variable once per session, for example by reading the file first and skipping a variable that is already exported with the same value, or by rewriting its own lines in place. The accumulation and the cut are also reported to Claude Code (the file is never deduplicated there and the Windows command-line limit is unhandled), but the plugin can stop the growth on its own with this change.

Reproduction: install the plugin on Windows with Git Bash, resume or compact the session a few times, then in the Bash tool run tr '' ' ' < /proc/$$/cmdline | grep -c 'export CODEX_COMPANION_SESSION_ID'; the count is the number of SessionStart events so far.

The Claude Code side (the file is never deduplicated there, the Windows command-line limit is unhandled, and double backslashes are halved) is filed as anthropics/claude-code#100936: anthropics/claude-code#100936

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions