Docs

Reference

Hook events

How each agent's native hook events map to Comity events, what is sent, timeouts, and how answers are rendered.

12 min readUpdated

On this page

Every agent integration runs comity hook --tool <tool> --event <Event> with the host's hook JSON on stdin (the omp extension calls the same code in-process). The CLI maps the native event to a Comity event, sends it to POST /v1/hooks/evaluate, and prints the host's native hook output.

Event mapping

Comity event Claude Code / Copilot CLI Codex Cursor (via Claude hooks) omp
session_start SessionStart SessionStart sessionStart session_start
prompt UserPromptSubmit UserPromptSubmit beforeSubmitPrompt before_agent_start
plan PreToolUse on ExitPlanMode – – –
pre_edit PreToolUse on an edit tool PreToolUse on apply_patch / edit preToolUse on an edit tool tool_call on edit, apply_patch, write
pre_shell PreToolUse on Bash or PowerShell PreToolUse on a shell command preToolUse on Shell tool_call on bash, eval, ast_edit
post_edit PostToolUse on an edit tool or Bash PostToolUse postToolUse tool_result on the same tools
checkpoint PostToolUse on Agent / Task (Claude Code main agent) – – tool_result on other tools (at most every 20 s), or on bash/eval/ast_edit that changed no file and ran 5 s or more
stop Stop Stop stop session_stop
session_end SessionEnd SessionEnd sessionEnd session_shutdown
  • Edit tools: Edit, Write, MultiEdit, NotebookEdit (and Delete where a host has it). Host-specific names are normalized: create/write → Write, edit/str_replace_editor → Edit, Shell/bash/powershell/shell/exec_command and Claude Code's Windows PowerShell tool → Bash.
  • Codex apply_patch: paths come from the patch envelope (*** Update File: …). A shell command containing *** Begin Patch is treated as an edit of those files.
  • Other tools (reads, searches, web) are ignored and never leave the machine.
  • Subagent returns (checkpoint): Claude Code's main agent gets a subagent's result back through the Agent tool (Task in older releases). While it waited, only the subagent's tool calls ran hooks, and those never take messages, questions or answers, so the CLI sends a checkpoint: the server evaluates nothing (no edit check, no snapshot, no detection) and only returns what arrived meanwhile: messages, questions, answers, arrival notices and conflicts that changed. A subagent's own Agent call sends nothing. omp sends checkpoint after reads, searches and MCP tools (at most every 20 s per session) and after a shell-like call that changed no file but ran 5 s or more, never from a subagent. Codex doesn't send checkpoint.
  • The matchers comity init writes: Claude Code PreToolUse Edit|Write|MultiEdit|NotebookEdit|Bash|PowerShell|ExitPlanMode|mcp__comity__task_accept and PostToolUse Edit|Write|MultiEdit|NotebookEdit|Bash|PowerShell|Task|Agent|TodoWrite|TaskCreate|TaskUpdate; Codex PreToolUse apply_patch|Edit|Write|Bash and PostToolUse apply_patch|Edit|Write|Bash|update_plan; Gemini CLI BeforeTool write_file|replace|run_shell_command and AfterTool write_file|replace|run_shell_command|write_todos; Factory Droid PreToolUse Create|Edit|ApplyPatch|Execute|mcp__comity__task_accept and PostToolUse Create|Edit|ApplyPatch|Execute|TodoWrite; Cursor also a beforeMCPExecution hook (for task_accept). The todo tools report todo (progress of a shared task); task_accept gets the host's approval prompt (shared tasks). Hooks written by CLI 0.4.0 or older lack ExitPlanMode, so they never send plan; hooks written by CLI 0.6.3 or older lack Task|Agent, so they never send checkpoint, and lack PowerShell, so Claude Code's PowerShell tool on Windows bypasses protected paths and goes unrecorded. Hooks without the todo tools or task_accept report no task progress and show no approval prompt for work requests. They keep working otherwise, and comity doctor shows "update available" until you rerun comity init. Codex has no plan event.
  • pre_push exists in the protocol but no integration sends it and the server doesn't act on it.

