> 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/copilot-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 Copilot CLI

Extend agent oversight to the GitHub Copilot command line tool with a policy hook, how to set it up from the Setup page bundle, why a block is best effort, 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 Copilot CLI tool calls through a `preToolUse` policy hook. Rules start in **Recording**. A rule that is **Enforcing** can deny a call, but **a deny is best effort**.

* Your existing rules apply. Herd maps Copilot's tool names to the names the rules already use.
* Prompts are not checked. Only tool calls are registered.
* Herd does not send added context to Copilot CLI. A rule whose action is to add context is recorded as **Would have blocked**, and the AI is told nothing.
* Copilot in VS Code and the cloud agent are not covered.

## Why a block is best effort

GitHub documents HTTP `preToolUse` hooks as failing open. It documents command hook timeouts as failing open too, "even for `preToolUse` and admin-deployed policy hooks". So a call can run unchecked when the hook is slow, whatever the rule says. The hook times out after 3 seconds.

## What you need

* The ability to place files on each device, owned by root and not writable by the group or the world on macOS and Linux. GitHub requires this.
* **`HERD_HOOK_TOKEN`** visible to the Copilot CLI process. See [Agent oversight hook token](https://herd-security.gitbook.io/herd-security-docs/ai/agent-oversight/hook-token.md).
* **Node 18 or later** on the hook's `PATH`, if you turn **Fail closed** on.

## Set it up

1. Go to **AI Insights → Setup** and download the Copilot CLI bundle. Its files do not carry your token.
2. Place the policy file in `/etc/github-copilot/policy.d/` on Linux and macOS, or `C:\ProgramData\GitHub\Copilot\policy.d\` on Windows.
3. Decide how `HERD_HOOK_TOKEN` reaches each device.
4. Check one device first. Run a command in Copilot CLI and check that a session shows in Herd.

The bundle uses one hook mechanism, chosen by the **Fail closed** setting:

* **Fail closed off:** one HTTPS hook. It fails open, as GitHub documents.
* **Fail closed on:** one command hook and a script. GitHub documents a crash or non-zero exit of a command hook as a block. The script blocks a shell command that Herd could not be asked about.

{% hint style="danger" %}
**The token header depends on how Copilot expands the variable.** The HTTPS hook sends the token as `Bearer $HERD_HOOK_TOKEN` with the variable listed in `allowedEnvVars`. GitHub documents `allowedEnvVars` but not how the variable is expanded, and does not name HTTP entries in policy files. If Copilot does not expand it, the call gets a 401, runs unchecked, and Herd does not see it. If no session appears on your test device, use the script variant by turning **Fail closed** on.
{% endhint %}

## When Herd cannot check a call

| Situation                                                                                                                                           | Fail closed off (HTTPS hook)                                                                                                       | Fail closed on (command hook)                                                                       |
| --------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
| Herd cannot be reached or errors                                                                                                                    | The call runs unchecked and Herd shows nothing.                                                                                    | A shell command is blocked. Other tools run.                                                        |
| 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.                                                                                           |
| The hook runs past its timeout                                                                                                                      | The call runs.                                                                                                                     | The call runs.                                                                                      |
| Herd cannot read the call                                                                                                                           | Blocked only while an **Enforcing** rule could apply to it.                                                                        | The same.                                                                                           |
| The token is missing                                                                                                                                | The call runs unchecked.                                                                                                           | A shell command is blocked.                                                                         |
| A device has no `node`, or the script is missing or unreadable                                                                                      | Not applicable                                                                                                                     | **Every Copilot tool call on that device is blocked.** GitHub documents a non-zero exit as a block. |
| A device has no policy file                                                                                                                         | Not seen.                                                                                                                          | Not seen.                                                                                           |

## People and sessions

Copilot's payload names no user, so a Copilot session is recorded **without a person**, in every organization. Copilot 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).

## What is sent to Herd

The whole hook payload goes to Herd for the check, including the contents of a file on a create or edit. The script cannot remove the content, because GitHub documents no per-tool argument keys. Cursor's script does remove it.

With **Fail closed** on, the script also sends the computer's serial number on macOS, and Herd stores it on the session. A serial number the script cannot read is left out, and the answer is the same. With **Fail closed** off there is no script: the HTTPS hook cannot run a program, so no serial number is sent. Herd does not count Copilot 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).

## 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 Codex CLI](https://herd-security.gitbook.io/herd-security-docs/ai/agent-oversight/codex-cli.md)
