Skip to main content

Hooks

Overview

Hooks use a defined JSON schema in standalone files at .kiro/hooks/*.json. This replaces the previous IDE .kiro.hook format with a structured, validated schema shared with the CLI — the same hook file works on every surface.

json
{ "version": "v1", "hooks": [ { "name": "format-on-save", "trigger": "PostFileSave", "matcher": "\\.ts$", "action": { "type": "command", "command": "prettier --write {{filePath}}" } } ] }

Schema details

FieldRequiredDescription
versionYesSchema version — currently "v1"
hooks[].nameYesUnique identifier for the hook
hooks[].triggerYesEvent trigger name in PascalCase (see table below)
hooks[].matcherNoRegex pattern matched against the event subject
hooks[].action.typeYesAction type: command or agent
hooks[].action.commandCond.Shell command to run (when action.type: "command")
hooks[].action.promptCond.Agent prompt to inject (when action.type: "agent")

Available triggers

TriggerFires whenMatcher matchesCan block?
SessionStartSession begins—No
StopAgent execution completes—No
UserPromptSubmitYou send a messagePrompt textYes
PreTaskExecBefore a spec task starts—Yes
PostTaskExecAfter a spec task finishes—No
PreToolUseBefore a tool executesTool nameYes
PostToolUseAfter a tool executesTool nameNo
PostFileCreateA new file is created by the agentFile pathNo
PostFileSaveA file is saved/modified by the agentFile pathNo
PostFileDeleteA file is deleted by the agentFile pathNo

Blocking: a command action that exits with code 2 blocks the triggering event (PreToolUse, UserPromptSubmit, PreTaskExec). Use this for policy enforcement — for example, block writes to *.env files. Any other non-zero exit code is treated as an error, not a block.

Migrating from 0.x trigger names

Legacy .kiro.hook trigger names map directly onto the new PascalCase triggers:

Old (when.type)New (trigger)
agentSpawnSessionStart
agentStopStop
promptSubmitUserPromptSubmit
preToolUsePreToolUse
postToolUsePostToolUse
fileCreatedPostFileCreate
fileEditedPostFileSave
fileDeletedPostFileDelete
preTaskExecutionPreTaskExec
postTaskExecutionPostTaskExec
userTriggeredNo v1 equivalent; existing Hooks remain runnable as legacy Hooks

Your regex patterns transfer directly; the when/then structure becomes trigger/matcher/action. The IDE migrates hooks for you: open the Agent Hooks panel and click the upgrade badge on each legacy hook.

Existing userTriggered Hooks continue to appear with a legacy label and remain runnable from the Agent Hooks panel. You can't create a new Manual-trigger Hook in the v1 schema. For a new on-demand workflow, create a manually included Steering file in .kiro/steering/; it runs as a /<filename> slash command. See Steering.

Action types

  • command — runs a subprocess; receives JSON context on stdin. The {{filePath}} template variable is available for file-related triggers.
  • agent — injects a prompt into the agent's context at trigger time. Use this to add conditional steering (e.g., "A test file was saved — check coverage"). Unlike command, it can't block the trigger.

For the full reference (exit-code semantics, stdin payloads, global hooks in ~/.kiro/hooks/), see Hooks.

Page updated: August 21, 2026