Skip to content
BENIBIX Learn

CLAUDE_ENV_FILE vs CLAUDE_CODE_SHELL_PREFIX

People think CLAUDE_ENV_FILE and the shell prefix both just run something before each command, so either will do. They work at different levels. The env file runs inside the same shell as the command, so what it exports, the command sees. The prefix is a program that wraps the whole command from outside. Use the env file to set up, and the prefix to log or check.

AI⌨️ Claude Code

CLAUDE_ENV_FILE

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

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
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.
Full entry
AI⌨️ Claude Code

CLAUDE_CODE_SHELL_PREFIX

It wraps each shell command in a tool of yours, often a log.

CLAUDE_CODE_SHELL_PREFIX names a program that wraps each shell command Claude Code starts. That covers Bash tool calls, hooks, the status line and the start of local MCP servers. The program gets the whole command as one value in $1. It must run it again, for example with exec bash -c "$1". It is mostly used to log or check commands.

Example
Lucy's team must keep a record of each command an AI runs. She points this at a small logger script.
Why it matters
It gives one place to see, log or block each command. The commands stay the same.
Full entry

In one line

CLAUDE_ENV_FILE
A script that runs before each Bash command, so its exports stay.
CLAUDE_CODE_SHELL_PREFIX
It wraps each shell command in a tool of yours, often a log.