# CLAUDE_PID

> It holds Claude Code's own process id, for the scripts it starts.

**Field:** Artificial Intelligence  
**Category:** Claude Code  
**Also known as:** $CLAUDE_PID

## Think of it like

It is like the room number of the one who sent you on a job.

## Definition

CLAUDE_PID holds the process id of Claude Code itself. Claude Code sets it in the Bash commands and hooks it starts. A script can use it to find or signal the Claude Code that started it. On Linux, the Bash tool uses it to refuse a pkill that would stop Claude Code itself.

## Example

Jack's hook needs to know how long the session has been open. It reads the start time from CLAUDE_PID.

## Example code

```bash
ps -p "$CLAUDE_PID" -o pid,etime,command
```

See the Claude Code that started this script.

## Why it matters

Without it, a script has to guess which Claude Code on the machine is its parent.

## Common mistake

Looking for it in an MCP server. It is set for Bash commands and hooks only.

## Three principles

- **Claude Code's own id.** The parent.
- **Bash and hooks.** Not MCP.
- **Guards pkill.** On Linux.

## Related terms

- [CLAUDE_CODE_SESSION_ID](https://learn.benibix.com/term/ai/claude-code-session-id-variable)
- [CLAUDECODE](https://learn.benibix.com/term/ai/claudecode-variable)

![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/claude-pid-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.
