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_FILE should contain a path to a file
- Variables written to that file should be available in subsequent Bash commands
Actual Behavior
CLAUDE_ENV_FILE is 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.
Environment
Description
According to the hooks documentation,
SessionStarthooks should receiveCLAUDE_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_FILEis an empty string when the hook runs, so the documented mechanism doesn't work.Steps to Reproduce
~/.claude/hooks/session-start.sh:~/.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:
Expected Behavior
CLAUDE_ENV_FILEshould contain a path to a fileActual Behavior
CLAUDE_ENV_FILEis an empty string (exists but has no value)[ -n "$CLAUDE_ENV_FILE" ]check failsAdditional Context
From within a Bash tool call in the session:
CLAUDE_ENV_FILEis 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_FILEnot being populated.