Skip to content

CLAUDE_ENV_FILE not provided to SessionStart hooks #15840

@excessivereason

Description

@excessivereason

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

  1. 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
  1. Register it in ~/.claude/settings.json:
{
  "hooks": {
    "SessionStart": [
      {
        "matcher": "*",
        "hooks": [
          {
            "type": "command",
            "command": "~/.claude/hooks/session-start.sh"
          }
        ]
      }
    ]
  }
}
  1. Start a new Claude Code session

  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:corearea:toolsbugSomething isn't workinghas reproHas detailed reproduction stepsplatform:macosIssue specifically occurs on macOSstaleIssue 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