> For the complete documentation index, see [llms.txt](https://herd-security.gitbook.io/herd-security-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://herd-security.gitbook.io/herd-security-docs/ai/agent-oversight/codex-cli.md). Agents can also search and read this documentation through its [MCP server](https://herd-security.gitbook.io/herd-security-docs/~gitbook/mcp).

# Agent Oversight for Codex CLI

Extend agent oversight to the Codex command line tool with a managed hook, how to set it up from the Setup page bundle, what it checks, and what is not covered.

{% hint style="warning" %}
**Plan feature.** Agent oversight is locked, with an **I'm interested** button, until it is on your organization's plan.
{% endhint %}

## What it does

Herd records Codex CLI shell commands, file edits made with `apply_patch`, and MCP tool calls through a managed `PreToolUse` hook. The hook sends each call to Herd, and Herd's answer comes back to Codex.

* **Rules start in Recording.** Your organization's rule modes apply. A rule blocks only after an admin switches it to **Enforcing**.
* **Built-in rules judge shell commands only.** No built-in rule looks at `apply_patch` edits or MCP calls on Codex. They are recorded, not judged.
* **Prompts are not checked.** Only the tool call hook is installed.

## What you need

* **Node 18 or later** on each device.
* **`HERD_HOOK_TOKEN`** visible to the Codex process. See [Agent oversight hook token](https://herd-security.gitbook.io/herd-security-docs/ai/agent-oversight/hook-token.md).
* A way to put files on devices, such as your device management tool.

## Set it up

1. Go to **AI Insights → Setup** and download the Codex CLI bundle. It holds a `requirements.toml` and a script named `herd-codex-hook.mjs`. Neither carries your token.
2. Install `herd-codex-hook.mjs` on each device at `/opt/herd/codex-hooks` on macOS and Linux, or `C:\ProgramData\Herd\codex-hooks` on Windows. Codex does not distribute the script.
3. Merge the generated `requirements.toml` into the device's Codex requirements file. If the device already has a requirements file, do not add a second `[hooks]` table, because that is invalid. Codex reads the file from `/etc/codex/requirements.toml`, from `%ProgramData%\OpenAI\Codex\requirements.toml`, or on macOS from a managed profile (`com.openai.codex:requirements_toml_base64`).
4. Decide how `HERD_HOOK_TOKEN` reaches each device.
5. Start with one device. Run a shell command in Codex and check that it appears in Herd. On **Agents → Activity**, the sessions list has a **Surface** filter with a **Codex CLI** option.

The file pins hooks on. The Setup page can also add the option that allows only managed hooks, which needs the **Enforce AI governance rules** permission, as **Fail closed** does.

Herd does not use Codex's cloud-managed delivery of hooks. Use the device files.

## When Herd cannot check a call

By default the hook fails open: if something goes wrong on the device or in the connection, the call runs. **Fail closed** is the option on the Setup page that changes the cases marked below. `apply_patch` and MCP calls run either way. The script gives up after 2 seconds, and Codex's own hook timeout is 6 seconds.

| Situation                                                                                                                                                                                                                                                                                                     | Fail closed off (default)                                                                                                          | Fail closed on                                                                                             |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| Herd cannot be reached, or answers with an error status such as a 503 or a refused token. Herd answers a 503 itself when it does not have your rules: it could not tell which organization is calling, your rules did not load and it has no earlier copy, or it ran out of time or failed before they loaded | The script prints nothing and the call runs.                                                                                       | The script blocks shell commands (`Bash`, `PowerShell`, `Monitor`) and any call whose tool it cannot name. |
| Herd answers with your rules in hand but cannot check the call (a rule could not run, an engine error, or a missed deadline after the rules loaded)                                                                                                                                                           | A shell command is blocked only while an **Enforcing** rule could apply to it; otherwise it runs and Herd records it as unchecked. | The same as the left column.                                                                               |
| Herd cannot read the call in full                                                                                                                                                                                                                                                                             | Blocked only while an **Enforcing** rule could apply to it.                                                                        | The same as the left column.                                                                               |

What Codex does when a hook crashes, times out or exits non-zero is not documented by OpenAI, and its open-source code lets the call continue.

## People and sessions

Codex's payload names no user, so a Codex session is recorded **without a person**, in every organization. Herd cannot name or message the person whose session it was. Codex CLI never reports how a session was started, so **Who ran it** reads **Not reported yet**. See [Who ran it](https://herd-security.gitbook.io/herd-security-docs/ai/agent-oversight/coverage-and-bypass.md#who-ran-it). Identical commands repeated in a session count as separate calls, and Herd records them as one row with a count.

## The computer's serial number

On macOS the script also sends the computer's serial number with each call, and Herd stores it on the session. A serial number the script cannot read is left out, and the answer is the same. Herd does not count Codex CLI computers yet: a command-line tool is not in an application inventory, so there is nothing to compare the serial number with. See [What Herd puts on a managed computer](https://herd-security.gitbook.io/herd-security-docs/ai/ai-coach/what-herd-puts-on-a-managed-computer.md#the-computers-serial-number).

## What is not covered

* OpenAI describes tool hooks as "a useful guardrail, not a complete enforcement boundary", and says some specialised tool paths can skip hooks.
* Hosted tools such as web search never reach the hook.
* Codex cloud is not covered.
* Prompts are not checked.
* A device without the hook files is not seen.

## Keep personal accounts out

Optional, and off until you turn it on. In **Setup**, type your ChatGPT workspace ids under **Restrict sign-in to ChatGPT workspace ids**. Herd adds `allowed_login_methods = ["chatgpt"]` and `allowed_chatgpt_workspaces` to `requirements.toml`. Only a ChatGPT login to a listed workspace works, and an API key is refused.

* Codex ignores these two keys in cloud-managed requirements, so the file has to be on each computer.
* Try it on one managed computer before you roll it out.

See [Personal accounts](https://herd-security.gitbook.io/herd-security-docs/ai/agent-oversight/coverage-and-bypass.md#personal-accounts).

## Related

* [Agent oversight hook token](https://herd-security.gitbook.io/herd-security-docs/ai/agent-oversight/hook-token.md)
* [Agent oversight coverage and bypass](https://herd-security.gitbook.io/herd-security-docs/ai/agent-oversight/coverage-and-bypass.md)
* [Deliver the agent oversight settings with device management](https://herd-security.gitbook.io/herd-security-docs/ai/agent-oversight/device-management.md)
* [Agent oversight for Copilot CLI](https://herd-security.gitbook.io/herd-security-docs/ai/agent-oversight/copilot-cli.md)
