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

QuestionCodex CLIchecked at 0.164.0
The variable to check

CODEX_THREAD_ID holds the current thread's ID (a UUID). Commands the model runs also get CODEX_CI=1. Check either to know you're inside Codex.

CODEX_CI doesn't mean a hosted CI job; Codex sets it on its own command runs.

Which processes get it

Every command the model runs through its shell tool, including commands sent to a remote executor, and every command you run yourself with !.

Child processes inherit it, so anything those commands start sees it too.

Which session started the command

CODEX_THREAD_ID is the thread ID; the SDK resumes it with codex.resumeThread(process.env.CODEX_THREAD_ID). Each command also gets CODEX_TOOL_CALL_ID, the call that started it.

Codex says these labels are for correlation, not authorization: shell startup files and child processes can change or remove them.

Relying on it

QuestionCodex CLIchecked at 0.164.0
Telling the agent's commands from yours

Partly

Use CODEX_CI. Your own ! commands get CODEX_THREAD_ID but not CODEX_CI, which is only set on commands the model runs.

Signs that nobody will answer a prompt

Commands the model runs get CODEX_CI=1, TERM=dumb, NO_COLOR=1, COLORTERM empty, UTF-8 locale and cat as PAGER, GIT_PAGER and GH_PAGER.

Removing or overriding it

Not supported

No. shell_environment_policy (inherit, exclude, include_only, set) is applied first and CODEX_THREAD_ID is added afterwards, so no setting removes or replaces it. The CODEX_CI defaults are also applied after your policy.

Notes and sources

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