hook-authoring
Use when creating or editing .ai/hooks.toml hook definitions. Teaches the TOML format, valid events, matchers, and cross-tool translation.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Use when creating or editing .ai/hooks.toml hook definitions. Teaches the TOML format, valid events, matchers, and cross-tool translation.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | hook-authoring |
| description | Use when creating or editing .ai/hooks.toml hook definitions. Teaches the TOML format, valid events, matchers, and cross-tool translation. |
| version | 1.0.0 |
Hooks are defined in .ai/hooks.toml using TOML. Each hook is grouped under an [[EventName]] section with an optional matcher field, and contains one or more [[EventName.hooks]] entries.
[[PreToolUse]]
matcher = "Bash"
[[PreToolUse.hooks]]
type = "command"
command = "bash .ai/scripts/validate-bash.sh"
timeout = 10
| Event | Description |
|---|---|
PreToolUse | Fires before a tool is invoked. Use matcher to target specific tools. |
PostToolUse | Fires after a tool completes. Use matcher to target specific tools. |
Stop | Fires when the agent stops (completes a response). |
SubagentStop | Fires when a sub-agent stops. |
| Event | Description |
|---|---|
Notification | Fires when a notification is sent. |
| Event | Description |
|---|---|
PostToolUseFailure | Fires when a tool invocation fails. |
SessionStart | Fires when a new session begins. |
SessionEnd | Fires when a session ends. |
BeforeShellExecution | Fires before a shell command runs. |
AfterShellExecution | Fires after a shell command completes. |
BeforeReadFile | Fires before reading a file. |
AfterFileEdit | Fires after a file is edited. |
BeforeSubmitPrompt | Fires before a prompt is submitted. |
PreCompact | Fires before context compaction. |
AfterAgentResponse | Fires after the agent responds. |
AfterAgentThought | Fires after an agent thought step. |
SubagentStart | Fires when a sub-agent starts. |
BeforeMCPExecution | Fires before an MCP tool call. |
AfterMCPExecution | Fires after an MCP tool call completes. |
Note: Claude Code natively supports additional events (
SessionStart,SessionEnd,UserPromptSubmit,PreCompact) that aisync does not yet translate. When writing hooks for these events in.ai/hooks.toml, aisync will currently skip them during Claude Code translation. To use these events, configure them directly in.claude/settings.jsonor via a Claude Code plugin'shooks.json.
The matcher field filters which tools trigger the hook:
| Pattern | Matches |
|---|---|
Edit | Exact tool name match. |
Edit|Write | Multiple tools (pipe-separated). |
mcp__.* | Regex pattern — matches all MCP tools. |
Omit matcher to match all tools for that event.
command — Shell command hookRuns a bash command. Available for all events and all tools.
[[PostToolUse.hooks]]
type = "command"
command = "echo 'Tool finished'"
timeout = 30
prompt — LLM-driven hookSends a prompt to the LLM for evaluation. Claude Code only, and only for these events via aisync: PreToolUse, Stop, SubagentStop. Note that UserPromptSubmit prompt hooks work in native Claude Code hooks.json but not through aisync's translation layer.
[[PreToolUse]]
matcher = "Bash"
[[PreToolUse.hooks]]
type = "prompt"
command = "Review this bash command for safety. Reject if it modifies system files."
When aisync syncs hooks to different tools, it translates the canonical format:
PreToolUse becomes preToolUse)Edit (Claude Code) maps to Write (Cursor)Bash (Claude Code) maps to Shell (Cursor)Use aisync hooks list to see all hooks and their per-tool support status.
Use aisync hooks translate to preview the exact output each tool will receive after translation.
# Validate bash commands before execution
[[PreToolUse]]
matcher = "Bash"
[[PreToolUse.hooks]]
type = "command"
command = "bash .ai/scripts/validate-bash.sh"
timeout = 10
# Log all tool usage
[[PostToolUse]]
[[PostToolUse.hooks]]
type = "command"
command = "bash .ai/scripts/log-tool-use.sh"
timeout = 5
# Review agent output before stopping
[[Stop]]
[[Stop.hooks]]
type = "prompt"
command = "Review the agent's final response for completeness and accuracy."