Codex (OpenAI)

Two ways to wire KYA into Codex. Pick one or use both:

Codex plugin

This repo is also a Codex plugin marketplace named shield-kya (.agents/plugins/marketplace.json) with one plugin, kya (the same plugins/kya folder as the Claude Code plugin; Codex reads plugins/kya/.codex-plugin/plugin.json).

codex plugin marketplace add The-Pixel-Boys/shield-kya
codex plugin add kya@shield-kya

Or open /plugins in Codex CLI and install kya from the shield-kya tab. Plugins are not available in the Codex IDE extension.

Then trust the hooks. Codex does not run plugin hooks until you review and trust them: open /hooks in Codex CLI and trust the two Shield KYA hooks. Until you do, KYA records nothing and codex exec gives no warning. Codex keys trust to the hook definition (command string, matcher, timeout, status message), not to the scripts or the package that command runs. The SessionStart command carries the pinned kya version, so every kya release changes it and Codex asks again; until you re-trust it, the PreToolUse hook keeps using the kya copy already installed. The PreToolUse command carries no version, so its trust carries over. A change to the plugin’s scripts that leaves the command strings unchanged runs without a new prompt.

Trust model. Codex upgrades Git marketplaces at startup. Anyone who can push to the main branch of The-Pixel-Boys/shield-kya, or who holds the token that syncs it, can therefore change what runs at your next Codex start. That is the trust model of any auto-updating plugin marketplace. Teams that want to choose when updates land can add the marketplace at a pinned release ref, codex plugin marketplace add The-Pixel-Boys/shield-kya@vX.Y.Z (Codex accepts owner/repo@ref). Checked with Codex CLI 0.162.1: the startup auto-upgrade honours a pinned ref (a pinned install stayed on its tag while an unpinned one followed main), and codex plugin marketplace upgrade reports a pinned marketplace as up to date. The price of pinning is that you get no kya updates, including fixes, until you add the marketplace again at the new tag. This was exercised against a local Git server; the GitHub @tag form stores the same ref field.

What the plugin does, and does not do:

Uninstall: codex plugin remove kya@shield-kya, then delete ~/.codex/plugins/data/kya-shield-kya.

MCP server

kya connect codex wires the stdio entry into ~/.codex/config.toml (TOML, merge-only); --gate writes a url-based [mcp_servers.shield-kya-gate] table pointing at the local kya gateway instead. To copy the richer example by hand (environment-inherited keys), see below.

Setup

  1. Open openai/codex.config.example.toml.
  2. Merge its [mcp_servers.shield-kya] block into ~/.codex/config.toml. Global only: do not drop a live key into a project’s .codex/config.toml; that file is easy to commit. The example inherits KYA_API_KEY from the environment (env_vars) instead of storing it.
  3. Restart Codex.

Two variants in the one file: pick one, not both:

Responses API (no CLI): see openai/responses-mcp.example.json: server_url + Authorization: Bearer ${KYA_API_KEY}. ChatGPT Apps: deferred; Developer Mode wants OAuth. Use Codex until then.

What KYA reports

Three tools: kya.policy_evaluate (Allow / Deny / Hold), kya.session_ingest, kya.request_approval. Each call lands on the receipt with a clipped, redacted change preview: kya receipt --open.

Files written

For the MCP path you edit one file by hand: ~/.codex/config.toml. KYA installs nothing else. (The plugin path installs kya into the plugin data directory, see above.)

Verify

  1. Restart Codex, then run codex mcp list. shield-kya should show.
  2. Ask Codex for a small change and watch the record.
  3. Offline smoke:

    kya wrap --offline --tool-id Write --irreversible --args '{"path":"x.ts","content":"hi"}'
    

    Expect a REQUIRE_APPROVE row in the record.

Uninstall

Remove the [mcp_servers.shield-kya] block from ~/.codex/config.toml and restart.

Troubleshooting

Honesty note

On the MCP path, Codex decides which tools go through MCP; anything it executes natively is outside that path. The plugin hook sees native tool calls too, but it is advisory: it records them and blocks the never-list and the guard pack. The config inherits your key from the environment. Never paste a live key into the TOML.

Wrap fallback

kya wrap --offline -- codex exec "fix the tests"

Wrap evaluates the command itself before it runs and records a row in the record. Exit 0 Allow, 4 Hold, 1 Deny.