claude_code_settings/hooks.rs
1//! `hooks`: event → matcher groups → hooks.
2
3use alloc::collections::BTreeMap;
4use alloc::string::String;
5use alloc::vec::Vec;
6
7use serde::{Deserialize, Serialize};
8use serde_json::{Map, Value};
9
10use crate::Extra;
11use crate::enums::{HookEvent, HookOnFailure, Shell};
12use crate::walk::{Unknown, join, walk};
13
14/// `hooks`: for each [`HookEvent`], its matcher groups.
15///
16/// Claude Code runs every group whose `matcher` matches the event, and the
17/// hooks of all matching groups in parallel. Across settings layers the
18/// groups of an event add up (see [`merge_values`](crate::merge_values));
19/// an identical handler defined in two files runs once. An event name
20/// Claude Code doesn't know is skipped with a warning; this crate keeps it as
21/// [`HookEvent::Other`].
22///
23/// - **Default**: unset, so no hooks run.
24/// - **Scope**: any settings file. With `allowManagedHooksOnly` set in managed
25/// settings, only managed hooks run; `disableAllHooks` turns all of them off.
26///
27/// Docs: [`hooks`](https://code.claude.com/docs/en/settings-reference#hooks),
28/// [hooks reference](https://code.claude.com/docs/en/hooks).
29pub type Hooks = BTreeMap<HookEvent, Vec<HookMatcher>>;
30
31/// A matcher group: the hooks to run when `matcher` matches the event.
32///
33/// Docs: [matcher patterns](https://code.claude.com/docs/en/hooks#matcher-patterns).
34#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
35#[serde(rename_all = "camelCase")]
36#[non_exhaustive]
37pub struct HookMatcher {
38 /// What the group matches, case-sensitive. Each event matches on its own
39 /// field: the tool name for tool events, the agent type for subagent
40 /// events, the source for `SessionStart`, and so on.
41 ///
42 /// - **Values**: `"*"`, `""` or unset matches everything; a string of only
43 /// letters, digits, `_`, `-`, spaces, `,` and `|` is an exact name or a
44 /// list of names (`Edit|Write`); anything else is an unanchored
45 /// JavaScript regular expression (`mcp__memory__.*`).
46 /// - **Default**: unset: every occurrence of the event.
47 ///
48 /// Docs: [`matcher`](https://code.claude.com/docs/en/hooks#matcher-patterns).
49 #[serde(skip_serializing_if = "Option::is_none")]
50 pub matcher: Option<String>,
51 /// The handlers to run, in parallel, when the group matches.
52 ///
53 /// - **Values**: [`Hook`]s: `command`, `http`, `mcp_tool`, `prompt` or
54 /// `agent`.
55 /// - **Default**: none: Claude Code requires the key, so this crate always
56 /// writes it (an empty list when unset).
57 ///
58 /// Docs: [hook handler fields](https://code.claude.com/docs/en/hooks#hook-handler-fields).
59 #[serde(default)]
60 pub hooks: Vec<Hook>,
61 /// Keys Claude Code accepts here that this crate doesn't model (newer or
62 /// undocumented ones), kept as written so the document round-trips.
63 #[serde(flatten)]
64 pub extra: Extra,
65}
66
67impl HookMatcher {
68 /// A group that runs `hooks` on every occurrence of the event.
69 pub fn all(hooks: impl IntoIterator<Item = Hook>) -> Self {
70 Self {
71 hooks: hooks.into_iter().collect(),
72 ..Self::default()
73 }
74 }
75
76 /// A group that runs `hooks` when `matcher` matches.
77 pub fn matching(matcher: impl Into<String>, hooks: impl IntoIterator<Item = Hook>) -> Self {
78 Self {
79 matcher: Some(matcher.into()),
80 ..Self::all(hooks)
81 }
82 }
83}
84
85walk!(HookMatcher { hooks: "hooks" });
86
87/// A hook, by its `type`.
88#[derive(Debug, Clone, PartialEq)]
89#[non_exhaustive]
90pub enum Hook {
91 /// `command`: run a shell command (or a program, with `args`).
92 Command(CommandHook),
93 /// `prompt`: ask a model about the event.
94 Prompt(PromptHook),
95 /// `agent`: have an agent verify something.
96 Agent(AgentHook),
97 /// `http`: `POST` the event to a URL.
98 Http(HttpHook),
99 /// `mcp_tool`: call a tool on a connected MCP server.
100 McpTool(McpToolHook),
101 /// A `type` this crate doesn't know (or none), the whole object as
102 /// written.
103 Other(Map<String, Value>),
104}
105
106impl Hook {
107 /// A command hook running `command`.
108 pub fn command(command: impl Into<String>) -> Self {
109 Self::Command(CommandHook::new(command))
110 }
111
112 /// The hook's `type`.
113 pub fn kind(&self) -> Option<&str> {
114 match self {
115 Self::Command(_) => Some("command"),
116 Self::Prompt(_) => Some("prompt"),
117 Self::Agent(_) => Some("agent"),
118 Self::Http(_) => Some("http"),
119 Self::McpTool(_) => Some("mcp_tool"),
120 Self::Other(m) => m.get("type").and_then(Value::as_str),
121 }
122 }
123}
124
125impl Serialize for Hook {
126 fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
127 let inner = match self {
128 Self::Command(h) => serde_json::to_value(h),
129 Self::Prompt(h) => serde_json::to_value(h),
130 Self::Agent(h) => serde_json::to_value(h),
131 Self::Http(h) => serde_json::to_value(h),
132 Self::McpTool(h) => serde_json::to_value(h),
133 Self::Other(m) => return m.serialize(s),
134 };
135 let Value::Object(mut obj) = inner.map_err(serde::ser::Error::custom)? else {
136 return Err(serde::ser::Error::custom("a hook serializes as an object"));
137 };
138 if let Some(kind) = self.kind() {
139 obj.insert("type".into(), kind.into());
140 }
141 obj.serialize(s)
142 }
143}
144
145impl<'de> Deserialize<'de> for Hook {
146 fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
147 fn parse<T: serde::de::DeserializeOwned, E: serde::de::Error>(
148 mut obj: Map<String, Value>,
149 ) -> Result<T, E> {
150 obj.remove("type");
151 serde_json::from_value(Value::Object(obj)).map_err(E::custom)
152 }
153 let obj = Map::<String, Value>::deserialize(d)?;
154 Ok(match obj.get("type").and_then(Value::as_str) {
155 Some("command") => Self::Command(parse(obj)?),
156 Some("prompt") => Self::Prompt(parse(obj)?),
157 Some("agent") => Self::Agent(parse(obj)?),
158 Some("http") => Self::Http(parse(obj)?),
159 Some("mcp_tool") => Self::McpTool(parse(obj)?),
160 _ => Self::Other(obj),
161 })
162 }
163}
164
165impl Unknown for Hook {
166 fn unknown(&self, path: &str, out: &mut Vec<String>) {
167 match self {
168 Self::Command(h) => h.unknown(path, out),
169 Self::Prompt(h) => h.unknown(path, out),
170 Self::Agent(h) => h.unknown(path, out),
171 Self::Http(h) => h.unknown(path, out),
172 Self::McpTool(h) => h.unknown(path, out),
173 Self::Other(_) => out.push(join(path, "type")),
174 }
175 }
176}
177
178/// A `command` hook.
179///
180/// Docs: [settings reference](https://code.claude.com/docs/en/hooks#command-hook-fields).
181#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
182#[serde(rename_all = "camelCase")]
183#[non_exhaustive]
184pub struct CommandHook {
185 /// Shell command to execute. With `args`, the executable to spawn directly. See [Exec form
186 /// and shell form](https://code.claude.com/docs/en/hooks#exec-form-and-shell-form).
187 ///
188 /// - **Values**: string
189 ///
190 /// Docs: [`command`](https://code.claude.com/docs/en/hooks#command-hook-fields).
191 #[serde(skip_serializing_if = "Option::is_none")]
192 pub command: Option<String>,
193 /// Argument list. When present, `command` is resolved as an executable and spawned directly
194 /// with `args` as the argument vector, with no shell involved. See [Exec form and shell
195 /// form](https://code.claude.com/docs/en/hooks#exec-form-and-shell-form).
196 ///
197 /// - **Values**: array of strings
198 ///
199 /// Docs: [`args`](https://code.claude.com/docs/en/hooks#command-hook-fields).
200 #[serde(skip_serializing_if = "Option::is_none")]
201 pub args: Option<Vec<String>>,
202 /// Seconds before canceling. Claude Code doesn't enforce it on a command hook you run with
203 /// [`async: true`](https://code.claude.com/docs/en/hooks#run-hooks-in-the-background).
204 /// Defaults: 600 for `command`, `http`, and `mcp_tool`; 30 for `prompt`; 60 for `agent`.
205 ///
206 /// - **Values**: a number
207 ///
208 /// Docs: [`timeout`](https://code.claude.com/docs/en/hooks#common-fields).
209 #[serde(skip_serializing_if = "Option::is_none")]
210 pub timeout: Option<f64>,
211 /// If `true`, runs in the background without blocking. See [Run hooks in the
212 /// background](https://code.claude.com/docs/en/hooks#run-hooks-in-the-background).
213 ///
214 /// - **Values**: Boolean
215 ///
216 /// Docs: [`async`](https://code.claude.com/docs/en/hooks#command-hook-fields).
217 #[serde(rename = "async", skip_serializing_if = "Option::is_none")]
218 pub run_async: Option<bool>,
219 /// If `true`, runs in the background and wakes Claude on exit code 2. The hook's stderr, or
220 /// stdout if stderr is empty, is shown to Claude as a [system
221 /// reminder](https://code.claude.com/docs/en/glossary#system-reminder) so it can react to a
222 /// long-running background failure.
223 ///
224 /// - **Values**: Boolean
225 ///
226 /// Docs: [`asyncRewake`](https://code.claude.com/docs/en/hooks#command-hook-fields).
227 #[serde(skip_serializing_if = "Option::is_none")]
228 pub async_rewake: Option<bool>,
229 /// Shell to use for this hook. Accepts `"bash"` or `"powershell"`. Defaults to `"bash"`, or
230 /// to `"powershell"` on Windows when Git Bash isn't installed.
231 ///
232 /// - **Values**: `"bash"`, `"powershell"`
233 ///
234 /// Docs: [`shell`](https://code.claude.com/docs/en/hooks#command-hook-fields).
235 #[serde(skip_serializing_if = "Option::is_none")]
236 pub shell: Option<Shell>,
237 /// [Permission rule
238 /// syntax](https://code.claude.com/docs/en/permissions#permission-rule-syntax) to filter
239 /// when this hook runs, such as `"Bash(git *)"` or `"Edit(*.ts)"`. The hook command only
240 /// runs if the tool call matches the pattern. See the [Bash matching
241 /// table](https://code.claude.com/docs/en/hooks#bash-if-matching) for how Bash patterns
242 /// evaluate against subcommands, `$()`, and backticks.
243 ///
244 /// - **Values**: string
245 ///
246 /// Docs: [`if`](https://code.claude.com/docs/en/hooks#common-fields).
247 #[serde(rename = "if", skip_serializing_if = "Option::is_none")]
248 pub condition: Option<String>,
249 /// Custom spinner message displayed while the hook runs.
250 ///
251 /// - **Values**: string
252 ///
253 /// Docs: [`statusMessage`](https://code.claude.com/docs/en/hooks#common-fields).
254 #[serde(skip_serializing_if = "Option::is_none")]
255 pub status_message: Option<String>,
256 /// Whether the action that triggered the hook goes ahead when the hook fails: `"continue"`
257 /// or `"block"`. See [Block the action when a hook
258 /// fails](https://code.claude.com/docs/en/hooks#block-the-action-when-a-hook-fails) for
259 /// `"block"` and for leaving the field unset. Requires Claude Code v2.1.295 or later.
260 ///
261 /// - **Values**: `"continue"` or `"block"`. Requires Claude Code v2.1.295 or later
262 /// - **Default**: unset: the action goes ahead on most events
263 ///
264 /// Docs: [`onFailure`](https://code.claude.com/docs/en/hooks#command-hook-fields).
265 #[serde(skip_serializing_if = "Option::is_none")]
266 pub on_failure: Option<HookOnFailure>,
267 /// Keys Claude Code accepts here that this crate doesn't model (newer or
268 /// undocumented ones), kept as written so the document round-trips.
269 #[serde(flatten)]
270 pub extra: Extra,
271}
272
273impl CommandHook {
274 /// A command hook running `command` in a shell.
275 pub fn new(command: impl Into<String>) -> Self {
276 Self {
277 command: Some(command.into()),
278 ..Self::default()
279 }
280 }
281
282 /// Sets `timeout`, in seconds.
283 #[must_use]
284 pub fn with_timeout(mut self, seconds: f64) -> Self {
285 self.timeout = Some(seconds);
286 self
287 }
288}
289
290/// A `prompt` hook.
291///
292/// Docs: [settings reference](https://code.claude.com/docs/en/hooks#prompt-and-agent-hook-fields).
293#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
294#[serde(rename_all = "camelCase")]
295#[non_exhaustive]
296pub struct PromptHook {
297 /// Prompt text to send to the model. Use `$ARGUMENTS` as a placeholder for the hook input
298 /// JSON. Escape with a backslash to include literal text: `\$1.00` renders as `$1.00`.
299 ///
300 /// - **Values**: string
301 ///
302 /// Docs: [`prompt`](https://code.claude.com/docs/en/hooks#prompt-and-agent-hook-fields).
303 #[serde(skip_serializing_if = "Option::is_none")]
304 pub prompt: Option<String>,
305 /// Model to use for evaluation. Defaults to the model Claude Code uses for [background
306 /// functionality](https://code.claude.com/docs/en/model-config#environment-variables).
307 ///
308 /// - **Values**: string
309 ///
310 /// Docs: [`model`](https://code.claude.com/docs/en/hooks#prompt-and-agent-hook-fields).
311 #[serde(skip_serializing_if = "Option::is_none")]
312 pub model: Option<String>,
313 /// Seconds before canceling. Claude Code doesn't enforce it on a command hook you run with
314 /// [`async: true`](https://code.claude.com/docs/en/hooks#run-hooks-in-the-background).
315 /// Defaults: 600 for `command`, `http`, and `mcp_tool`; 30 for `prompt`; 60 for `agent`.
316 ///
317 /// - **Values**: a number
318 ///
319 /// Docs: [`timeout`](https://code.claude.com/docs/en/hooks#common-fields).
320 #[serde(skip_serializing_if = "Option::is_none")]
321 pub timeout: Option<f64>,
322 /// [Permission rule
323 /// syntax](https://code.claude.com/docs/en/permissions#permission-rule-syntax) to filter
324 /// when this hook runs, such as `"Bash(git *)"` or `"Edit(*.ts)"`. The hook command only
325 /// runs if the tool call matches the pattern. See the [Bash matching
326 /// table](https://code.claude.com/docs/en/hooks#bash-if-matching) for how Bash patterns
327 /// evaluate against subcommands, `$()`, and backticks.
328 ///
329 /// - **Values**: string
330 ///
331 /// Docs: [`if`](https://code.claude.com/docs/en/hooks#common-fields).
332 #[serde(rename = "if", skip_serializing_if = "Option::is_none")]
333 pub condition: Option<String>,
334 /// Custom spinner message displayed while the hook runs.
335 ///
336 /// - **Values**: string
337 ///
338 /// Docs: [`statusMessage`](https://code.claude.com/docs/en/hooks#common-fields).
339 #[serde(skip_serializing_if = "Option::is_none")]
340 pub status_message: Option<String>,
341 /// When the prompt returns ok: false, feed the reason back to Claude and continue the turn
342 /// instead of stopping. Implemented as continue: true on the resulting decision: "block".
343 ///
344 /// - **Values**: Boolean
345 /// - **Default**: `false`
346 ///
347 /// Docs: not in the settings reference; listed in the
348 /// [JSON schema](https://json.schemastore.org/claude-code-settings.json).
349 #[serde(skip_serializing_if = "Option::is_none")]
350 pub continue_on_block: Option<bool>,
351 /// Keys Claude Code accepts here that this crate doesn't model (newer or
352 /// undocumented ones), kept as written so the document round-trips.
353 #[serde(flatten)]
354 pub extra: Extra,
355}
356
357/// An `agent` hook.
358///
359/// Docs: [settings reference](https://code.claude.com/docs/en/hooks#prompt-and-agent-hook-fields).
360#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
361#[serde(rename_all = "camelCase")]
362#[non_exhaustive]
363pub struct AgentHook {
364 /// Prompt text to send to the model. Use `$ARGUMENTS` as a placeholder for the hook input
365 /// JSON. Escape with a backslash to include literal text: `\$1.00` renders as `$1.00`.
366 ///
367 /// - **Values**: string
368 ///
369 /// Docs: [`prompt`](https://code.claude.com/docs/en/hooks#prompt-and-agent-hook-fields).
370 #[serde(skip_serializing_if = "Option::is_none")]
371 pub prompt: Option<String>,
372 /// Model to use for evaluation. Defaults to the model Claude Code uses for [background
373 /// functionality](https://code.claude.com/docs/en/model-config#environment-variables).
374 ///
375 /// - **Values**: string
376 ///
377 /// Docs: [`model`](https://code.claude.com/docs/en/hooks#prompt-and-agent-hook-fields).
378 #[serde(skip_serializing_if = "Option::is_none")]
379 pub model: Option<String>,
380 /// Seconds before canceling. Claude Code doesn't enforce it on a command hook you run with
381 /// [`async: true`](https://code.claude.com/docs/en/hooks#run-hooks-in-the-background).
382 /// Defaults: 600 for `command`, `http`, and `mcp_tool`; 30 for `prompt`; 60 for `agent`.
383 ///
384 /// - **Values**: a number
385 ///
386 /// Docs: [`timeout`](https://code.claude.com/docs/en/hooks#common-fields).
387 #[serde(skip_serializing_if = "Option::is_none")]
388 pub timeout: Option<f64>,
389 /// [Permission rule
390 /// syntax](https://code.claude.com/docs/en/permissions#permission-rule-syntax) to filter
391 /// when this hook runs, such as `"Bash(git *)"` or `"Edit(*.ts)"`. The hook command only
392 /// runs if the tool call matches the pattern. See the [Bash matching
393 /// table](https://code.claude.com/docs/en/hooks#bash-if-matching) for how Bash patterns
394 /// evaluate against subcommands, `$()`, and backticks.
395 ///
396 /// - **Values**: string
397 ///
398 /// Docs: [`if`](https://code.claude.com/docs/en/hooks#common-fields).
399 #[serde(rename = "if", skip_serializing_if = "Option::is_none")]
400 pub condition: Option<String>,
401 /// Custom spinner message displayed while the hook runs.
402 ///
403 /// - **Values**: string
404 ///
405 /// Docs: [`statusMessage`](https://code.claude.com/docs/en/hooks#common-fields).
406 #[serde(skip_serializing_if = "Option::is_none")]
407 pub status_message: Option<String>,
408 /// Keys Claude Code accepts here that this crate doesn't model (newer or
409 /// undocumented ones), kept as written so the document round-trips.
410 #[serde(flatten)]
411 pub extra: Extra,
412}
413
414/// An `http` hook.
415///
416/// Docs: [settings reference](https://code.claude.com/docs/en/hooks#http-hook-fields).
417#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
418#[serde(rename_all = "camelCase")]
419#[non_exhaustive]
420pub struct HttpHook {
421 /// URL to send the POST request to.
422 ///
423 /// - **Values**: string
424 ///
425 /// Docs: [`url`](https://code.claude.com/docs/en/hooks#http-hook-fields).
426 #[serde(skip_serializing_if = "Option::is_none")]
427 pub url: Option<String>,
428 /// Additional HTTP headers as key-value pairs. Values support environment variable
429 /// interpolation using `$VAR_NAME` or `${VAR_NAME}` syntax. Only variables listed in
430 /// `allowedEnvVars` are resolved.
431 ///
432 /// - **Values**: object
433 ///
434 /// Docs: [`headers`](https://code.claude.com/docs/en/hooks#http-hook-fields).
435 #[serde(skip_serializing_if = "Option::is_none")]
436 pub headers: Option<BTreeMap<String, String>>,
437 /// List of environment variable names that may be interpolated into header values.
438 /// References to unlisted variables are replaced with empty strings. Required for any env
439 /// var interpolation to work.
440 ///
441 /// - **Values**: array of strings
442 ///
443 /// Docs: [`allowedEnvVars`](https://code.claude.com/docs/en/hooks#http-hook-fields).
444 #[serde(skip_serializing_if = "Option::is_none")]
445 pub allowed_env_vars: Option<Vec<String>>,
446 /// Seconds before canceling. Claude Code doesn't enforce it on a command hook you run with
447 /// [`async: true`](https://code.claude.com/docs/en/hooks#run-hooks-in-the-background).
448 /// Defaults: 600 for `command`, `http`, and `mcp_tool`; 30 for `prompt`; 60 for `agent`.
449 ///
450 /// - **Values**: a number
451 ///
452 /// Docs: [`timeout`](https://code.claude.com/docs/en/hooks#common-fields).
453 #[serde(skip_serializing_if = "Option::is_none")]
454 pub timeout: Option<f64>,
455 /// [Permission rule
456 /// syntax](https://code.claude.com/docs/en/permissions#permission-rule-syntax) to filter
457 /// when this hook runs, such as `"Bash(git *)"` or `"Edit(*.ts)"`. The hook command only
458 /// runs if the tool call matches the pattern. See the [Bash matching
459 /// table](https://code.claude.com/docs/en/hooks#bash-if-matching) for how Bash patterns
460 /// evaluate against subcommands, `$()`, and backticks.
461 ///
462 /// - **Values**: string
463 ///
464 /// Docs: [`if`](https://code.claude.com/docs/en/hooks#common-fields).
465 #[serde(rename = "if", skip_serializing_if = "Option::is_none")]
466 pub condition: Option<String>,
467 /// Custom spinner message displayed while the hook runs.
468 ///
469 /// - **Values**: string
470 ///
471 /// Docs: [`statusMessage`](https://code.claude.com/docs/en/hooks#common-fields).
472 #[serde(skip_serializing_if = "Option::is_none")]
473 pub status_message: Option<String>,
474 /// What happens to the action when the hook fails: `"continue"`, the default, or `"block"`.
475 /// See [Block the action when a hook
476 /// fails](https://code.claude.com/docs/en/hooks#block-the-action-when-a-hook-fails).
477 /// Requires Claude Code v2.1.295 or later.
478 ///
479 /// - **Values**: `"continue"` or `"block"`. Requires Claude Code v2.1.295 or later
480 /// - **Default**: `"continue"`
481 ///
482 /// Docs: [`onFailure`](https://code.claude.com/docs/en/hooks#http-hook-fields).
483 #[serde(skip_serializing_if = "Option::is_none")]
484 pub on_failure: Option<HookOnFailure>,
485 /// Keys Claude Code accepts here that this crate doesn't model (newer or
486 /// undocumented ones), kept as written so the document round-trips.
487 #[serde(flatten)]
488 pub extra: Extra,
489}
490
491/// An `mcp_tool` hook.
492///
493/// Docs: [settings reference](https://code.claude.com/docs/en/hooks#mcp-tool-hook-fields).
494#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
495#[serde(rename_all = "camelCase")]
496#[non_exhaustive]
497pub struct McpToolHook {
498 /// Name of a configured MCP server. For a [plugin-bundled
499 /// server](https://code.claude.com/docs/en/mcp#plugin-provided-mcp-servers), this is the
500 /// scoped name `plugin:<plugin-name>:<server-name>`, such as `plugin:my-plugin:db`, not the
501 /// bare server key.
502 ///
503 /// - **Values**: string
504 ///
505 /// Docs: [`server`](https://code.claude.com/docs/en/hooks#mcp-tool-hook-fields).
506 #[serde(skip_serializing_if = "Option::is_none")]
507 pub server: Option<String>,
508 /// Name of the tool to call on that server.
509 ///
510 /// - **Values**: string
511 ///
512 /// Docs: [`tool`](https://code.claude.com/docs/en/hooks#mcp-tool-hook-fields).
513 #[serde(skip_serializing_if = "Option::is_none")]
514 pub tool: Option<String>,
515 /// Arguments passed to the tool. String values support `${path}` substitution from the
516 /// hook's [JSON input](https://code.claude.com/docs/en/hooks#hook-input-and-output), such
517 /// as `"${tool_input.file_path}"`.
518 ///
519 /// - **Values**: object
520 ///
521 /// Docs: [`input`](https://code.claude.com/docs/en/hooks#mcp-tool-hook-fields).
522 #[serde(skip_serializing_if = "Option::is_none")]
523 pub input: Option<Map<String, Value>>,
524 /// Seconds before canceling. Claude Code doesn't enforce it on a command hook you run with
525 /// [`async: true`](https://code.claude.com/docs/en/hooks#run-hooks-in-the-background).
526 /// Defaults: 600 for `command`, `http`, and `mcp_tool`; 30 for `prompt`; 60 for `agent`.
527 ///
528 /// - **Values**: a number
529 ///
530 /// Docs: [`timeout`](https://code.claude.com/docs/en/hooks#common-fields).
531 #[serde(skip_serializing_if = "Option::is_none")]
532 pub timeout: Option<f64>,
533 /// [Permission rule
534 /// syntax](https://code.claude.com/docs/en/permissions#permission-rule-syntax) to filter
535 /// when this hook runs, such as `"Bash(git *)"` or `"Edit(*.ts)"`. The hook command only
536 /// runs if the tool call matches the pattern. See the [Bash matching
537 /// table](https://code.claude.com/docs/en/hooks#bash-if-matching) for how Bash patterns
538 /// evaluate against subcommands, `$()`, and backticks.
539 ///
540 /// - **Values**: string
541 ///
542 /// Docs: [`if`](https://code.claude.com/docs/en/hooks#common-fields).
543 #[serde(rename = "if", skip_serializing_if = "Option::is_none")]
544 pub condition: Option<String>,
545 /// Custom spinner message displayed while the hook runs.
546 ///
547 /// - **Values**: string
548 ///
549 /// Docs: [`statusMessage`](https://code.claude.com/docs/en/hooks#common-fields).
550 #[serde(skip_serializing_if = "Option::is_none")]
551 pub status_message: Option<String>,
552 /// Keys Claude Code accepts here that this crate doesn't model (newer or
553 /// undocumented ones), kept as written so the document round-trips.
554 #[serde(flatten)]
555 pub extra: Extra,
556}
557
558walk!(CommandHook {});
559walk!(PromptHook {});
560walk!(AgentHook {});
561walk!(HttpHook {});
562walk!(McpToolHook {});