Preflight Checklist
What's Wrong?
On Windows, CLAUDE_ENV_FILE is correctly provided to SessionStart hooks and the env file is written with valid export statements. However, subsequent Bash tool calls do not have access to the exported environment variables — the file is never sourced.
This differs from #15840 (env file not provided) and #14433 (not sourced after /clear). Here, the file IS provided and written on initial session start, but never sourced for any Bash tool call.
Reproduction Steps
- Create a
SessionStart hook that writes to CLAUDE_ENV_FILE:
{
"hooks": {
"SessionStart": [{
"hooks": [{
"type": "command",
"command": "node -e \"const fs=require('fs'); if(process.env.CLAUDE_ENV_FILE) fs.appendFileSync(process.env.CLAUDE_ENV_FILE, 'export MY_TEST_VAR=hello\n');\""
}]
}]
}
}
- Start a new Claude Code session on Windows
- Ask Claude to run:
echo $MY_TEST_VAR
- Result: empty. The variable is not set.
Diagnostic Evidence
Added debug logging to the SessionStart hook to write process.env.CLAUDE_ENV_FILE to a file:
CLAUDE_ENV_FILE=C:\Users\<user>\.claude\session-env\<session-id>\sessionstart-hook-1.sh
Contents of sessionstart-hook-1.sh (correctly written):
export WIZ_SCRIPTS="C:/Users/<user>/.claude/plugins/cache/lansweeper-tools/wiz/3.7.0/scripts"
export TMPDIR="/tmp/claude"
export CLAUDE_CODE_DISABLE_1M_CONTEXT=1
Bash tool call results:
WIZ_SCRIPTS= (empty)
TMPDIR=/tmp (should be /tmp/claude)
CLAUDE_ENV_FILE= (empty)
None of the exported variables are available. The file exists, has correct content, but is not sourced.
Expected Behavior
Per the hooks documentation: "Claude Code will source this file before each Bash command, making the environment persistent across all commands."
Environment variables written to CLAUDE_ENV_FILE during SessionStart should be available in subsequent Bash tool calls on Windows.
Environment
- Claude Code version: 2.1.33
- OS: Windows 11 Enterprise 10.0.26200
- Shell: Git Bash (via Claude Code's default Windows shell)
- Node.js: v22.20.0
Related Issues
Preflight Checklist
What's Wrong?
On Windows,
CLAUDE_ENV_FILEis correctly provided toSessionStarthooks and the env file is written with validexportstatements. However, subsequent Bash tool calls do not have access to the exported environment variables — the file is never sourced.This differs from #15840 (env file not provided) and #14433 (not sourced after
/clear). Here, the file IS provided and written on initial session start, but never sourced for any Bash tool call.Reproduction Steps
SessionStarthook that writes toCLAUDE_ENV_FILE:{ "hooks": { "SessionStart": [{ "hooks": [{ "type": "command", "command": "node -e \"const fs=require('fs'); if(process.env.CLAUDE_ENV_FILE) fs.appendFileSync(process.env.CLAUDE_ENV_FILE, 'export MY_TEST_VAR=hello\n');\"" }] }] } }echo $MY_TEST_VARDiagnostic Evidence
Added debug logging to the SessionStart hook to write
process.env.CLAUDE_ENV_FILEto a file:Contents of
sessionstart-hook-1.sh(correctly written):Bash tool call results:
None of the exported variables are available. The file exists, has correct content, but is not sourced.
Expected Behavior
Per the hooks documentation: "Claude Code will source this file before each Bash command, making the environment persistent across all commands."
Environment variables written to
CLAUDE_ENV_FILEduringSessionStartshould be available in subsequent Bash tool calls on Windows.Environment
Related Issues
CLAUDE_ENV_FILEnot provided to hooks (macOS) — different: on Windows it IS provided/clear(macOS) — different: on Windows it's not sourced at all, not just after/clear