Skip to main content

HookEvent

Enum HookEvent 

Source
#[non_exhaustive]
pub enum HookEvent {
Show 34 variants PreToolUse, PostToolUse, PostToolUseFailure, PostToolBatch, PermissionRequest, PermissionDenied, Notification, UserPromptSubmit, UserPromptExpansion, Stop, StopFailure, SubagentStart, SubagentStop, PreCompact, PostCompact, Elicitation, ElicitationResult, TeammateIdle, TaskCreated, TaskCompleted, Setup, InstructionsLoaded, CwdChanged, FileChanged, ConfigChange, WorktreeCreate, WorktreeRemove, SessionStart, SessionEnd, PreModelSwitch, PostModelSwitch, MessageDisplay, DirectoryAdded, Other(String),
}
Expand description

A hook event: a key of hooks.

Docs: settings reference.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

PreToolUse

Runs after Claude creates tool parameters and before processing the tool call.

Docs: PreToolUse.

§

PostToolUse

Runs immediately after a tool completes successfully.

Docs: PostToolUse.

§

PostToolUseFailure

Runs when a tool that started executing fails: the tool threw an error, or an MCP tool returned an error result.

Docs: PostToolUseFailure.

§

PostToolBatch

Runs once after every tool call in a batch has resolved, before Claude Code sends the next request to the model.

Docs: PostToolBatch.

§

PermissionRequest

Runs when Claude Code is about to ask you for permission to use a tool.

Docs: PermissionRequest.

§

PermissionDenied

Runs when auto mode denies a tool call, including when it denies without a classifier verdict because a safety check separate from auto mode refused the classifier’s own request or its response didn’t parse.

Docs: PermissionDenied.

§

Notification

Runs when Claude Code sends notifications.

Docs: Notification.

§

UserPromptSubmit

Runs when a prompt is submitted, before Claude processes it.

Docs: UserPromptSubmit.

§

UserPromptExpansion

Runs when a user-typed command expands into a prompt before reaching Claude.

Docs: UserPromptExpansion.

§

Stop

Runs when the main Claude Code agent has finished responding.

Docs: Stop.

§

StopFailure

Runs instead of Stop when the turn ends due to an API error.

Docs: StopFailure.

§

SubagentStart

Runs when Claude spawns a subagent with the Agent tool, when Claude resumes a subagent, and each time an in-process agent team teammate handles a new message.

Docs: SubagentStart.

§

SubagentStop

Runs when a Claude Code subagent has finished responding.

Docs: SubagentStop.

§

PreCompact

Runs before Claude Code is about to run a compact operation.

Docs: PreCompact.

§

PostCompact

Runs after Claude Code completes a compact operation.

Docs: PostCompact.

§

Elicitation

Runs when an MCP server requests user input mid-task.

Docs: Elicitation.

§

ElicitationResult

Runs after a user responds to an MCP elicitation.

Docs: ElicitationResult.

§

TeammateIdle

Runs when an agent team teammate is about to go idle after finishing its turn.

Docs: TeammateIdle.

§

TaskCreated

Runs when a task is being created via the TaskCreate tool.

Docs: TaskCreated.

§

TaskCompleted

Runs when a task is being marked as completed.

Docs: TaskCompleted.

§

Setup

Fires only when you launch Claude Code with --init-only, or with --init or --maintenance in non-interactive mode with the -p flag.

Docs: Setup.

§

InstructionsLoaded

Fires when a CLAUDE.md or .claude/rules/*.md file is loaded into context.

Docs: InstructionsLoaded.

§

CwdChanged

Runs when a shell command in the main conversation changes the working directory, for example when Claude executes a cd command.

Docs: CwdChanged.

§

FileChanged

Runs when a watched file changes on disk.

Docs: FileChanged.

§

ConfigChange

Runs when a configuration file changes during a session.

Docs: ConfigChange.

§

WorktreeCreate

Runs when Claude Code creates a worktree in cases such as these:

Docs: WorktreeCreate.

§

WorktreeRemove

Runs when Claude Code cleans up a worktree that your WorktreeCreate hook created.

Docs: WorktreeRemove.

§

SessionStart

Runs when Claude Code starts a new session or resumes an existing session.

Docs: SessionStart.

§

SessionEnd

Runs when a Claude Code session ends.

Docs: SessionEnd.

§

PreModelSwitch

Runs before Claude Code applies a model switch that you or a client requested.

Docs: PreModelSwitch.

§

PostModelSwitch

Runs after the session’s model changes.

Docs: PostModelSwitch.

§

MessageDisplay

Runs while an assistant message streams to the screen.

Docs: MessageDisplay.

§

DirectoryAdded

Runs after you add a working directory mid-session with the /add-dir command, or after an SDK client adds one with the register_repo_root control request.

Docs: DirectoryAdded.

§

Other(String)

A value this crate doesn’t know, as written.

Implementations§

Source§

impl HookEvent

Source

pub fn as_str(&self) -> &str

The value as Claude Code spells it.

Source

pub fn is_known(&self) -> bool

Whether this is a value this crate knows (not Other).

Trait Implementations§

Source§

impl AsRef<str> for HookEvent

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for HookEvent

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HookEvent

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for HookEvent

Source§

fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for HookEvent

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for HookEvent

Source§

impl From<&str> for HookEvent

Source§

fn from(s: &str) -> Self

Converts to this type from the input type.
Source§

impl From<String> for HookEvent

Source§

fn from(s: String) -> Self

Converts to this type from the input type.
Source§

impl Hash for HookEvent

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for HookEvent

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for HookEvent

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for HookEvent

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for HookEvent

Source§

fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for HookEvent

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.