Documents
Kiro Automation Hooks
Kiro Automation Hooks
Type
Document
Status
Published
Created
Oct 31, 2025
Updated
Oct 31, 2025
Updated by
Dosu Bot

The Kiro hooks system in this project provides a declarative, event-driven automation framework for maintaining code quality, formatting, documentation accuracy, and CI reliability. Hooks are configured as JSON files in .kiro/hooks, each specifying its name, activation status, purpose, trigger conditions, file patterns, and the action or prompt to execute when triggered. This modular approach ensures that only relevant files and events activate automation, minimizing unnecessary changes and maximizing safety and maintainability.

Key Hooks Overview#

Rust Code Analyzer#

The rust-code-analyzer hook monitors Rust source files (*.rs) and Cargo.toml for user-triggered changes. When activated, it analyzes only the files changed in the current branch, detected via git --no-pager diff --name-only origin/main. The hook applies safe, mechanical, non-breaking improvements across eight categories: code smells, design patterns, best practices, readability, maintainability, performance, type safety, and error handling. All changes are validated by running just lint && just test to ensure no breakage. The hook produces a detailed report of applied changes and deferred items, preserving public APIs and project conventions. See configuration

Code Quality Check#

The code-quality-check hook runs just check when a code file is saved (triggered by fileEdited on *.rs, Cargo.toml, Cargo.lock, and justfile). This validates formatting, linting, and basic compilation. If the first run makes formatting changes, the hook runs the check again to ensure all issues are resolved. Results and any issues needing attention are reported. See configuration

Markdown Format Fix#

The markdown-format-fix hook activates when a markdown file (*.md) is created. It runs mdformat across all markdown files in the repository, focusing on identifying and fixing formatting issues in embedded code blocks. The hook instructs agents to make only safe, targeted corrections, avoiding risky blanket changes or disabling formatters. This ensures code blocks remain valid and documentation formatting is consistent. See configuration

Documentation Synchronization#

The docs-sync-hook monitors a broad set of files for user-triggered changes, including Rust source files, configuration files (Cargo.toml, Cargo.lock, justfile, *.toml, *.yaml, *.yml), and documentation files (README.md, docs/src/**/*.md, spec/*.md, .kiro/steering/**/*.md). When triggered, it prompts an agent to review the codebase and update both the README.md and the mdbook user guide in /docs/src/ to reflect new features, API changes, usage patterns, and architecture changes. This ensures documentation remains accurate and up-to-date with the current project state. See configuration

CI Auto-Fix#

The ci-auto-fix hook automatically runs CI checks when source files change (user-triggered on *.rs, Cargo.toml, Cargo.lock, justfile, deny.toml, rust-toolchain.toml). It starts by running just ci-check to identify failures, then applies minimal, targeted fixes for formatting, linting, compilation errors, test failures, security audits, and license compliance. After each fix, it verifies success by rerunning the CI check, repeating as needed until all checks pass. The hook provides a summary of what was fixed, ensuring CI reliability and compliance. See configuration

Trigger Conditions and File Change Detection#

Each hook defines its trigger conditions using a combination of event types (userTriggered, fileEdited, fileCreated) and file patterns (e.g., **/*.rs, **/*.md). For example, the Rust Code Analyzer uses userTriggered events and detects changed files via git diff against the main branch, ensuring only relevant files are analyzed and modified. Other hooks respond to file save or creation events, scoped to specific file types.

Contribution to Code Quality and Documentation Maintenance#

The Kiro hooks system enforces code quality by automating linting, formatting, and safe code improvements, ensuring that only validated, non-breaking changes are applied. Documentation hooks keep user guides and READMEs synchronized with the codebase, reducing drift and improving onboarding. CI hooks maintain continuous integration reliability by automatically fixing and verifying issues as code evolves. This tightly integrated automation framework supports a zero-warnings policy, prioritizes safety, and streamlines developer workflows, resulting in a maintainable, high-quality codebase and accurate documentation.