Repository navigation
Closed as not planned
Labels
area:corearea:toolsbugSomething isn't workingSomething isn't workinghas reproHas detailed reproduction stepsHas detailed reproduction stepsplatform:macosIssue specifically occurs on macOSIssue specifically occurs on macOSstaleIssue is inactiveIssue is inactive
Description
Environment
- Claude Code version: 2.0.76
- OS: macOS (Darwin 25.1.0)
- Shell: bash
Description
According to the hooks documentation, SessionStart hooks should receive CLAUDE_ENV_FILE - a path to a file where export statements can be written to persist environment variables to subsequent Bash tool calls.
However, CLAUDE_ENV_FILE is an empty string when the hook runs, so the documented mechanism doesn't work.
Steps to Reproduce
- Create a SessionStart hook in
~/.claude/hooks/session-start.sh:
#!/bin/bash
# Try to use CLAUDE_ENV_FILE as documented
if [ -n "$CLAUDE_ENV_FILE" ]; then
echo "export MY_SESSION_VAR=\"test\"" >> "$CLAUDE_ENV_FILE"
fi
# Debug: log the actual value
echo "CLAUDE_ENV_FILE='$CLAUDE_ENV_FILE'" >> /tmp/claude-hook-debug.log- Register it in
~/.claude/settings.json:
{
"hooks": {
"SessionStart": [
{
"matcher": "*",
"hooks": [
{
"type": "command",
"command": "~/.claude/hooks/session-start.sh"
}
]
}
]
}
}-
Start a new Claude Code session
-
Run a Bash command to check environment:
echo "MY_SESSION_VAR: $MY_SESSION_VAR"Expected Behavior
CLAUDE_ENV_FILEshould contain a path to a file- Variables written to that file should be available in subsequent Bash commands
Actual Behavior
CLAUDE_ENV_FILEis an empty string (exists but has no value)- The
[ -n "$CLAUDE_ENV_FILE" ]check fails - No environment variables are persisted
Additional Context
From within a Bash tool call in the session:
$ env | grep -i claude
CLAUDE_CODE_ENTRYPOINT=cli
CLAUDECODE=1
CLAUDE_ENV_FILE is not set or is empty - not provided with a path as documented.
The hook itself runs correctly (other parts of the hook execute fine, like creating files), confirming the issue is specifically with CLAUDE_ENV_FILE not being populated.
Reacted by Nico, Tim Frison and Sauyon Lee
Metadata
Metadata
Assignees
Labels
area:corearea:toolsbugSomething isn't workingSomething isn't workinghas reproHas detailed reproduction stepsHas detailed reproduction stepsplatform:macosIssue specifically occurs on macOSIssue specifically occurs on macOSstaleIssue is inactiveIssue is inactive
Activity
excessivereason commentedon Dec 31, 2025
@claude You can start work on this. thanks!
piercelamb commentedon Jan 28, 2026
Bumping this thread, would also like to see this fixed
Oloremo commentedon Jan 29, 2026
Really needed to extend oTel metrics.
hb-man commentedon Feb 11, 2026
still a problem :c
ryan-dyer-sp commentedon Feb 18, 2026
Doesnt seem to be an issue with Claude CLI version 2.1.45
acushner-rippling commentedon Mar 11, 2026
/clearcausesCLAUDE_ENV_FILEto point to the wrong sessionVersion: 2.1.70 (macOS)
Finding
CLAUDE_ENV_FILEworks correctly on freshstartupbut after/clear, it still points to the previous session's env file path. The hook receives the correct newsession_idin stdin JSON, but writes it to the old session's env file — which the new session never sources.Evidence
Added debug logging to a
SessionStarthook:Impact
Any
SessionStarthook that writes toCLAUDE_ENV_FILE(e.g., exportingCLAUDE_SESSION_ID) will write the correct value to the wrong file. SubsequentBashtool calls retain the stale env from the pre-/clearsession.Repro
SessionStarthook that logs$CLAUDE_ENV_FILEand stdinsession_idclaudefresh — observe matching paths/clear— observeCLAUDE_ENV_FILEpath still contains the old session IDThis is consistent with #14433 (closed as stale). The
SessionStartevent fires correctly after/clear, but the env file path is not regenerated for the new session.github-actions commentedon Apr 9, 2026
Closing for now — inactive for too long. Please open a new issue if this is still relevant.
github-actions commentedon Apr 17, 2026
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.