Hooks

Hooks run your own scripts at fixed points in an agent run. Use them to block a dangerous command, run a linter after every edit, or add context at the start of a session.

Availability and trust

Because project hooks never run without that trust, a cloned repository cannot execute code just by being opened.

Events

Event When it runs Extra stdin fields Exit 2 does
PreToolUse Before a tool call tool_name, tool_input Blocks the call
PostToolUse After a tool call tool_name, tool_input, tool_response (output, success) Feeds stderr back to the model
UserPromptSubmit When you send a message prompt Blocks the message
SessionStart When a session starts or resumes source (startup or resume) Nothing special; stdout is added as context
Stop When the agent is about to finish stop_hook_active, last_assistant_message Keeps the agent working, with stderr as the reason

Configuration

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [{ "type": "command", "command": "./.ccd/hooks/check.sh", "timeout": 10 }]
      }
    ],
    "PostToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [{ "type": "command", "command": "./.ccd/hooks/lint.sh" }]
      }
    ]
  }
}

The protocol

The command receives one JSON object on stdin:

{
  "hook_event_name": "PreToolUse",
  "session_id": "...",
  "cwd": "/path/to/project",
  "tool_name": "exec",
  "tool_input": { "cmd": "rm -rf build" }
}

It answers with its exit code:

Exit code Meaning
0 OK. For UserPromptSubmit and SessionStart, plain stdout is added to the agent's context. Stdout JSON may refine the outcome (below).
2 Block. stderr is fed back to the model as the reason.
anything else, timeout, crash Ignored. A broken hook never stops a run.

Stdout JSON the runner understands:

{ "decision": "block", "reason": "..." }
{ "continue": false, "stopReason": "..." }
{ "systemMessage": "..." }
{ "hookSpecificOutput": {
    "permissionDecision": "deny",
    "permissionDecisionReason": "...",
    "updatedInput": { "cmd": "rm -rf build/" },
    "additionalContext": "..." } }

Example: block git push --force

.ccd/hooks/check.sh:

#!/usr/bin/env bash
# reads the hook JSON on stdin; exit 2 blocks the call
payload=$(cat)
if echo "$payload" | grep -q 'git push.*--force'; then
  echo "Force pushes are not allowed in this project." >&2
  exit 2
fi
exit 0

Make it executable with chmod +x .ccd/hooks/check.sh.

Kill switches

Set "disableAllHooks": true in the global settings, or start the server with CCD_HOOKS_DISABLED=1. Either turns every hook off.

Hooks versus permission rules

Use permission rules for simple allow and deny decisions on commands and paths. Use hooks when you need logic, such as running a script or editing the input.