All guides

Configure a Check Task That Runs After Kiro Saves a File

Use one PostFileSave hook to run your own check script after matching files are saved, then verify, adjust and disable it.

AINavWritten / Updated Sources checked
On this page

At a glance

Kiro Hooks run shell commands or send agent prompts automatically when certain events occur in a session. This guide sets up one hook for a made-up practice project that runs a check script after a file is saved. You write the JSON, trigger the hook once, check the result, and turn it off when you no longer need it. It is for readers who want Kiro to trigger a repetitive manual check.

Workflow

  1. Layer 1: A narrow trigger

    Confirm the trigger is PostFileSave and that matcher, a regex against the file path, limits the file type; without a matcher the hook always matches.

  2. Layer 2: A controlled action

    Confirm action.type is command, that it runs in the project root and receives session context as JSON on STDIN, and that timeout is set sensibly.

  3. Layer 3: Easy to withdraw

    Confirm the file sits in .kiro/hooks/ and is valid JSON, and know that setting enabled to false skips the hook while deleting the file removes it.

Each stage cites official sources.

Before you start

  • Use Kiro IDE 1.0 or CLI V3, which support the standalone .kiro/hooks/*.json format, installed and signed in with a practice project open. Upgrade older versions or follow the official migration documentation first.
  • A fast check script of your own with no secrets or personal data, such as the fictional ./scripts/quick-check.sh, and a practice .py file for it to check.

1. Choose how to create it

In the IDE, click the + button in the Agent Hooks section of the Kiro panel and select Ask Kiro to create a hook, then describe what you need in plain language, for example 'run my quick check script after a Python file is saved'. Kiro writes the configuration through that conversation. You can also create .kiro/hooks/check-on-save.json by hand in the project root. Both routes leave a JSON file in that folder.

2. Write or verify the configuration

The file needs version (currently "v1") and a hooks array. This example has one hook with name, trigger PostFileSave, matcher \\.py$, an action of type command pointing at your script, and a timeout of 30 seconds. The documented default timeout is 60 seconds and 0 disables it; keep a limit while you are practising.

3. Handle the script input

The command runs in the project root and receives JSON on STDIN with the saved file path and session context. Start with a script that only prints what it receives, look at the structure, then decide which fields to read. Do not guess field names; the official Hook Actions page documents the format.

4. Trigger it once and watch

Start a session; hooks activate automatically when a session starts. Ask the agent to modify and save a .py file, then check whether the script ran and whether its output appeared. The official example fires when the agent saves or edits a file, so test with agent changes.

5. Run a non-matching control

Ask the agent to change a file that does not end in .py, such as notes.md, and confirm the script did not run. If it did run, tighten the matcher and test again.

6. Adjust and stop

If the check is slow or noisy, narrow the matcher or lower the timeout. To pause the hook, set enabled to false instead of deleting it; delete the JSON file when you no longer need it. Repeat steps 4 and 5 after each change.

Original example

Fictional scenario: the practice project has app.py, notes.md and scripts/quick-check.sh. Create .kiro/hooks/check-on-save.json containing:

json
{
  "version": "v1",
  "hooks": [{
    "name": "Check on save",
    "description": "Run my quick check after a .py file is saved",
    "trigger": "PostFileSave",
    "matcher": "\\.py$",
    "action": { "type": "command", "command": "./scripts/quick-check.sh" },
    "timeout": 30,
    "enabled": true
  }]
}

Ask the agent to add one comment line to app.py and expect the script to run once; then ask it to edit notes.md and expect no run. The script contents and any output are yours to define and are not real Kiro output. To pause, change enabled to false and test again; it should no longer run.

Completion checks

  • The file is in .kiro/hooks/, is valid JSON, has version and hooks, and each hook has name, trigger and action.
  • Editing a .py file runs the script; editing a .md file does not.
  • The script finishes within 30 seconds; if it times out, you know whether to adjust timeout or the script.
  • After setting enabled to false, editing a .py file no longer triggers it.

Limits

  • Hooks are available in the IDE and CLI only, not Web or Mobile; the global ~/.kiro/hooks/ location applies to CLI V3 only, and this guide uses the workspace location.
  • This covers only PostFileSave with a command action, not PreToolUse gating, Stop confirmation prompts or agent prompt actions; the official Hook types page is the authoritative trigger list.
  • The command runs in your project root, so run only scripts you have read and keep secrets and personal data out of them; whether the script changes files depends on the script itself.

Verification scope

This guide is based on reading the official documentation. Login, installation, product API execution, file upload and generated output were not tested, and the example content is original and illustrative.

Article sources

Original editorial content; official descriptions and checking suggestions are distinguished.

  1. Kiro · Official sources
    View details