Lifecycle hooks

Since v0.7.2, Zagens can run user-defined shell commands at agent lifecycle points — for audit, policy injection, env vars, or enterprise integration.

Where to configure

Surface Role
Settings → Hooks Edit global [hooks] in ~/.zagens/config.toml; save restarts the sidecar
Project tree {workspace}/.zagens/hooks.toml, .zagens/hooks.json, .cursor/hooks.json

Merge order: global config → project TOML → project JSON → Cursor hooks; project entries append after global.

Common events

Event Blocking? When
session_start / session_end No Session start / shutdown
message_submit Yes Before user message hits the LLM
tool_call_before / tool_call_after Before yes / after no Before / after tool execution
shell_env No Before each exec_shell; stdout merged as env vars
pre_compact / post_compact No Before / after context compaction
subagent_start / subagent_end Before yes / after no Before sub-agent spawn / on terminal state

Cursor-style aliases supported (e.g. beforeShelltool_call_before + exec_shell filter).

Blocking vs background

I/O protocol

Sync hooks read JSON context on stdin (session id, tool name, workspace, …) and return JSON actions on stdout (allow / deny / modify, …). See product repo docs/desktop/HOOKS.md for the full schema.

Example uses

Tips

Related: Scheduled tasks · Shell tools · CRAFT