What each event sends

Event Extra fields
session_start Workspace packages (repo.packages, up to 200)
prompt prompt_excerpt: first 2,000 characters of the prompt. When the prompt points the agent at a shared task list: task_list (the parsed markdown file: {source: "file", path, title?, version_ms?, content_sha?, items}), or task_list_mention: true (no file named); working_list: null when the user says to stop working from the list
plan plan_text (up to 32,768 characters)
pre_edit paths: repo-relative paths about to change (up to 500)
pre_shell shell.command (up to 4,000 characters); paths the command visibly writes: redirect targets, tee, sed -i/perl -i/awk -i inplace files, mv/cp/install destinations (and mv sources), rm/touch/truncate operands, git checkout -- <paths>/git restore/git rm/git mv, prettier --write/eslint --fix files, PowerShell Set-Content/Add-Content/Clear-Content/Out-File/New-Item/Remove-Item/Move-Item/Copy-Item paths. Chains, cd, quoting and shell wrappers (powershell -Command, cmd /c, bash -lc) are followed; globs are expanded in the working tree
post_edit paths changed (for shell commands: the working-tree diff before/after, plus the files of commits the command made on the same branch); gitignored files are left out. analysis: per-file symbols, signature hashes, compatibility, new references, and truncated: true when only part of the files was analyzed (20 always, more within about 2 s; changed definitions and their importers first). Analysis waits while a rebase, merge, cherry-pick or revert is stopped half-way or a file has conflict markers, and runs on the first edit or command after it finished. changed_set: every path that differs from the merge-base (up to 2,000), so files you deleted or reverted leave your recorded changes and claims
checkpoint Nothing beyond the common fields
stop status: {excerpt (≤500 chars of the last assistant message), files (touched this turn)}, unless COMITY_SHARE_STATUS=0; changed_set as for post_edit

Any event may also carry todo: {done, total}: the agent's own todo list after its todo tool ran (TodoWrite, TaskCreate/TaskUpdate, update_plan, write_todos, omp's todo), the progress of the session's claimed shared task.

