Skip to content
BENIBIX Learn

CLAUDE_ENV_FILE

AI⌨️ Claude CodeConfiguration

Also known as CLAUDE_ENV_FILE=~/.claude/env.sh

A script that runs before each Bash command, so its exports stay.

Think of it like

It is like you put on your apron each time you cook.

Example

Jack's tests need his Python virtualenv. Each command forgot it. He puts the activate line in an env file and sets this.

Why it matters

Each Bash command starts fresh. Without this, a setup step does not carry to the next command.

Definition

CLAUDE_ENV_FILE names a shell script that Claude Code runs before each Bash command, in the same shell. So anything the script exports, the command can see. It is the way to keep a Python virtualenv or a conda setup turned on across commands. Some hooks, such as SessionStart, can also write to it.

Example code

bash
# env.sh
source ~/projects/app/.venv/bin/activate

export CLAUDE_ENV_FILE=~/env.sh
claude
Keep a Python env on for each command.
The env file runs first, inside the shell.

Common mistake

Putting the activate line in a normal command and expecting it to last. It is gone by the next one.

Key takeaways

  1. 1
    Runs before each command. Same shell.
  2. 2
    Exports carry. Into the command.
  3. 3
    Hooks can fill it. SessionStart.

Compare