# Codex CLI through Grodmir

Tested with Codex CLI 0.155 against a live gateway (`dataplane/tests/test_agents_live.py`).
Codex talks the OpenAI **Responses** API, which the gateway serves at `POST /v1/responses`.

## 1. Point it at the gateway

Merge `deploy/integrations/codex/config.toml` into `~/.codex/config.toml` and set the virtual
key in the environment (never in a file):

```sh
export AIGUARD_KEY=aig_...
codex
```

## 2. Repository rules and client assignment (optional)

Headers differ per repository, so pass them per run:

```sh
codex -c "model_providers.aiguard.http_headers=$(aiguard repo headers --format toml)"
```

## What is protected

- Prompts, instructions, tool calls and tool results are scanned like any other request; the
  model only sees tokens and Codex shows the original values.
- Repository markers and excluded paths from [`.aiguard.yaml`](https://grodmir.com/dokumentacja/zrodla/repo-rules.md) are enforced by the
  gateway. If Codex runs `cat secrets/db.txt`, the request that would carry the output is
  refused (tested).
- **No provider-side state.** The gateway sets `store: false` on every request and refuses
  `previous_response_id`, `conversation` and `background` (HTTP 400): Codex sends the full
  history each turn, so nothing is lost; the provider keeps no copy (Q-034).

## Not covered (be explicit with your users)

- **Hooks are not shipped for Codex.** Codex supports `PreToolUse` hooks, but each hook has to
  be reviewed and trusted interactively (`/hooks`), and this could not be verified headless. Only
  the gateway layer is tested for Codex. Hook support may be added once trust can be scripted.
- Your model destination must serve `/responses`; many OpenAI-compatible servers do not.
- The same NER false positives as for Claude Code apply to Codex's long instructions.

## Verify

```sh
AIGUARD_TEST_CODEX=1 uv run pytest dataplane/tests/test_agents_live.py -k codex
```
