VOOZH about

URL: https://kiro.dev/docs/hooks/

⇱ Hooks - IDE - Docs - Kiro


Hooks


Agent hooks are automated triggers that execute agent prompts or shell commands when specific events occur in your IDE. Rather than manually asking for routine tasks, hooks handle them automatically.

What are agent hooks?

Agent hooks set up automated responses to events such as:

  • Saving, creating, or deleting files
  • User prompt submission and agent turn completion
  • Before or after tool invocations
  • Before or after spec task execution

By setting up hooks for common tasks, you can:

  • Maintain consistent code quality
  • Prevent security vulnerabilities
  • Reduce manual overhead
  • Standardize team processes

How agent hooks work

The agent hook system follows a two-step process:

  1. Event Detection: The system monitors for specific events in your IDE
  2. Automated Action: When an event occurs, an action (either an agent prompt or a shell command) is executed

Setting up agent hooks

You can create hooks in three ways: describe what you want in natural language, manually fill out a form, or write a JSON file directly.

JSON file format

Hooks are JSON files stored in .kiro/hooks/ (workspace-level) or ~/.kiro/hooks/ (user-level):

json
{ "version": "v1", "hooks": [ { "name": "lint-on-save", "trigger": "PostFileSave", "matcher": "\\.ts$", "action": { "type": "command", "command": "npm run lint" }, "timeout": 30, "enabled": true } ] }
FieldTypeRequiredDefaultDescription
namestringYesIdentifier shown in telemetry
descriptionstringNoDocumentation only
triggerstringYesWhen the hook fires
matcherregex stringNoalways-matchFilters by tool name or file path
actionobjectYes{ type: "command", command: "..." } or { type: "agent", prompt: "..." }
timeoutinteger (seconds)No600 disables timeout. Ignored for agent actions
enabledbooleanNotrueSet false to skip without deleting

Creating a hook from the UI

  1. Navigate to the Agent Hooks section in the Kiro panel
  2. Click the + button to create a new hook
  3. Choose how you want to create the hook:
    • Manually create a hook — configure a hook by hand in a form
    • Ask Kiro to create a hook — describe a hook using natural language and have Kiro create one

Ask Kiro to create a hook

  1. Select Ask Kiro to create a hook
  2. Describe the hook workflow using natural language
  3. Press Enter or click Submit to proceed
  4. Review the generated configuration, adjust if needed, and click Save Hook

Manually create a hook

  1. Select Manually create a hook to open the hook form
  2. Fill in the form fields:
    • Title — a short name for the hook
    • Description — what the hook does
    • Event — the trigger type (e.g., File Save, Post Tool Use, Pre Task Execution)
    • Tool name — for Pre/Post Tool Use hooks, specify which tools to match
    • File pattern — for file event hooks, specify which files to match
    • Action — choose Ask Kiro (agent prompt) or Run Command (shell command)
    • Instructions or Command — the prompt or shell command to execute
  3. Click Create Hook when done, or Clear to reset the form

You can also open the Hook UI from the Command Palette with Cmd + Shift + P (Mac) or Ctrl + Shift + P (Windows/Linux) and typing Kiro: Open Kiro Hook UI.

Trigger reference

TriggerFires whenMatcher matchesCan block?
SessionStartSession beginsNo
StopAgent completes its turnNo
PreToolUseBefore tool executesTool name (regex)Yes
PostToolUseAfter tool executesTool name (regex)No
PreTaskExecBefore a spec task startsYes
PostTaskExecAfter a spec task finishesNo
UserPromptSubmitUser submits a promptYes
PostFileCreateAfter a file is created by the agentFile path (regex)No
PostFileSaveAfter a file is saved by the agentFile path (regex)No
PostFileDeleteAfter a file is deleted by the agentFile path (regex)No

Exit code behavior

For command actions:

Exit codeBehavior
0Success. STDOUT added to context (SessionStart, UserPromptSubmit) or ignored (others)
2Block execution (PreToolUse, UserPromptSubmit, PreTaskExec only). STDERR returned to the agent
OtherWarning shown to user. Tool execution proceeds

Next steps

Now that you have created a hook file, you can further learn about hooks here:

  • Hook Types - Learn about different trigger types and their use cases
  • Hook Actions - Learn about different hook actions and their use cases
  • Management - Learn how to organize, edit, and maintain your hooks
  • Best Practices - Follow patterns for effective hook design
  • Examples - See examples and templates you can use
Page updated: June 25, 2026
Create powers
Hook triggers