Docs

Agents

Codex

Set up Comity hooks and MCP for OpenAI Codex, including the hook approval step.

4 min readUpdated

On this page

Codex gets the same integration as Claude Code: hooks on session start, prompts, edits (apply_patch) and shell commands, plus the Comity MCP server.

Set up

Terminal
cd your-repo
comity init --tools codex
git add .codex/hooks.json .codex/config.toml
git commit -m "Set up Comity for coding agents"

Then in Codex:

  1. Trust the project when Codex asks. Codex ignores a project's .codex/hooks.json and .codex/config.toml until you do, so there are no Comity hooks and no comity MCP server.
  2. Open /hooks and approve the comity hooks.

Important

Codex skips project hooks until you approve them in /hooks. Until then Comity sees nothing from that Codex session: no briefings, no warnings, no blocks. Codex pins each approval to the hook's exact definition, so when a later comity init changes .codex/hooks.json (for example after a CLI update), approve the changed hooks again. comity doctor checks both the trust and the approvals.

What init writes

.codex/hooks.json

Same six events as Claude Code. Each handler has a POSIX command and a commandWindows variant, because Codex runs hook commands through Windows PowerShell on Windows. Shown for one event; the others differ only in event name, matcher and timeout.

JSON
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "apply_patch|Edit|Write|Bash",
        "hooks": [
          {
            "type": "command",
            "command": "command -v comity >/dev/null 2>&1 || exit 0; exec comity hook --tool codex --event PreToolUse",
            "commandWindows": "$c = Get-Command comity -CommandType Application -ErrorAction SilentlyContinue | Select-Object -First 1; if (-not $c) { exit 0 }; & $c.Source hook --tool codex --event PreToolUse",
            "timeout": 5
          }
        ]
      }
    ]
  }
}
Event Matcher Timeout (s)
SessionStart 5
UserPromptSubmit 5
PreToolUse apply_patch|Edit|Write|Bash 5
PostToolUse apply_patch|Edit|Write|Bash 10
Stop 10
SessionEnd 3

The Windows command resolves comity.cmd/comity.exe directly and skips the npm comity.ps1 shim, which PowerShell's default execution policy refuses to run. Both variants exit quietly when the CLI isn't installed.

.codex/config.toml

TOML
[mcp_servers.comity]
url = "https://api.comity.so/mcp"
http_headers_helper = "comity mcp-headers"

Codex runs comity mcp-headers at connect time to get the Authorization header from COMITY_TOKEN or your login. No token is written. Other tables in the file, including your own [mcp_servers.comity.tools.*] subtables, are kept.

What your agent sees

  • Session start and each prompt: the briefing as added context.
  • Before an edit or shell command: a block denies the call with Comity's reason. Warnings are added as context right away (Codex supports additionalContext on PreToolUse).
  • After an edit or shell command: new conflicts, messages, answers and arrival notices.
  • When the agent updates its plan (update_plan): the done/total count becomes the progress of its claimed shared task.
  • Before task_accept (answering a teammate's work request): Codex's approval prompt, in interactive sessions. comity init adds [mcp_servers.comity.tools.task_accept] with approval_mode = "prompt" to .codex/config.toml; comity doctor checks it (codex task approval). Codex shows that prompt only when its approval policy asks at all: with never (codex exec, --dangerously-bypass-approvals-and-sandbox, or approval_policy = "never" in your config) it runs the tool without asking. The hooks tell Comity so (their permission_mode is bypassPermissions), and Comity then refuses to accept a request from that session; the agent tells you to answer it in the dashboard (Needs you) or from an interactive Codex session. The same holds when neither the project's nor your user config.toml has the task_accept table (set up before it existed): rerun comity init --tools codex. It can still decline when you told it to. In an interactive session the agent tells you in one line what is asked and calls the tool right away, so the prompt is the only question; No ("user rejected MCP tool call" in the session log) declines the request and Comity tells the sender, while cancelling the prompt is no answer.

Codex reads only the first 512 characters of an MCP server's instructions; Comity puts the essential rules first for that reason. Use agent instructions in AGENTS.md to reinforce them.

Verify

Terminal
comity doctor

Expect codex hooks all 6 events installed, codex mcp configured in …/.codex/config.toml and codex hook trust all 6 comity hooks approved in /hooks. In Codex, /mcp should list comity.

Doctor reads Codex's user config, $CODEX_HOME/config.toml (default ~/.codex/config.toml), without changing it:

  • codex trust warns when the project is marked untrusted. Start codex in the repo and trust it. With no [projects."<path>"] entry at all (Codex never asked about this project, maybe because you don't use Codex here), it is an i note that doesn't change doctor's exit code.
  • codex hook trust warns when comity hooks are not approved yet, were changed since you approved them, or are turned off. Open /hooks in Codex and approve them. In codex exec without the TUI, the only alternative is --dangerously-bypass-hook-trust.

Without a Codex home (Codex has never run on this machine), doctor can't tell and shows only codex hooks and codex mcp.

Try Comity now.

Start free →

npm i -g comity-cli && comity login && comity init