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: usizeMaximum 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§
Trait Implementations§
Source§impl Clone for HooksConfig
impl Clone for HooksConfig
Source§fn clone(&self) -> HooksConfig
fn clone(&self) -> HooksConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for HooksConfig
impl Debug for HooksConfig
Source§impl Default for HooksConfig
impl Default for HooksConfig
Source§fn default() -> HooksConfig
fn default() -> HooksConfig
Source§impl<'de> Deserialize<'de> for HooksConfigwhere
HooksConfig: Default,
impl<'de> Deserialize<'de> for HooksConfigwhere
HooksConfig: Default,
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<HooksConfig, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<HooksConfig, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for HooksConfig
impl Serialize for HooksConfig
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl Freeze for HooksConfig
impl RefUnwindSafe for HooksConfig
impl Send for HooksConfig
impl Sync for HooksConfig
impl Unpin for HooksConfig
impl UnsafeUnpin for HooksConfig
impl UnwindSafe for HooksConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request