Hooks
Hooks are shell commands that fire automatically on events — before tool calls, after edits, when the model finishes. Configure in dynamo.yaml or .dynamo/hooks/*.yaml.
Configuration
hooks:
- event: PreToolUse
matcher: "run_command"
if: "rm"
command: "echo 'blocked' >&2; exit 2"
- event: PostToolUse
matcher: "edit_file"
command: ".dynamo/hooks/lint.sh"
- event: Stop
command: ".dynamo/hooks/build-gate.sh"
timeout: 30000Hooks can also be defined in separate files under .dynamo/hooks/*.yaml (project) or ~/.config/dynamo/hooks/*.yaml (global).
Events
| Event | When | Use case |
|---|---|---|
| PreToolUse | Before tool executes | Block dangerous commands, modify input |
| PostToolUse | After tool executes | Auto-lint, inject build errors as context |
| Stop | Model finishes responding | Build gates — model auto-fixes errors |
| SessionStart | Session begins | Environment checks, context loading |
| SessionEnd | Session ends | Cleanup, metrics, logging |
Matching
- `matcher` — tool name to match (e.g.
"run_command","edit_file") - `if` — content filter within the tool call (e.g.
"rm"to match only rm commands)
Sequential execution, first block wins.
Exit Codes
| Code | Meaning |
|---|---|
0 | Approve — continue execution. Parse stdout as JSON for structured output. |
2 | Block — prevent the tool from executing |
| Other | Warn — show a warning but continue |
Hooks receive JSON on stdin with the tool call details and can return structured output on stdout.
Managing Hooks
Use /hooks to browse configured hooks — a 3-level picker showing event types, numbered hook list, and detail view with execution history.
Examples
Auto-lint after edits
hooks:
- event: PostToolUse
matcher: "edit_file"
command: "npx eslint --fix ${DYNAMO_FILE_PATH}"Build gate on Stop
hooks:
- event: Stop
command: "npm run build 2>&1 || exit 1"
timeout: 30000When a Stop hook fails, Dynamo feeds the error back to the model which auto-fixes and retries.
Block dangerous commands
hooks:
- event: PreToolUse
matcher: "run_command"
if: "docker"
command: "echo 'Docker commands blocked' >&2; exit 2"