Skip to content
Learn Kiro.

Recipes · Chapter 34 of 63

Keep Docs in Sync With a Hook

Create a Kiro hook that checks your documentation against changed source files and proposes an update, without letting the hook rewrite its own trigger.

All levels 2 min read last reviewed 2026-09-04

◎ Learning objective

Create a hook that notices when source changes make documentation stale and proposes the edit for review.

Documentation goes stale because nothing notices when it does. A hook can notice: point it at your source folder, and Kiro compares the changed code against the documentation and proposes an edit.

When to use this

Use this when you keep hand-written documentation that mirrors code, such as an API reference, a configuration table, or a README command list. Skip it when your documentation is generated from the code already, because the generator is the better tool.

Steps

  1. Decide exactly which document mirrors which folder. A hook needs one pair, not a vague instruction to keep everything current. For example, docs/api.md mirrors src/api/.

  2. Open the hooks section of the Kiro panel, or find the hook commands in the Command Palette.

  3. Create a new hook. Kiro accepts a natural-language description, and the IDE also offers a guided form. Describe the pair explicitly:

    When a file under src/api/ is saved, compare the endpoint
    signatures against docs/api.md. If they disagree, propose an
    edit to docs/api.md only. Never edit files under src/.
  4. Choose the file-save trigger and set the pattern to the source folder alone, src/api/**. Do not include docs/** in the trigger, or the hook re-triggers itself.

  5. Ask for a proposal, not a commit. The wording above tells the agent to propose an edit. Review the diff like any other change.

  6. Save the hook. The configuration lands in .kiro/hooks/ in your workspace. Commit it so the team shares the rule. Put it in ~/.kiro/hooks/ instead if you want it in every project.

  7. Add a matching line to steering so the agent knows the pairing outside the hook too, for example “docs/api.md documents every endpoint in src/api/”. See Create your first steering file.

Check it worked

Change an endpoint signature in the source folder and save. The hook should fire and either report that the documentation still matches or propose a specific edit to the documentation file. Then save a file that the pattern does not cover and confirm nothing happens. A hook that fires on everything is worse than no hook.

Common problems

  • The hook rewrites source files. Your action was too broad. Name the target file and forbid edits elsewhere in the action text.
  • A loop starts. The trigger pattern covers the file the hook writes. Separate them.
  • The proposal is always wrong. The agent lacks context about the document’s structure. Add a short steering file that explains how the document is organised.
  • It fires on formatter saves. Auto-format on save can trigger the hook repeatedly. Narrow the pattern, or trigger on agent-driven changes only where your version supports it.
  • Nobody reviews the proposals. Treat a documentation diff like a code diff. An unreviewed automated edit is a future bug report.

Frequently asked questions

Can Kiro update documentation automatically?

Yes. Create an agent hook with a file-save trigger on your source folder and an action that asks the agent to compare the documentation against the changed code and propose an update. Review the proposed diff before you accept it.

Will the hook fire when the agent edits files, not just me?

In the IDE, yes. Hooks on agent-driven file changes arrived in IDE v1.0.116 (July 2026), so documentation stays in step with agent work as well as your own edits.

How do I stop a docs hook from looping?

Never let the hook write into a folder its trigger pattern matches. Trigger on src/ and write only to docs/. If both are inside one pattern, the hook re-triggers itself on every run.

☰ Chapter summary

  • A documentation hook watches source files and asks the agent to check the matching docs.
  • Trigger on file save for a narrow source folder, and write output only to the docs folder.
  • The IDE can also trigger hooks on agent-driven file changes, not only on your own saves.
  • Ask the hook to propose a diff for review rather than commit changes silently.
  • Project hooks live in .kiro/hooks/; global hooks live in ~/.kiro/hooks/.

All chapter summaries are collected on the revision page.

Was this chapter helpful?