Agents
Codex
Set up Comity hooks and MCP for OpenAI Codex, including the hook approval step.
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
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:
- Trust the project when Codex asks. Codex ignores a project's
.codex/hooks.jsonand.codex/config.tomluntil you do, so there are no Comity hooks and nocomityMCP server. - Open
/hooksand approve thecomityhooks.
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.
{
"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
[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
additionalContextonPreToolUse). - 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 initadds[mcp_servers.comity.tools.task_accept]withapproval_mode = "prompt"to.codex/config.toml;comity doctorchecks it (codex task approval). Codex shows that prompt only when its approval policy asks at all: withnever(codex exec,--dangerously-bypass-approvals-and-sandbox, orapproval_policy = "never"in your config) it runs the tool without asking. The hooks tell Comity so (theirpermission_modeisbypassPermissions), 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 userconfig.tomlhas thetask_accepttable (set up before it existed): reruncomity 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
comity doctorExpect 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 trustwarns when the project is marked untrusted. Startcodexin 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 aninote that doesn't change doctor's exit code.codex hook trustwarns when comity hooks are not approved yet, were changed since you approved them, or are turned off. Open/hooksin Codex and approve them. Incodex execwithout 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.