Completely without external tools. The hooks are created via chat (natural language) and are agent hooks — platform-independent, no Python, no runtime, no installation needed.
This lab has two exercises. In the first you create a simple hook that greets you by name. In the second we get to the key point: why a hook only fires when the agent acts, not when you do something yourself.
Exercise 1: A hook that greets you
We build a small hook and see what Kiro makes of it. Insert your own name instead of the placeholder. Type in the chat (or via the Kiro panel → Agent Hooks → + → Ask Kiro to create a hook):
Create a hook that triggers on every prompt and instructs you
to always address me with "Hello [YOUR NAME]" in the response.
Replace [YOUR NAME] with your first name. Example: "Hello Sabine".
Inspect & test the hook
- Kiro generates the hook configuration (trigger + action) and creates it.
- In the Kiro panel (ghost icon) → Agent Hooks open and inspect the new hook:
- Trigger:
UserPromptSubmit(on every prompt) - Action: an agent prompt (an AI action)
- Optionally open the file under
.kiro/hooks/and look at the JSON structure.
- Trigger:
- Then ask any question → the response starts with your greeting, e.g. "Hello Sabine".
- To continue working, disable or delete the hook again (in the panel → Agent Hooks).
Note: trigger = when, action = what happens. Hooks can be created entirely in natural language — no hand-written JSON needed.
Exercise 2: CSV, a hook on save, and the proof
Now for the interesting part. We build a hook that reacts to saving a CSV file. Then we test it in two ways and see an important difference.
Step 1 – Create test data
Create a file data.csv:
name,department,hours
Anna,Engineering,38
Ben,Design,32
Carla,Engineering,40
David,Sales,25
Step 2 – Generate the CSV viewer via prompt
We have Kiro build a small page that displays a CSV in the browser:
Create a single HTML file (index.html) with vanilla JavaScript and CSS,
without external libraries. It should:
- have a file-select button to choose a CSV file
- read the CSV in the browser (FileReader) and show it as a table
- treat the first row as column headers
- show the number of data rows and the sum of the "hours" column at the bottom
Open index.html in the browser, select data.csv → the table and sum appear.
Step 3 – Create a hook that reacts to saving
Create an agent hook: whenever a CSV file is saved,
Kiro should read the changed file and give a short summary
(number of rows, column names and the sum of the "hours" column).
Inspect the generated hook in the panel: trigger PostFileSave, file pattern *.csv, agent action.
Step 4 – Change the file by hand
Now the first test. Open data.csv in the editor, change a number (e.g. Anna's hours from 38 to 40) and save with Ctrl+S. Check whether the hook runs.
Observation: the hook does NOT run.
Even though the CSV file was saved, nothing happens. No summary, no reaction. Many people expect the hook to fire here — but it doesn't. That is not a bug.
Step 5 – Why is that? Agent hooks explained
The reason is in the name: they are agent hooks. Such a hook only fires when Kiro itself (the agent) writes or saves the file. If you save the same file by hand in the editor, it does not count.
This is by design, for two reasons:
- Control over costs: If a hook reacted to any file change at all, it would run far too often. An example: you pull your colleagues' work from Git or CodeCommit. In one go, maybe hundreds of files change. The hook would start an AI action hundreds of times.
- No runaway at scale: In a data engineering context, where a single run can touch thousands of files, it would be even more drastic: thousands of hook executions, enormous consumption of context and credits, and in the worst case a chain of actions that keeps triggering itself.
Hence the clear rule: a hook only reacts to what the agent does. This keeps it predictable and controllable when and how often a hook runs.
Step 6 – The proof: the agent saves
Now we have Kiro change and save the same file. Ask the agent in the chat:
Add two more rows with made-up employees to data.csv
(name, department, hours) and save the file.
Observation: as soon as Kiro saves the file, the hook triggers and the summary appears automatically (number of rows, column names, sum of hours). The exact same save operation as in Step 4, but this time triggered by the agent — and only for that reason the hook fires.
This is the core message of the lab: it is not the save operation itself that triggers the hook, but who saves. Only the agent's actions count.
Discussion point: Hook vs. Steering
The greeting hook from Exercise 1 is great as a demo, but as a permanent solution it is actually not the smartest choice: it fires on every prompt (UserPromptSubmit) and starts an AI action each time — just to greet you by name. That unnecessarily costs context and credits and is overkill.
Steering is much better suited for this. Instead of a hook, you create a small steering rule, e.g.:
# Personal preferences
- The user's name is Sabine and she likes to be addressed by name.
Rule of thumb: Hooks are for actions on events (e.g. "on saved CSV → summarize"). Persistent behavior or preferences belong in steering (see Lab 5).