Hooks let you execute shell commands at key points in an agent’s lifecycle. They provide deterministic control that works alongside the LLM’s behavior — useful for validation, logging, environment setup, notifications, and blocking dangerous operations.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/docker/docker-agent/llms.txt
Use this file to discover all available pages before exploring further.
Common use cases:
- Validate or transform tool inputs before execution
- Block dangerous operations based on custom rules
- Log all tool calls to an audit file
- Set up the environment when a session starts
- Send external notifications when errors occur
- Log model responses for analytics or compliance
Hook events
There are seven hook events:| Event | When it fires | Can block? |
|---|---|---|
pre_tool_use | Before a tool call executes | Yes |
post_tool_use | After a tool completes successfully | No |
session_start | When a session begins or resumes | No |
session_end | When a session terminates | No |
on_user_input | When the agent is waiting for user input | No |
stop | When the model finishes responding | No |
notification | When the agent emits a notification (error/warning) | No |
Configuration
Hooks are configured underagents.<name>.hooks:
Hook definition fields
Hook type. Currently only
command is supported.Shell command or inline shell script to execute. Multi-line scripts are supported using YAML block scalars (
|).Execution timeout in seconds. The hook is killed if it exceeds this limit.
Matcher patterns
pre_tool_use and post_tool_use hooks use a matcher field with regex patterns to match tool names:
| Pattern | Matches |
|---|---|
* | All tools |
shell | Only the shell tool |
shell|edit_file | Either shell or edit_file |
mcp:.* | All MCP tools |
Hook input
Hooks receive JSON on stdin with context about the event:Fields by event type
| Field | pre_tool_use | post_tool_use | session_start | session_end | on_user_input | stop | notification |
|---|---|---|---|---|---|---|---|
session_id | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
cwd | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
hook_event_name | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
tool_name | ✓ | ✓ | |||||
tool_use_id | ✓ | ✓ | |||||
tool_input | ✓ | ✓ | |||||
tool_response | ✓ | ||||||
source | ✓ | ||||||
reason | ✓ | ||||||
stop_response | ✓ | ||||||
notification_level | ✓ | ||||||
notification_message | ✓ |
sourceforsession_start:startup,resume,clear, orcompactreasonforsession_end:clear,logout,prompt_input_exit, orothernotification_level:errororwarning
Hook output
Hooks communicate back by writing JSON to stdout:| Field | Type | Description |
|---|---|---|
continue | boolean | Whether to continue execution. Default: true. |
stop_reason | string | Message displayed to the user when continue is false. |
suppress_output | boolean | When true, hides the hook’s stdout from the transcript. |
system_message | string | Warning message displayed to the user. |
Pre-tool-use output
pre_tool_use hooks support additional output via hook_specific_output:
| Field | Values | Description |
|---|---|---|
permission_decision | allow, deny, ask | Override the permission decision for this call |
permission_decision_reason | string | Explanation shown to the user |
updated_input | object | Replacement tool input (replaces original) |
Plain text output
Forsession_start, post_tool_use, and stop hooks, plain text written to stdout (non-JSON) is captured and injected as additional context for the agent.
Exit codes
| Exit code | Meaning |
|---|---|
0 | Success — continue normally |
2 | Blocking error — stop the operation |
| Other | Error — logged, execution continues |
session_end hooks run even when the session is interrupted (e.g., Ctrl+C), subject to their configured timeout.Examples
Block dangerous commands
Audit logging
Session lifecycle
Response logging (stop hook)
Error notifications
notification hook fires when:
- All models fail to respond
- A degenerate tool call loop is detected
- The
max_iterationslimit is reached
CLI flags
Add hooks from the command line without modifying the YAML file:| Flag | Description |
|---|---|
--hook-pre-tool-use | Run a command before every tool call |
--hook-post-tool-use | Run a command after every tool call |
--hook-session-start | Run a command when a session starts |
--hook-session-end | Run a command when a session ends |
--hook-on-user-input | Run a command when waiting for input |
CLI hooks are appended to hooks defined in the YAML config — they don’t replace existing hooks. CLI pre/post-tool-use hooks match all tools (equivalent to
matcher: "*").