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
-
Decide exactly which document mirrors which folder. A hook needs one pair, not a vague instruction to keep everything current. For example,
docs/api.mdmirrorssrc/api/. -
Open the hooks section of the Kiro panel, or find the hook commands in the Command Palette.
-
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/. -
Choose the file-save trigger and set the pattern to the source folder alone,
src/api/**. Do not includedocs/**in the trigger, or the hook re-triggers itself. -
Ask for a proposal, not a commit. The wording above tells the agent to propose an edit. Review the diff like any other change.
-
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. -
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.
Related
- Hooks covers every trigger type and the creation flow.
- Run tests on save with a hook is the companion recipe.
- Advanced Tutorial shows both hooks inside a full workflow.
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.
Related chapters
- ConceptsHooksKiro hooks run an agent prompt or shell command when something happens. Trigger types, where hook files live, and how to scope them so they help.
- RecipesRun Tests on Save With a HookCreate a Kiro agent hook that runs the right tests when you save a source file, scope the trigger narrowly, and avoid noisy hook loops.
- Hands-onAdvanced TutorialA production-shaped workflow that combines specs, steering, hooks, MCP, custom agents, and skills, written for engineers who already know the basics.
- RecipesCreate Your First Steering FileCreate product.md, tech.md, and structure.md in .kiro/steering/, set inclusion modes in front matter, and check that the agent obeys them.