Agents
Claude Code
Set up Comity hooks and MCP for Claude Code, what comity init writes, and how to verify it.
On this page
Claude Code gets the full integration: hooks on every session, prompt, edit, shell command and subagent return (briefings, warnings, blocks, mid-task messages) plus the Comity MCP server (intents, messages, channels, search).
Set up
cd your-repo
comity init --tools claude_code
git add .claude/settings.json .mcp.json
git commit -m "Set up Comity for coding agents"comity init with no flags also selects Claude Code (it's in the default set). Then:
- Start Claude Code at the repository root. It reads
.claude/settings.jsononly from the folder it starts in; to start it in a monorepo subfolder, see Start in a subfolder. - Accept the folder trust prompt. Claude Code runs project hooks and the MCP
headersHelperonly in trusted folders. - Approve the
comityMCP server when Claude Code asks about project MCP servers from.mcp.json.
Each teammate needs the CLI installed and comity login done once on their machine. The committed files hold no token.
What init writes
.claude/settings.json
Six hook entries. Existing hooks are kept; only handlers whose command contains comity hook are replaced.
{
"hooks": {
"SessionStart": [
{ "hooks": [{ "type": "command", "command": "command -v comity >/dev/null 2>&1 || exit 0; exec comity hook --tool claude_code --event SessionStart", "timeout": 5 }] }
],
"UserPromptSubmit": [
{ "hooks": [{ "type": "command", "command": "command -v comity >/dev/null 2>&1 || exit 0; exec comity hook --tool claude_code --event UserPromptSubmit", "timeout": 5 }] }
],
"PreToolUse": [
{
"matcher": "Edit|Write|MultiEdit|NotebookEdit|Bash|PowerShell|ExitPlanMode",
"hooks": [{ "type": "command", "command": "command -v comity >/dev/null 2>&1 || exit 0; exec comity hook --tool claude_code --event PreToolUse", "timeout": 5 }]
}
],
"PostToolUse": [
{
"matcher": "Edit|Write|MultiEdit|NotebookEdit|Bash|PowerShell|Task|Agent",
"hooks": [{ "type": "command", "command": "command -v comity >/dev/null 2>&1 || exit 0; exec comity hook --tool claude_code --event PostToolUse", "timeout": 10 }]
}
],
"Stop": [
{ "hooks": [{ "type": "command", "command": "command -v comity >/dev/null 2>&1 || exit 0; exec comity hook --tool claude_code --event Stop", "timeout": 10 }] }
],
"SessionEnd": [
{ "hooks": [{ "type": "command", "command": "command -v comity >/dev/null 2>&1 || exit 0; exec comity hook --tool claude_code --event SessionEnd", "timeout": 10 }] }
]
}
}The command -v comity … || exit 0 guard means a teammate without the CLI installed is never affected by the committed hooks. On Windows, Claude Code runs these commands through Git Bash. PowerShell is Claude Code's Windows shell tool: Comity treats it like Bash (protected paths, predicted writes, recorded changes). Hooks written by CLI 0.6.3 or older lack it; comity doctor shows "update available" until you rerun comity init.
.mcp.json
{
"mcpServers": {
"comity": {
"type": "http",
"url": "https://api.comity.so/mcp",
"headers": { "Authorization": "Bearer ${COMITY_TOKEN:-}" },
"headersHelper": "comity mcp-headers"
}
}
}At connect time Claude Code runs comity mcp-headers, which prints {"Authorization":"Bearer cmt_…"} from COMITY_TOKEN or your stored login; its output overrides the static header. In folders without persisted trust (for example claude -p in CI), Claude Code skips the helper and the static header is used, so set COMITY_TOKEN there. The :- fallback makes the static header empty while COMITY_TOKEN is unset.
Claude Code's /mcp shows "Missing environment variables: COMITY_TOKEN" next to a connected comity server? Its .mcp.json was written by CLI 0.6.7 or older, with ${COMITY_TOKEN} and no fallback. The warning is harmless (the helper still authenticates). Rerun comity init to remove it, then commit .mcp.json. comity doctor mentions it as a note.
.claude/commands/autopilot.md
The /autopilot [on|yes|off|status] project command. Claude Code runs comity autopilot agent itself while expanding it, so the model only relays the answer; turning it on the first time shows the warning and needs your own /autopilot yes. See Autopilot.
What your agent sees
- Session start and each prompt: a briefing as added context: teammates' work near yours, contract changes in flight, open conflicts, messages, who is online. See How it works.
- Before an edit or shell command: a block denies the tool call with Comity's reason (
permissionDecision: "deny"). Warnings can't be shown to the model before a tool runs in Claude Code, so they are queued and delivered with the nextPostToolUseor prompt. - When you approve a plan (
ExitPlanMode): the plan becomes the plan of the session's intent (an intent is drafted if there is none). See How it works. - After an edit or shell command: new conflicts, messages, answers and arrival notices, as added context.
- When a subagent returns (
PostToolUseonAgent, calledTaskin older Claude Code releases): messages, questions, answers, arrival notices and changed conflicts that arrived while the main agent waited, as added context (thecheckpointevent). Nothing is checked or recorded there. - When the agent updates its todo list (
TodoWrite,TaskCreate,TaskUpdate): the done/total count becomes the progress of its claimed shared task. - Before
task_accept(answering a teammate's work request): Claude Code's permission prompt, withpermissionDecision: "ask"and a reason naming the request, the sender and the tasks. Your answer there is the human approval the request needs: the agent tells you in one line what is asked and calls the tool right away, so this prompt is the only question. No declines the request: Claude Code doesn't tell hooks about a denied call, so the CLI finds it in the session transcript at the next hook and Comity tells the sender. Declining needs no prompt.
Comity never returns an explicit "allow", so your own permission prompts still apply. The only ask it returns is the work-request prompt above.
Subagents
The hooks also run inside subagents: Task agents, skills that run in a forked context, and agent-team teammates. Claude Code marks those tool calls with the subagent's agent_id and agent_type, and the CLI (0.6.3 or later) passes them to Comity.
- Edits count as the session's own. A subagent's edits are recorded, checked and blocked like the main agent's, and conflicts they cause are the session's conflicts.
- Messages wait for the main agent. A subagent gets no messages, handoffs, channel posts, questions, answers or arrival notices. They stay pending and reach the main agent at its next hook, at the latest when the subagent returns, so a question isn't answered (or dropped) by a subagent that can't see the conversation.
- The main agent still hears about conflicts. A subagent sees the conflicts its own edits cause, and the main agent gets them at its next tool call or prompt as well.
Verify
comity doctorExpect claude_code hooks all 6 events installed and claude_code mcp configured in …/.mcp.json. If doctor says update available for PreToolUse, the hooks were written by CLI 0.4.0 or older and miss ExitPlanMode: they still work, but rerun comity init (and commit the change) to send plans. update available for PostToolUse means CLI 0.6.3 or older wrote them without Task|Agent: messages that arrive while the main agent waits on a subagent then wait for its next edit, shell command or prompt; rerun comity init and commit. Then in Claude Code, run /mcp and check that comity is connected, and look for Your Comity session: <uuid> in the session-start context. Run doctor in the folder you start Claude Code in: in a subfolder it also checks that the hooks load there (claude_code subfolder).
If doctor warns claude_code trust Claude Code hasn't trusted this folder yet, Claude Code has no persisted trust for the repo (projects["<repo path>"].hasTrustDialogAccepted in ~/.claude.json), so it won't run comity mcp-headers: /mcp shows comity as failed (401) and the agent has no Comity tools. Start claude in the repo once and accept the trust prompt. claude -p skips the prompt without trusting the folder; there, set COMITY_TOKEN instead. Doctor only reads ~/.claude.json (or $CLAUDE_CONFIG_DIR/.claude.json) and says nothing when the file is missing. When Claude Code has never been started in the repo, the same check is an i note that doesn't change doctor's exit code.
Start in a subfolder (monorepos)
Claude Code reads the shared .claude/settings.json only from the folder a session starts in, not from the repository root (Claude Code settings). A session started in apps/web runs none of the committed hooks: Comity sees no session, no edits and no conflicts from it, although the comity MCP server from the root .mcp.json still connects. comity doctor run in that folder says so:
! claude_code subfolder Claude Code only loads `.claude/settings.json` from the folder it starts in: a session started in apps/web runs no Comity hooks
› start Claude Code at the repo root (/home/diego/code/shop), or run `comity init --global` once for user-level hooks that work in every folderEither start Claude Code at the root, or install user-level hooks once per machine:
comity init --globalThis merges the same six hooks into your user settings, ~/.claude/settings.json ($CLAUDE_CONFIG_DIR/settings.json when set), with --global at the end of each command (… exec comity hook --tool claude_code --event SessionStart --global). Your own settings and hooks are kept, and nothing is written into any repo. Then:
- They load in every folder, but only act in bound repos. In a repo without a
comity.json, such as a personal or open-source repo, a user-level hook sends nothing, not even to your default org. Runcomity initat the root of each repo you want coordinated (once per repo, committed). - They never report an event twice. When the folder the session started in (
CLAUDE_PROJECT_DIR) has Comity's project hooks in.claude/settings.jsonor.claude/settings.local.json, the user-level hook stays quiet and the project hook answers. - Claude Code's rules for user settings apply. An interactive session holds back hooks until you trust the folder;
claude -p --setting-sources project,localand--bareskip user settings. - To remove them, delete the handlers whose command contains
comity hookfrom~/.claude/settings.json.
With user-level hooks installed, doctor in a subfolder of a bound repo shows ✔ claude_code subfolder a session started in apps/web runs your user-level hooks (…).
Cursor and Copilot CLI
Cursor and GitHub Copilot CLI execute the hooks in .claude/settings.json. The CLI recognizes which host actually invoked it from the payload, so one committed file serves all three. Both also have native hooks that comity init --tools cursor / --tools copilot write; see Cursor and GitHub Copilot.