CLAUDE_ENV_FILE written but not sourced for Bash tool calls on Windows
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
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
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');\""
}]
}]
}
}
- 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
- #15840 —
CLAUDE_ENV_FILEnot provided to hooks (macOS) — different: on Windows it IS provided - #14433 — not sourced after
/clear(macOS) — different: on Windows it's not sourced at all, not just after/clear - #24775 — session ID mismatch on resume — potentially related if the sourcing logic has a path resolution issue on Windows
This issue has 7 comments on GitHub. Read the full discussion on GitHub ↗