Skip to content
BENIBIX Learn

CLAUDE_PID

AI⌨️ Claude CodeConfiguration

Also known as $CLAUDE_PID

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

Think of it like

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

Example

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

Why it matters

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

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 code

bash
ps -p "$CLAUDE_PID" -o pid,etime,command
See the Claude Code that started this script.
The third row skips the MCP server.

Common mistake

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

Key takeaways

  1. 1
    Claude Code's own id. The parent.
  2. 2
    Bash and hooks. Not MCP.
  3. 3
    Guards pkill. On Linux.