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
- Global hooks (
~/.ccd/settings.json) run on the machine CCD runs on. They are owned by whoever operates the CCD server. - Project hooks (
<project>/.ccd/settings.json) run only on the project's own node, through the same sandboxed command path as any agent command, and only when the project is trusted. A project cannot grant itself trust: trust comes from the server operator's settings. On the hosted service, project hooks are therefore off until DENDAT enables them for your project. Ask support if you need them.
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" }]
}
]
}
}
matcheris an anchored, case-insensitive regular expression against the tool name. Empty or*matches every tool.- Matchers can use either CCD tool names or the familiar names:
execandrun_backgroundareBash;write_fileisWrite;edit_file,edit,apply_patchareEdit;multi_editisMultiEdit;read_fileisRead;grep,glob,ls,web_search,web_fetchmap toGrep,Glob,LS,WebSearch,WebFetch;dispatch_aiisTask. timeoutis in seconds. Default 30, maximum 120.- At most 20 hooks run per event. Identical commands are de-duplicated.
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.