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