You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: agent-schema.json
+15-1Lines changed: 15 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -411,6 +411,20 @@
411
411
"items": {
412
412
"$ref": "#/definitions/HookDefinition"
413
413
}
414
+
},
415
+
"stop": {
416
+
"type": "array",
417
+
"description": "Hooks that run when the model finishes responding and is about to hand control back to the user. Can perform post-response validation or logging.",
418
+
"items": {
419
+
"$ref": "#/definitions/HookDefinition"
420
+
}
421
+
},
422
+
"notification": {
423
+
"type": "array",
424
+
"description": "Hooks that run when the agent sends a notification (error, warning) to the user. Can send external notifications or log events.",
For `session_start`, `post_tool_use`, and `stop` hooks, plain text written to stdout (i.e., output that is not valid JSON) is captured as additional context for the agent.
192
+
168
193
## Exit Codes
169
194
170
195
Hook exit codes have special meaning:
@@ -175,7 +200,37 @@ Hook exit codes have special meaning:
175
200
| `2` | Blocking error — stop the operation |
176
201
| Other | Error — logged but execution continues |
177
202
178
-
## Example: Validation Script
203
+
## Timeout
204
+
205
+
Hooks have a default timeout of 60 seconds. You can customize this per hook:
206
+
207
+
```yaml
208
+
hooks:
209
+
pre_tool_use:
210
+
- matcher: "*"
211
+
hooks:
212
+
- type: command
213
+
command: "./slow-validation.sh"
214
+
timeout: 120 # 2 minutes
215
+
```
216
+
217
+
<div class="callout callout-warning">
218
+
<div class="callout-title">⚠️ Performance
219
+
</div>
220
+
<p>Hooks run synchronously and can slow down agent execution. Keep hook scripts fast and efficient. Consider using <code>suppress_output: true</code> for logging hooks to reduce noise.</p>
221
+
222
+
</div>
223
+
224
+
<div class="callout callout-info">
225
+
<div class="callout-title">ℹ️ Session End and Cancellation
226
+
</div>
227
+
<p><code>session_end</code> hooks are designed to run even when the session is interrupted (e.g., Ctrl+C). They are still subject to their configured timeout.</p>
228
+
229
+
</div>
230
+
231
+
## Examples
232
+
233
+
### Validation Script
179
234
180
235
A simple pre-tool-use hook that blocks dangerous shell commands:
181
236
@@ -201,7 +256,7 @@ echo '{"decision": "allow"}'
201
256
exit 0
202
257
```
203
258
204
-
## Example: Audit Logging
259
+
### Audit Logging
205
260
206
261
A post-tool-use hook that logs all tool calls:
207
262
@@ -222,24 +277,74 @@ echo '{"continue": true}'
222
277
exit 0
223
278
```
224
279
225
-
## Timeout
280
+
### Session Lifecycle
226
281
227
-
Hooks have a default timeout of 60 seconds. You can customize this per hook:
282
+
Session start and end hooks for environment setup and cleanup:
echo "Session $SESSION_ID ended ($REASON) at $(date)" >> /tmp/agent-session.log
237
303
```
238
304
239
-
<div class="callout callout-warning">
240
-
<div class="callout-title">⚠️ Performance
241
-
</div>
242
-
<p>Hooks run synchronously and can slow down agent execution. Keep hook scripts fast and efficient. Consider using <code>suppress_output: true</code> for logging hooks to reduce noise.</p>
305
+
### Response Logging with Stop Hook
306
+
307
+
Log every model response for analytics or compliance:
0 commit comments