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

Questionpichecked at 1.4.0
The variable to check

AI_AGENT=pi (since 0.84.0) and PI_CODING_AGENT=true (since 0.67.1).

Which processes get it

Everything Pi starts. Pi sets both on its own process at startup, so every child inherits them. Not set when Pi is embedded through the SDK.

Which session started the command

PI_SESSION_ID, PI_SESSION_FILE (the session's JSONL file, unset for ephemeral sessions), PI_PROVIDER, PI_MODEL and PI_REASONING_LEVEL in the agent's bash and powershell commands.

Relying on it

Questionpichecked at 1.4.0
Telling the agent's commands from yours

Partly

Use PI_SESSION_ID. The two markers are inherited by everything, including your own ! and !! commands, but the session variables are only given to the agent's bash and powershell tools.

Signs that nobody will answer a prompt

Not documented

Not documented. Pi's environment reference lists no terminal, pager or CI settings for agent commands.

Removing or overriding it

A custom shell tool's spawnHook can rewrite the environment, and exposeSessionEnvironment: false drops the session variables (and strips inherited ones). The two process markers can't be turned off.

Notes and sources

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