Skip to content

CLAUDE_ENV_FILE written but not sourced for Bash tool calls on Windows #27987

@ls-edwin-bekaert

Description

@ls-edwin-bekaert

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • 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

  1. 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');\""
      }]
    }]
  }
}
  1. Start a new Claude Code session on Windows
  2. Ask Claude to run: echo $MY_TEST_VAR
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:basharea:hooksbugSomething isn't workinghas reproHas detailed reproduction stepsplatform:windowsIssue specifically occurs on WindowsstaleIssue is inactive

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions