# CLAUDECODE

> Set to 1 in each program Claude Code starts, so a script knows.

**Field:** Artificial Intelligence  
**Category:** Claude Code  
**Also known as:** CLAUDECODE=1, CLAUDE_CODE_CHILD_SESSION

## Think of it like

It is like a name tag that says I came with Claude.

## Definition

CLAUDECODE is set to 1 in the programs Claude Code starts. That means Bash commands, hooks, the status line and local MCP servers. IDE plugins also set it in their own terminals. A script reads it to know it is running inside Claude Code, and can act on that.

## Example

Jack's test script opens a browser, which stalls Claude. The script now skips the browser when this is set.

## Example code

```bash
if [ -n "$CLAUDECODE" ]; then
  echo "Running inside Claude Code"
fi
```

A script that checks where it runs.

## Why it matters

Some scripts should act a bit differently for an AI than for a person, such as no prompts.

## Common mistake

Setting it yourself in your shell. Then every script thinks it is inside Claude Code.

## Three principles

- **Set to 1.** By Claude Code.
- **In what it starts.** Bash, hooks, MCP.
- **For scripts.** To detect it.

## Related terms

- [CLAUDE_CODE_SESSION_ID](https://learn.benibix.com/term/ai/claude-code-session-id-variable)
- [CLAUDE_CODE_REMOTE](https://learn.benibix.com/term/ai/claude-code-remote-variable)
- [Bash Tool](https://learn.benibix.com/term/ai/bash-tool)

## Told apart from

- [CLAUDECODE vs CLAUDE_CODE_REMOTE](https://learn.benibix.com/compare/claudecode-variable-vs-claude-code-remote-variable): People think CLAUDECODE tells a script it is in the cloud. It only says the script was started by Claude Code, and that is true on your laptop too. CLAUDE_CODE_REMOTE is the one set to true only in a cloud session. A hook that should act only on a fresh cloud machine checks the second.

![Which variables Claude Code sets in a Bash command, a hook and an MCP server it starts.](https://learn.benibix.com/diagrams/env-subprocess-vars.svg)

---

Source: https://learn.benibix.com/term/ai/claudecode-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.
