Agent hooks support various trigger types, each designed for specific automation scenarios. Understanding these types helps you choose the right approach for your workflow needs.
This page describes standalone Hook definitions stored in .kiro/hooks/*.json. Inline profile Hooks have separate current and legacy forms; see the agent configuration reference.
File and task triggers are available in the IDE and CLI V3. Kiro Web sessions run the Prompt Submit, Agent Stop, Session Start, Pre Tool Use, and Post Tool Use triggers. The table below shows what's supported where.
| Trigger | IDE | CLI | Web | Mobile |
|---|---|---|---|---|
| Prompt Submit | ✓ | ✓ | ✓ | — |
| Agent Stop | ✓ | ✓ | ✓ | — |
| Session Start | ✓ | V3 | ✓ | — |
| Agent Spawn | — | 2.x / V3 alias | — | — |
| Session End | — | V3 | — | — |
| Pre Compaction | ✓ | V3 (3.1.0+) | — | — |
| Post Compaction | ✓ | V3 (3.1.0+) | — | — |
| Pre Tool Use | ✓ | ✓ | ✓ | — |
| Permission Request | ✓ | V3 (3.4.0+) | — | — |
| Post Tool Use | ✓ | ✓ | ✓ | — |
| File Create | ✓ | V3 | — | — |
| File Save | ✓ | V3 | — | — |
| File Delete | ✓ | V3 | — | — |
| Pre Task Execution | ✓ | V3 | — | — |
| Post Task Execution | ✓ | V3 | — | — |
| Manual | — | Listed in V3 | Can be created | — |
| Legacy Manual Hook | Legacy only | — | — | — |
Triggers when the user submits a prompt.
When using the shell command action, the user prompt can be accessed via the USER_PROMPT environment variable.
Use Cases:
- Provide additional context to the agent relevant to the prompt
- Block certain prompts based on their content (IDE only; CLI Prompt Submit Hooks cannot block)
- Log all user prompts to a central location
Triggers when the agent has completed its turn and finished responding to the user.
This is useful for running post-processing tasks like code compilation, testing, formatting, or cleanup after the agent's response.
Use Cases:
- Compile code and report any failures to the agent
- Format or review any agent-generated code
- Review changes made by agent and provide additional instructions
Triggers when a new chat session starts in the IDE or CLI V3.
Use Cases:
- Inject workspace-specific instructions into the agent's context
- Run environment checks (verify dependencies, validate credentials)
- Load project-specific configuration at session start
CLI 2.x used agentSpawn when the agent was first activated. CLI V3 uses SessionStart as the canonical trigger but accepts AgentSpawn and agentSpawn for compatibility. The event provides no tool context.
{ "hook_event_name": "agentSpawn", "cwd": "/current/working/directory", "session_id": "abc123-def456-789" }
Exit Code Behavior:
- 0: Hook succeeded, STDOUT is added to agent's context
- Other: Show STDERR warning to user
Use Cases:
- Set up environment context when a session starts
- Load project-specific configuration
- Initialize logging or auditing systems
The SessionEnd trigger fires when a CLI V3 session is torn down.
Triggers before Kiro compacts a conversation. In Kiro IDE, compaction is automatic, so the Hook runs when the session approaches the model's context limit; see Compaction. This trigger takes no matcher.
In Kiro IDE 1.4.121 or later, choose Pre Compaction from the Compaction Hooks group in the Hook editor's trigger list.
In Kiro CLI 3.1.0 or later, the PreCompact trigger fires before a CLI V3 session compacts its conversation. Compaction runs when you run /compact, when automatic summarization starts, when Kiro recovers from a context overflow, and when Kiro hands the session to another model.
Exit Code Behavior:
- 0: Compaction continues. In the IDE, Kiro gives the command's standard output to the summarizer as guidance. In CLI V3, STDOUT is added to the agent's context, up to 3,000 characters.
- 2: Cancel the compaction. In the IDE, Kiro reports STDERR as the reason, and the turn continues without compacting unless the context is nearly full. In CLI V3, the conversation stays as it is.
Use Cases:
- Save a snapshot of current work before older history is summarized
- Refuse compaction while a task you track outside Kiro is still open
Triggers after Kiro has compacted a conversation and the summary has replaced the older history. The Hook's output is added to the conversation, so the agent keeps details the summary left out. This trigger takes no matcher.
In Kiro IDE 1.4.121 or later, choose Post Compaction from the Compaction Hooks group in the Hook editor's trigger list.
In Kiro CLI 3.1.0 or later, the PostCompact trigger fires after a CLI V3 session compacts its conversation. The event JSON on STDIN includes summary, up to 3,000 characters of the summary text, and summary_path, the file containing the full summary. The Hook cannot undo the compaction or change the summary.
Use Cases:
- Restore task-specific guidance after compaction
- Archive each summary for review
- Record when a long session was compacted and what the summary kept
Triggers when the agent is about to invoke a tool. Can validate and block tool usage.
In the Tool name pattern field, provide an exact tool ID, a built-in category, a source selector, or a regular expression. You can specify multiple entries. The following built-in categories are supported:
- read - all built-in file read tools
- write - all built-in file write tools
- shell - all built-in shell command-related tools
- web - all built-in web tools
- spec - all built-in spec tools
You can also use source selectors:
- @mcp - all MCP tools
- @powers - all Powers tools
- @builtin - all built-in tools
@<server>- all tools from one MCP server, for example@postgres@<server>/<tool>- one tool from one MCP server, for example@postgres/query
The editor checks each entry as a regular expression matched against tool IDs. A plain name such as read can therefore match any tool ID containing that text. Leave the field blank to match every tool.
Hook JSON files also accept wildcard patterns. Use * to match any number of characters and ? to match a single character. Edit the Hook JSON file directly to use these patterns because the IDE editor rejects them as invalid regular expressions.
You can ask Kiro for the names of the available tools.
A Run Command Hook can return hookSpecificOutput.updatedInput to replace the tool's complete input object. Copy every argument, change the values you need, and return the complete object. Kiro validates the replacement and keeps the normal permission checks. If Kiro asks you to approve the tool call, it shows the final arguments.
Use Cases:
- Block certain tool invocations
- Validate tool inputs before execution
- Rewrite a tool call's inputs before it runs (Kiro IDE 1.4.236 or later, or Kiro CLI 3.4.0 or later)
- Provide additional instructions to the agent before it invokes a tool
In Kiro IDE 1.4.236 or later and Kiro CLI 3.4.0 or later, the PermissionRequest trigger runs after Kiro evaluates its permission policy and immediately before a tool call would prompt you. A script can answer routine prompts in a session nobody is watching. The trigger does not run when policy already allows or denies the call, or when a Pre Tool Use Hook already allowed it. Kiro CLI 2.x has no equivalent. The camelCase alias permissionRequest is also accepted.
In the Hook editor, select Permission Request under Tool Hooks, then choose Run Command.
Only command actions run on this trigger. The matcher field works as it does for Pre Tool Use.
Hook Event:
{ "hook_event_name": "PermissionRequest", "cwd": "/current/working/directory", "session_id": "abc123-def456-789", "tool_name": "read_file", "tool_input": { "path": "/home/user/notes/todo.md" }, "permission": { "capability": "fs_read", "paths": ["/home/user/notes/todo.md"] } }
tool_input is the effective input, after any Pre Tool Use rewrite. The permission object carries whichever of capability, resource, command, and paths apply to the call.
Return the answer as JSON on STDOUT, in one of two shapes:
{"hookSpecificOutput": {"decision": {"behavior": "allow"}}}
{"hookSpecificOutput": {"decision": {"behavior": "deny", "message": "Reads outside the workspace need a person."}}}
Exit Code Behavior:
- 0 with an
allowdecision: The tool call runs without a prompt. - 0 with a
denydecision: The tool call is blocked andmessageis returned to the agent. - 2: Deny the tool call.
- 0 without a valid decision, or Other: Kiro shows the prompt as usual.
decision.behavior accepts only allow and deny. Any other hookSpecificOutput, including the Pre Tool Use fields permissionDecision and permissionDecisionReason, is not a decision and keeps the prompt. When several Hooks run, deny or exit code 2 from any Hook wins over allow.
To confirm the Hook answers, save a PermissionRequest Hook with the matcher ^read_file$ whose command prints the allow shape, then ask Kiro in a V3 session with no read_file allow rule to read a file outside the workspace. The read runs without a prompt and the Hook card shows the decision.
Use Cases:
- Approve routine prompts from a script in unattended sessions
- Deny a call that fails a team check, with a message the agent can act on
- Log every prompt a session would have shown
A PermissionRequest Hook can allow or deny, from a script, the ordinary prompt a tool call would otherwise show, so the call proceeds in a session nobody is watching. Each answer applies to that one tool call only. Kiro does not save it as a rule.
The Hook cannot override a policy deny, change the tool's input, or answer a protected-path, organization, or administration prompt, or any other prompt that requires a person. Those prompts still wait for you.
To stop a Hook from answering, disable or remove its definition. To limit which calls it answers, narrow its matcher. Policy allow, ask, and deny rules are described under Permissions.
Triggers after the agent has invoked a tool, with access to tool results.
For details on the Tool name field, refer to the Pre Tool Use section above.
Use Cases:
- Log tool invocations for auditing purposes
- Format or review any updated files after a "write" tool call
- Provide additional instructions to the agent on top of the tool response
Triggers when the agent creates new files matching specific patterns in your workspace.
Use Cases:
- Generate boilerplate code for new components
- Add license headers to new files
- Set up test files when creating implementation files
Triggers when the agent saves or modifies files matching specific patterns.
Use Cases:
- Run linting and formatting
- Update related files
- Generate documentation
- Run tests for changed files
Triggers when the agent deletes files matching specific patterns.
Use Cases:
- Clean up related files
- Update import references in other files
- Maintain project integrity
Triggers before a spec task begins execution.
Use Cases:
- Run setup scripts or environment preparation before task execution
- Validate prerequisites are met before a task starts
- Log task start events for tracking
Triggers after a spec task completes execution.
Use Cases:
- Run tests after a task completes to verify correctness
- Run linting or formatting on changed files
- Generate documentation for completed work
- Notify external systems of task completion
CLI V3 recognizes and lists Manual Hook definitions, but /hooks doesn't provide an action to invoke them.
In Kiro Web, you can choose Manual as the trigger when you create a Hook under Agent Config > Hooks.
Manual Hooks created in IDE 0.x continue to appear in the Agent Hooks panel with a legacy label. Enabled legacy manual Hooks remain runnable using the play button next to the Hook name or Start Hook in the Hook view.
IDE 0.x userTriggered Hooks don't have a v1 IDE trigger equivalent, and you can't create a new Manual-trigger Hook in the IDE. For a new IDE on-demand workflow, create a manually included Steering file; it runs as a /<filename> slash command.
For MCP tools, V3 Hook events use the sanitized internal tool ID mcp_<server>_<tool>, not the @server/tool display name:
{ "hook_event_name": "PreToolUse", "cwd": "/current/working/directory", "session_id": "abc123-def456-789", "tool_name": "mcp_postgres_query", "tool_input": { "sql": "SELECT * FROM orders LIMIT 10;" } }
This applies to Pre Tool Use, Permission Request, and Post Tool Use Hooks when targeting MCP server tools. In the Hook's matcher, use either the @<server> or @<server>/<tool> selector or a regex against the internal ID.
Hook types