Harness Notes

Environment detection

Updated 2026-11-22,

On this page

How a script, hook or CLI can tell it was started by each harness, and which session started it. Children inherit these variables, so treat them as hints that an agent is involved, not as proof that no person is watching.

Detecting the harness

QuestionClaude Codechecked at 2.1.310
The variable to check

CLAUDECODE=1. Since v2.1.172 commands Claude Code itself starts also get CLAUDE_CODE_CHILD_SESSION=1. It also sets AI_AGENT: claude-code_2-1-310_agent in commands its tools run, and claude-code_2-1-310_harness everywhere else it starts (unless another agent already set AI_AGENT).

AI_AGENT isn't in the environment reference, and the value carries the version, so match the claude-code_ prefix.

Which processes get it

CLAUDECODE: Bash and PowerShell tool commands, tmux sessions, hooks, status line commands and stdio MCP servers. CLAUDE_CODE_CHILD_SESSION: Bash, PowerShell and Monitor tool commands, hooks and status line commands, but not MCP servers.

Which session started the command

CLAUDE_CODE_SESSION_ID in tool commands, hooks and stdio MCP servers; it matches the hooks' session_id and changes on /clear (an MCP server keeps the ID it started with). Cloud sessions add CLAUDE_CODE_REMOTE_SESSION_ID, and Remote Control adds CLAUDE_CODE_BRIDGE_SESSION_ID (v2.1.199+).

Relying on it

QuestionClaude Codechecked at 2.1.310
Telling the agent's commands from yours

Use CLAUDE_CODE_CHILD_SESSION. The IDE extensions also set CLAUDECODE in their integrated terminals, so a person typing there looks like Claude Code; CLAUDE_CODE_CHILD_SESSION is only set when Claude Code launches the process.

Signs that nobody will answer a prompt

Partly

Undocumented, but commands get CLAUDE_CODE_SESSION_ATTENDED: 1 in an interactive session, 0 in background and daemon sessions. Bash tool commands also get GIT_EDITOR=true, so git never opens an editor.

Commands also get CLAUDE_PID (the Claude Code process) and CLAUDE_EFFORT (the current effort level).

Removing or overriding it

Not documented

Not documented. The reference describes a scrub that strips credentials from subprocesses, not a way to remove these markers.

Notes and sources

Claude Code, 3 sources
The variable to check, 3
Which processes get it, 1
Which session started the command, 1
Telling the agent's commands from yours, 1
Signs that nobody will answer a prompt, 3
Removing or overriding it, 1