From hook events, team decisions are checked against these fields only: pre_edit paths and pre_shell paths against reserved paths, pre_shell shell.command against forbidden commands and package-manager installs and removals (warn or block, by the decision's mode), and plan_text and prompt_excerpt for mentions of a forbidden package (warn only). A block names the decision in reason and lists its conflict (kind decision) in conflicts.

Every request also carries session (external_id, tool, model, surface, parent_external_id for subagents with a session of their own (omp, Cursor), subagent {id, type} for a tool call inside a subagent of this session (Claude Code agent_id/agent_type)), client (cli_version, os, tool_version, machine_id_hash), repo (remote_fingerprints, branch, head_sha, base_sha, worktree_hash, cwd_path; during a rebase branch is the branch being rebased, and a detached HEAD sends no branch but detached: true; git_operation (rebase, merge, cherry_pick, revert) while one is stopped half-way, so Comity keeps your conflicts as they are until it finished instead of resolving and reopening them), and a dedupe_key so a retried event is evaluated once. Subagent calls are evaluated like the session's own, but receive no messages, questions, answers, handoffs or arrival notices; those wait for the main agent.

Codex requests also carry session.approval_prompt: false when the hook's permission_mode is bypassPermissions (approval policy never: codex exec, --dangerously-bypass-approvals-and-sandbox), true otherwise; also false when neither the project's nor your user config.toml has the [mcp_servers.comity.tools.task_accept] table with approval_mode = "prompt" (set up before it existed), since Codex would then run task_accept without asking. A session that can't show its human an approval prompt can't accept a teammate's work request; its briefing tells the agent to leave the answer to its human (dashboard Needs you or an interactive session).

Claude Code and Codex requests may carry task_accept_denied (up to 10 WR-n): work requests your human declined with No in the agent's approval prompt for task_accept. Neither host tells hooks about a denied call, so the CLI reads it from the session transcript (Claude Code) or session log (Codex). Comity declines each one with the note "declined in the approval prompt", tells the sender, and tells the agent in a "### Work request answered" section not to call task_accept for it again. The CLI keeps sending a denial until the server answered.

session_start and stop also carry repo.head_history and repo.default_history: the abbreviated ids (12 hex characters) of the latest 200 commits of HEAD and of the default branch (origin/HEAD, else origin/main, origin/master, main, master), newest first. Comity uses them to tell work that is already in your branch from work in flight (no conflict with a teammate's commit you already have) and to close intents whose commits reached the default branch. To recognize branches that were squashed, rebased or merged, they also carry patch-ids of the branch's commits and of the default branch's latest 50 commits, and the git blob ids (12 hex characters) of the files the branch's commits changed (branch_blobs, up to 300) and of the file versions the default branch's latest 50 commits produced (default_blobs, up to 2,000); stop adds the same branch report for linked worktrees the session edited in (linked_branches). Only commit, patch and blob ids and file paths are sent, never file contents or messages; tool events never send them, so checks before an edit stay fast.

Hooks run in git repositories with a remote or at least one commit. repo.remote_fingerprints lists the remotes (github.com/acme/api, origin first) and then, for a young history (up to 2,000 commits on the default branch's first-parent line) or a repo without remotes, the root commit of the default branch (root:<sha>). A repo without a remote is identified by that root commit alone, and its requests add repo.repo_name (the folder name, never the path), which names the repo local/<folder>-<sha:7>. When a remote is added, the next request carries both, and Comity adds the remote to the same repo (taking the remote's owner/name), so the history stays in one place; a fork with its own remote shares the root commit but stays a repo of its own. A repo with neither a remote nor a commit sends nothing; a session there with a comity.json gets a one-time note at session start.

In a folder that contains several repositories (not itself a repo), the CLI sends each file's event to the repo it belongs to, and merges the briefings for up to 8 recently active repos at session start. An agent started inside one repo that edits files of another (../payments-api/src/x.ts) is treated the same way for those files: they go to their own repo, with a session of their own there, and that repo's policy decides. A worktree of the same repo (git worktree add ../api-fix) is different: its edits stay the agent's own session and intent, sent with that worktree's branch. Shell commands are also checked in up to 4 of the repo's worktrees (those the command names first), so a script that writes files in ../api-fix is recorded there.

Response

JSON
{
  "decision": "warn",
  "reason": "1 coordination warning(s): symbol_overlap sym:tsx:src/app/page.tsx#CartSummary with INT-8 (Marina). …",
  "inject_context": "## Comity update — system-generated for `acme/api`\n…",
  "conflicts": [{ "number": 9, "ref": "CF-9", "kind": "symbol_overlap", "severity": "warn" }],
  "intent": { "number": 14, "ref": "INT-14", "status": "active" },
  "session_id": "0192f0c4-7d1e-7a8b-9c2d-3e4f5a6b7c8d",
  "index_version": 412
}

When the session works from a shared task list or has work requests waiting, the response also carries tasks: {working_list, claimed, pending_requests}: the list (id, title, source, source_ref), the task the session holds (id, ref, title, progress) and the refs of work requests waiting for its human (WR-n).

How the CLI renders it for the host:

Result Before a tool call (PreToolUse) Other events
block {"hookSpecificOutput": {"hookEventName": "PreToolUse", "permissionDecision": "deny", "permissionDecisionReason": "<reason>"}} Never happens
warn / context Codex: additionalContext. omp: additionalContext, which the bridge delivers with the call's tool_result (omp drops tool_call context when the call fails). Claude Code, Cursor, Copilot CLI: queued and added to the next PostToolUse or prompt {"hookSpecificOutput": {"hookEventName": "<Event>", "additionalContext": "<text>"}} on SessionStart, UserPromptSubmit, PostToolUse
allow, nothing to say No output No output

Comity never outputs a native "allow" decision, so the host's own permission prompts still apply. The one ask it outputs is in front of an accepting task_accept (declines pass without it) (Claude Code and Factory Droid: "permissionDecision": "ask" with a reason naming the work request; Cursor's beforeMCPExecution: its ask permission), so the human approves a work request in the agent's own prompt. Added context is capped at 6,000 characters per event. The hook always exits 0.

Autopilot

With Autopilot, Claude Code and Codex also run a second Stop handler, comity hook --tool claude_code --event Stop --autopilot (--tool codex in .codex/hooks.json), with a 24-hour timeout and the status message "Autopilot: waiting for team work (Esc to stop)". While autopilot is off it exits at once without calling the API (the CLI caches the state from the last hook response). While on, it long-polls POST /v1/autopilot/wait (up to 55 s per call, repeated) with no model running, and when work arrives prints {"decision": "block", "reason": "<work prompt>"}, so the same session continues with the task. With no work for about a day, it blocks with a one-line "still waiting" reason to re-arm. omp's bridge does the same in the background and sends the work as a new prompt.

Fields:

  • Request autopilot_back: "esc" | "prompt": the user typed a prompt in a session autopilot was driving (Claude Code and Codex after Esc: esc; omp: prompt). /autopilot commands never send it. The server turns autopilot off and returns the summary in the same response.
  • Response autopilot: {enabled, summary?}: enabled whenever the user's autopilot is on (the CLI caches it for the Stop handler); summary ("While you were away …") once, at the first prompt or session start after autopilot went off. The same text is in inject_context under "## Comity autopilot", so the agent shows it to the user first.

Timeouts

CLI waits for the API Host hook timeout in init config
pre_edit, pre_shell 400 ms once connected, plus the connection setup (at most 800 ms) 5 s
Other events 1.5 s 5 s (SessionStart, UserPromptSubmit), 10 s (PostToolUse, Stop, SessionEnd; Codex SessionEnd 3 s)
omp extension 600 ms per event, then allows –

If the API doesn't answer in time, errors, or returns an unexpected shape, the agent proceeds and a fail-open line goes to hook.log in the CLI config folder. A pre_edit or pre_shell skipped this way (network error, timeout or 5xx) is also recorded in hook-skips.json (comity status), and the user sees a notice once per session where the host can show one: Claude Code and Codex systemMessage, omp ui.notify (also when the extension's own 600 ms budget runs out); Cursor and other hosts only log it. In a repo whose policy is fail_mode: "closed", such a call is answered with the host's block instead and logs a fail-closed line; see Fail-closed.

Before it calls the API, a session start also collects the git facts landed detection uses: the HEAD and default-branch histories, patch-ids, and which local branches the default branch already holds. That work gets at most 800 ms. Whatever isn't done by then is left out of the session start and sent with the next Stop, and a hook.log line says "ancestry cut short". The results are cached per repository by the commits they describe (in the CLI's temp folder, shared by worktrees and sessions), so a resumed or new session in an unchanged checkout skips that work.

Host detection

Cursor and Copilot CLI run the Claude Code hooks, so --tool claude_code is only a hint. The CLI decides from the payload and environment:

Host Recognized by
Cursor cursor_version or conversation_id in the payload, or CURSOR_VERSION set
Copilot CLI sessionId / toolName / toolArgs in the payload, or the VS Code–compatible payload (ISO timestamp, no transcript_path)
Codex --tool codex or turn_id in the payload
omp --tool omp (only the omp extension sets it)
Claude Code otherwise

If the detected host has its own Comity hook config (for example a .cursor/hooks.json or .github/hooks/*.json that calls comity hook), the invocation from the Claude Code config steps aside so each event is evaluated once.

Try Comity now.

Start free →

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