Skip to main content

HooksConfig

Struct HooksConfig 

Source
pub struct HooksConfig {
    pub cwd_changed: Vec<HookDef>,
    pub file_changed: Option<FileChangedConfig>,
    pub permission_denied: Vec<HookDef>,
    pub turn_complete: Vec<HookDef>,
    pub hook_block_cap: usize,
    pub pre_tool_use: Vec<HookMatcher>,
    pub post_tool_use: Vec<HookMatcher>,
}
Expand description

Top-level hooks configuration section.

Each sub-section corresponds to a lifecycle event. All sections default to empty (no hooks). Events fire in the order hooks are listed.

Hooks are declared inline in config.toml under the [hooks] table. No separate settings.json or external file is required. Both command and mcp_tool action types are supported for every event.

§Examples

[[hooks.pre_tool_use]]
matcher = "Edit|Write"
[[hooks.pre_tool_use.hooks]]
type = "command"
command = "echo pre $ZEPH_TOOL_NAME"
timeout_secs = 5
fail_closed = false

[[hooks.turn_complete]]
type = "mcp_tool"
server = "notifier"
tool = "notify"
[hooks.turn_complete.args]
channel = "desktop"

Fields§

§cwd_changed: Vec<HookDef>

Hooks fired when the agent’s working directory changes via set_working_directory.

§file_changed: Option<FileChangedConfig>

File-change watcher configuration with associated hooks.

§permission_denied: Vec<HookDef>

Hooks fired when a tool execution is blocked by a RuntimeLayer::before_tool check.

Environment variables set for Command hooks:

  • ZEPH_DENIED_TOOL — the name of the tool that was blocked.
  • ZEPH_DENY_REASON — human-readable reason string from the layer.
§turn_complete: Vec<HookDef>

Hooks fired after each agent turn completes (#3327).

Runs regardless of the [notifications] config. When a [notifications] notifier is also configured, these hooks share its should_fire gate (respecting min_turn_duration_ms, only_on_error, and enabled). When no notifier is configured, hooks fire on every completed turn.

Use min_duration_ms in a wrapper script or the [notifications].min_turn_duration_ms gate to avoid firing on trivial responses.

Environment variables set for Command hooks:

  • ZEPH_TURN_DURATION_MS — wall-clock duration of the turn in milliseconds.
  • ZEPH_TURN_STATUS"success" or "error".
  • ZEPH_TURN_PREVIEW — redacted first ≤ 160 chars of the assistant response.
  • ZEPH_TURN_LLM_REQUESTS — number of completed LLM round-trips this turn.
§hook_block_cap: usize

Maximum number of PreToolUse hook blocks allowed per turn before the turn is ended with a warning message. Counts individual tool blocks — if a tier has N blocked tools, the counter increments by N. Default: 8. Use 0 for no cap (unlimited blocks).

§pre_tool_use: Vec<HookMatcher>

Hooks fired before each tool execution, matched by tool name pattern.

Uses pipe-separated pattern matching (same as subagent hooks). Hooks fire before the RuntimeLayer::before_tool permission check — they observe every attempted tool call, including calls that will be subsequently blocked.

Hook serialization within a tier: hooks for tools in the same dependency tier are dispatched sequentially (one tool’s hooks complete before the next tool’s hooks start). Hooks for tools in different tiers may overlap.

Hooks are fail-open: errors are logged but do not block tool execution.

Environment variables set for Command hooks:

  • ZEPH_TOOL_NAME — name of the tool being invoked.
  • ZEPH_TOOL_ARGS_JSON — JSON-serialized tool arguments (truncated at 64 KiB).
  • ZEPH_SESSION_ID — current conversation identifier, omitted when unavailable.
§post_tool_use: Vec<HookMatcher>

Hooks fired after each tool execution completes, matched by tool name pattern.

Fires after the tool result is available. Same pattern matching and fail-open semantics as pre_tool_use.

Environment variables set for Command hooks:

  • ZEPH_TOOL_NAME — name of the tool that was invoked.
  • ZEPH_TOOL_ARGS_JSON — JSON-serialized tool arguments (truncated at 64 KiB).
  • ZEPH_SESSION_ID — current conversation identifier, omitted when unavailable.
  • ZEPH_TOOL_DURATION_MS — wall-clock execution time in milliseconds.

Implementations§

Source§

impl HooksConfig

Source

pub fn is_empty(&self) -> bool

Returns true when no hooks are configured (all sections are empty or absent).

§Examples
use zeph_config::hooks::HooksConfig;

assert!(HooksConfig::default().is_empty());

Trait Implementations§

Source§

impl Clone for HooksConfig

Source§

fn clone(&self) -> HooksConfig

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 HooksConfig

Source§

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

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

impl Default for HooksConfig

Source§

fn default() -> HooksConfig

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for HooksConfig

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<HooksConfig, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

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

impl Serialize for HooksConfig

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

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