[BUG] CLAUDE_ENV_FILE env lost after in-app /resume — hook writes to startup session dir, Bash reads resumed dir (still on 2.1.287; #40391, #24775 auto-closed)
Bug
After an in-app /resume, environment variables that SessionStart hooks write through CLAUDE_ENV_FILE are gone from the Bash tool. The resume-time SessionStart hook is handed a CLAUDE_ENV_FILE in the startup session's directory, while the Bash tool now loads env files from the resumed session's directory, which is empty.
This is the same defect as #40391 and #24775, both auto-closed as stale (the latter's last comment asks for a new issue if still relevant). Still reproducible on 2.1.287 (Linux, WSL2).
Repro
settings.json (or --settings):
{"hooks":{"SessionStart":[{"hooks":[{"type":"command","command":"bash /path/log-hook.sh"}]}]}}
log-hook.sh:
#!/usr/bin/env bash
in="$(cat)"
src="$(jq -r .source <<<"$in")"; sid="$(jq -r .session_id <<<"$in")"
echo "$src $sid $CLAUDE_ENV_FILE" >> /tmp/hook.log
[ -n "$CLAUDE_ENV_FILE" ] && echo "export RX_PROBE=$src-${sid:0:8}" >> "$CLAUDE_ENV_FILE"
- Create any earlier conversation to resume (e.g.
claude -p "say hi" --output-format json, notesession_id). - Start a fresh interactive
claude. Ask it to runecho R0=$RX_PROBE. /resume <that session id>. Ask it to runecho R=$RX_PROBE.
Observed
/tmp/hook.log
startup 8ac7c847 ~/.claude/session-env/8ac7c847-…/sessionstart-hook-7.sh
resume a0147893 ~/.claude/session-env/8ac7c847-…/sessionstart-hook-7.sh ← resumed session, startup dir
Bash before /resume: R0=startup-8ac7c847
Bash after /resume: R= ← empty
~/.claude/session-env/a0147893-…/ ← exists, empty
Both SessionStart runs (startup and resume) write into the startup session's directory; after /resume the Bash tool reads session-env/<resumed id>/, so nothing from either run is applied.
Expected
The resume-time SessionStart hook's CLAUDE_ENV_FILE points into the directory the Bash tool will read for the resumed session (or the Bash tool keeps reading the directory the hooks wrote to), so hook-provided env survives /resume — as the docs describe ("Claude Code runs [the file] as a script preamble before each Bash command").
🤖 Reproduced and drafted with Claude Code