# CLAUDE_CODE_SHELL_PREFIX

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

**Field:** Artificial Intelligence  
**Category:** Claude Code  
**Also known as:** CLAUDE_CODE_SHELL_PREFIX=/path/to/logger.sh

## Think of it like

It is like a guard at the door. The guard writes down each one who walks in.

## Definition

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.

## Example code

```bash
#!/bin/bash
# logger.sh
echo "$(date) $1" >> ~/claude-commands.log
exec bash -c "$1"
```

A wrapper that logs, then runs the command.

## Why it matters

It gives one place to see, log or block each command. The commands stay the same.

## Common mistake

Running $1 as if it were a program name. MCP servers that pass extra words then break.

## Three principles

- **Wraps each command.** Bash, hooks, MCP.
- **Command in $1.** As one value.
- **Run it again.** bash -c "$1".

## Related terms

- [CLAUDE_CODE_SHELL](https://learn.benibix.com/term/ai/claude-code-shell-variable)
- [CLAUDE_ENV_FILE](https://learn.benibix.com/term/ai/claude-env-file-variable)
- [/hooks Command](https://learn.benibix.com/term/ai/hooks-command)

## Told apart from

- [CLAUDE_ENV_FILE vs CLAUDE_CODE_SHELL_PREFIX](https://learn.benibix.com/compare/claude-env-file-variable-vs-claude-code-shell-prefix-variable): 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_CODE_SHELL vs CLAUDE_CODE_SHELL_PREFIX](https://learn.benibix.com/compare/claude-code-shell-variable-vs-claude-code-shell-prefix-variable): People think the prefix picks the shell, since the names are so close. It does not. CLAUDE_CODE_SHELL picks bash or zsh to run each command. The prefix names your own program that wraps that shell, most often to log what runs. You can set one, the other or both.

![How a Bash command is run: the prefix wraps the shell, the shell runs the env file, then the command.](https://learn.benibix.com/diagrams/env-bash-command-path.svg)

---

Source: https://learn.benibix.com/term/ai/claude-code-shell-prefix-variable
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-16
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
