Skip to content

Hooks

Hooks let you run shell commands or inject prompts at specific points in the AI tool lifecycle. They live in .agentsmesh/hooks.yaml.

File format

PreToolUse:
- matcher: "Edit|Write"
type: command
command: "eslint --fix $FILE"
timeout: 30
PostToolUse:
- matcher: "Bash"
type: prompt
prompt: "Review the command output for security concerns before proceeding."
Notification:
- matcher: "*"
type: command
command: "./scripts/log-notification.sh"
UserPromptSubmit:
- matcher: "*"
type: command
command: "./scripts/prompt-guard.sh"

Hook event types

EventWhen it fires
PreToolUseBefore a tool call executes.
PostToolUseAfter a tool call completes.
NotificationWhen the AI sends a notification.
UserPromptSubmitWhen the user submits a prompt.
SubagentStartWhen a subagent starts.
SubagentStopWhen a subagent stops.

Hook entry fields

FieldTypeRequiredDescription
matcherstringYesRegex pattern for which tool or event triggers the hook. Use * to match all.
typestringYescommand — run a shell command. prompt — inject a prompt into the conversation.
commandstringIf type: commandShell command to execute.
promptstringIf type: promptPrompt text to inject.
timeoutnumberNoTimeout in seconds. Default varies by tool.

Variable substitution

For PreToolUse and PostToolUse hooks, the following variables are available in command:

VariableDescription
$FILEThe file path being edited (for Edit/Write tools).
$TOOLThe tool name being called.

Common hook patterns

Auto-lint on file save

PreToolUse:
- matcher: "Edit|Write"
type: command
command: "npx eslint --fix $FILE"
timeout: 30

Security review on Bash execution

PostToolUse:
- matcher: "Bash"
type: prompt
prompt: "Check the output of the previous command for security issues, unexpected errors, or sensitive data before continuing."

Prompt injection guard

UserPromptSubmit:
- matcher: "*"
type: command
command: "./scripts/check-prompt-injection.sh"
timeout: 5

Log all notifications

Notification:
- matcher: "*"
type: command
command: "echo \"$(date): $NOTIFICATION\" >> .agentsmesh/notifications.log"

Tool-specific behavior

ToolSupportNotes
Claude CodeNativeFull hook support.
CursorNativeFull hook support.
CopilotPartialLimited hook types supported.
Gemini CLIPartialLimited hook types supported.
ClineNot supported.
Codex CLINot supported.
WindsurfNativeFull hook support.
ContinueNot supported.
JunieNot supported.

Agent-level hooks

Hooks can also be defined per-agent in agents/*.md frontmatter:

---
name: safe-editor
description: Editor agent with pre-commit validation
hooks:
PreToolUse:
- matcher: "Edit|Write"
type: command
command: "npx tsc --noEmit"
timeout: 60
---

Agent-level hooks apply only when that agent is active and override project-level hooks for matching events.