#[non_exhaustive]pub struct CommandHook {
pub command: Option<String>,
pub args: Option<Vec<String>>,
pub timeout: Option<f64>,
pub run_async: Option<bool>,
pub async_rewake: Option<bool>,
pub shell: Option<Shell>,
pub condition: Option<String>,
pub status_message: Option<String>,
pub on_failure: Option<HookOnFailure>,
pub extra: Extra,
}Expand description
A command hook.
Docs: settings reference.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.command: Option<String>Shell command to execute. With args, the executable to spawn directly. See Exec form
and shell form.
- Values: string
Docs: command.
args: Option<Vec<String>>Argument list. When present, command is resolved as an executable and spawned directly
with args as the argument vector, with no shell involved. See Exec form and shell
form.
- Values: array of strings
Docs: args.
timeout: Option<f64>Seconds before canceling. Claude Code doesn’t enforce it on a command hook you run with
async: true.
Defaults: 600 for command, http, and mcp_tool; 30 for prompt; 60 for agent.
- Values: a number
Docs: timeout.
run_async: Option<bool>If true, runs in the background without blocking. See Run hooks in the
background.
- Values: Boolean
Docs: async.
async_rewake: Option<bool>If true, runs in the background and wakes Claude on exit code 2. The hook’s stderr, or
stdout if stderr is empty, is shown to Claude as a system
reminder so it can react to a
long-running background failure.
- Values: Boolean
Docs: asyncRewake.
shell: Option<Shell>Shell to use for this hook. Accepts "bash" or "powershell". Defaults to "bash", or
to "powershell" on Windows when Git Bash isn’t installed.
- Values:
"bash","powershell"
Docs: shell.
condition: Option<String>Permission rule
syntax to filter
when this hook runs, such as "Bash(git *)" or "Edit(*.ts)". The hook command only
runs if the tool call matches the pattern. See the Bash matching
table for how Bash patterns
evaluate against subcommands, $(), and backticks.
- Values: string
Docs: if.
status_message: Option<String>§on_failure: Option<HookOnFailure>Whether the action that triggered the hook goes ahead when the hook fails: "continue"
or "block". See Block the action when a hook
fails for
"block" and for leaving the field unset. Requires Claude Code v2.1.295 or later.
- Values:
"continue"or"block". Requires Claude Code v2.1.295 or later - Default: unset: the action goes ahead on most events
Docs: onFailure.
extra: ExtraKeys Claude Code accepts here that this crate doesn’t model (newer or undocumented ones), kept as written so the document round-trips.