| name | kiro-spec-cleanup |
| description | Organize and clean up specification documents after implementation completion. Removes implementation details while preserving essential context for future refactoring. |
| allowed-tools | Read, Write, Edit, Bash, Glob, Grep, AskUserQuestion |
| argument-hint | <feature-name> |
kiro-spec-cleanup Skill
Role
This skill fills the post-implementation gap in the spec lifecycle. After /kiro-validate-impl returns GO, spec documents accumulate implementation-specific content (testing procedures, deployment checklists, detailed code examples) that clutters future reading. This skill trims the HOW while preserving the WHY, so that the specs remain a useful reference when refactoring months later.
Beyond trimming after the fact, this skill installs the standard for what a spec should contain at all โ the Write / Don't-Write test below โ as the opening section of design.md. A spec is not a record of the implementation; it is the starting point for the next change to this feature. Content a reader could reconstruct from the code and test files does not belong in it: when the code changes, that content goes stale silently and drags down trust in the whole document. The cheapest cleanup is the content that was never written, so the test is meant to be applied both retroactively (this run) and prospectively (every future edit, because the test now lives in the document).
That framing governs the explanatory documents (design.md, research.md). It does not license trimming requirements.md's Acceptance Criteria: those are the contract the next change is measured against, and they survive cleanup intact โ see What the test does not apply to.
Lifecycle position:
discovery โ init โ requirements โ design โ tasks โ impl โ validate-impl โ **spec-cleanup**
Core Mission
- Success Criteria:
- Implementation details (testing procedures, deployment checklists) removed
- Design decisions, architectural constraints, and boundary metadata preserved
requirements.md's numbered EARS Acceptance Criteria are still itemized and still at their original numbers (never collapsed into a summary paragraph, never renumbered)
- Each requirement's closing note states the residual un-testable gap, not an enumeration of the tests that cover it
- Unimplemented features removed or documented
- Content a reader could reconstruct from the code and test files is gone (signatures, file inventories, mechanism walk-throughs, covered-test lists, traceability tables)
- The Write / Don't-Write test is present as the opening section of
design.md, so future edits self-limit
- Sections that have served their purpose are removed, not annotated (a stale section, even with a correction note, is read as current)
- Documents remain valuable for future refactoring work
- All prose content matches the language in spec.json
Organizing Principle
"Can we read essential context from these spec documents when refactoring this feature months later โ without anything in them having silently gone stale?"
The Write / Don't-Write test
Apply this one test to every keep/remove call, and leave it in the spec as design.md's opening section so it governs future edits too. The guiding question for each piece of content is: could a reader reconstruct this by reading the code and the test files? If yes, it does not belong in the spec.
| Write it | Don't write it |
|---|
| Facts that took real research to reach โ behavior that isn't obvious from a quick read of the code; hidden behavior of an external library | Function signatures, file-layout diagrams, "which file holds what" |
| Why an unusual design was chosen โ especially the shapes that were tried and rejected, and why | Straightforward explanations of a straightforward implementation |
| What automated tests cannot catch (the residual gaps) | Enumerations of which tests cover what โ read the spec/test files instead; the list rots |
| Manual verification procedure not derivable from code: how to build the reproduction environment, what to look at, the baseline/threshold values that mean pass/fail | Whether there is a diff, when it was implemented, and other point-in-time history |
When in doubt, leave it out. Code-readable content placed in a spec goes stale the moment the code changes, and one stale section costs the whole document its credibility.
What the test does not apply to: requirements.md's Acceptance Criteria
The Write / Don't-Write test asks "could a reader reconstruct this from the code?" โ a question that only makes sense for explanatory content. Never point it at requirements.md's Acceptance Criteria. A criterion is not a description of the implementation; it is the contract the implementation is measured against. "The tests already encode it" is the intended end state of a requirement, not evidence that the requirement is redundant.
The numbered EARS list is also a set of live identifiers that other files point at by number:
tasks.md cites them as _Requirements: 1.3, 3.1_
design.md traces decisions back to them
- implementation and test files cite them in comments and test names (e.g.
(1.6), (6.1))
So there are two distinct ways to break a spec here, and both have actually happened (2026-08-05, restored in commit 6bf45a133d):
- Collapsing
#### Acceptance Criteria into one **่ฆ็ด**: paragraph deletes the targets those citations point at. (ai-agentic-search / ai-chat-page-mention / ai-provider-model-picker)
- Renumbering โ including the renumbering that falls out of merging two specs or deleting a requirement โ silently re-points existing citations at the wrong requirement, which is worse than a dangling one. (suggest-path)
Rule: cleanup may add a closing note to a requirement and may fix genuinely broken wording inside a single criterion, but it must leave the list itemized and every number where it is. If numbering truly has to change, update every citing file in the same commit โ otherwise renumber nothing.
Two resolutions that override the coarser lists below
-
File Structure Plan โ keep the decision (which component owns what, and why the seams sit where they do); drop the literal file-by-file inventory, which after implementation is read more reliably from the tree. During active implementation the inventory drives task boundaries and stays; at cleanup it has done its job.
-
Verification procedures โ remove procedures that only restate what the test files and CI already encode (e.g. "run pnpm vitest run X", per-AC test lists); keep manual procedures a future reader could not reconstruct from the code (repro-environment setup, what to observe, baseline values).
-
Keep: the numbered EARS Acceptance Criteria (the contract, not explanation), and the "Why" โ design decisions and their rejected alternatives, architectural constraints, boundary commitments, limitations, trade-offs, residual un-testable gaps, non-reconstructable verification steps, Implementation Notes
-
Remove: "How" the code already carries โ signatures, file inventories, mechanism walk-throughs, requirement-traceability tables, technology-stack catalogs, covered-test enumerations, deployment steps, point-in-time history
Execution Steps
Step 1: Load Context
Discover all spec files:
- Glob
.kiro/specs/$ARGUMENTS/ to list every file
- Categorize:
- Core files (must preserve):
spec.json, brief.md, requirements.md, design.md, tasks.md, research.md
- Other files (evaluate case-by-case): validation reports, notes, prototypes, migration guides, etc.
Read all discovered files:
- Read all core files first
- Read other files to understand their content and value
Determine target language:
- Read
spec.json and extract the language field (e.g., "ja", "en")
- All spec document prose must be in this language
- Exempt: code inside fenced blocks, inline code spans, proper nouns, technical terms
Verify implementation status:
- Count
[x] vs [ ] tasks in tasks.md
- If less than 90% complete, warn user and ask to confirm cleanup
Step 2: Analyze Current State
Identify cleanup opportunities across all files:
-
Other files (non-core files like validation-report.md, notes.md, etc.):
- Read each file to understand content and purpose
- Identify valuable information worth preserving:
- Implementation discoveries and lessons learned
- Critical constraints or design decisions
- Historical context for future refactoring
- Determine salvage strategy:
- Migrate valuable content to research.md or design.md
- Keep file if it contains essential reference information
- Delete if content is redundant or no longer relevant
- Case-by-case evaluation required โ never assume files should be deleted
-
brief.md (v3 discovery output):
- Preserved in substance โ it records the original problem, approach, scope, and boundary candidates from discovery
- The only permitted edit is a one-line header marking it as a discovery-time record whose current truth lives in design/requirements where they differ; without it, a reader mistakes discovery-time guesses for current decisions
- No other cleanup needed unless content duplicates other files
-
research.md:
- Should contain discovery findings, design decisions, and implementation lessons
- Check if implementation revealed new constraints or patterns to document
- Identify content from other files that should be migrated here
-
requirements.md:
- The
#### Acceptance Criteria lists are not cleanup targets. They stay itemized, in EARS form, at their existing numbers. The only edit allowed inside a criterion is fixing wording that is actually wrong or unreadable, and only while its number and its testable meaning stay the same. Merging criteria, replacing the list with a paragraph, and renumbering are all out of scope for this skill
- For each requirement's closing note, prefer stating what automated tests do NOT cover (the residual gap a future reader cannot derive) over enumerating the tests that do (that list duplicates the test files and rots)
- Find unimplemented requirements (compare with tasks.md). Before proposing to remove one, grep the repo for its number (
_Requirements:, (N.M), Requirement N) โ if anything cites it, keep the requirement and record its unimplemented status in the closing note instead
- Detect duplicate or redundant content in the narrative parts (Overview, Objective, background prose) โ not in the criteria
Step 3: Interactive Confirmation
Present cleanup plan to user:
For each file and section identified in Step 2, present recommendations and ask for approval. Group related decisions to reduce interruptions.
Example questions for other files:
- "validation-report.md found. Contains {brief summary}. Options:"
- "A: Migrate valuable content to research.md, then delete"
- "B: Keep as historical reference"
- "C: Delete (content no longer needed)"
Example questions for core files:
- "requirements.md: Add residual-gap closing notes to Req 1โ5? (Acceptance Criteria themselves stay untouched) [Y/n]"
- "requirements.md: Req 4 is unimplemented and no file in the repo cites its number. Remove it, leaving Req 5+ at their current numbers? [Y/n]"
- "design.md: Delete 'Testing Strategy' section (lines X-Y)? [Y/n]"
- "design.md: Keep Boundary Commitments and the File Structure Plan's decomposition decision, while dropping its literal file inventory? [Y/n]"
Translation confirmation (if language mismatches found):
- Show summary: "Found content in language(s) other than
{target_language} in:"
- List each flagged file with line range and short excerpt
- Ask: "Translate mismatched content to
{target_language}? [Y/n]"
Batch similar decisions:
- Group related sections (e.g., all "delete implementation details" decisions)
- Allow user to approve categories rather than individual items
Step 4: Execute Cleanup
For each approved action:
-
Salvage and cleanup other files (if approved):
- For each non-core file:
- Extract valuable information
- Migrate content to appropriate core file:
- Technical discoveries โ research.md
- Design constraints โ design.md
- Requirement clarifications โ requirements.md
- Delete file after salvage (if approved)
- Document salvaged content with source reference
-
Update research.md (if new discoveries or salvaged content):
- Add "Post-Implementation Discoveries" section if needed
- Document critical technical constraints discovered during implementation
- Integrate salvaged content from other files
- Cross-reference requirements.md and design.md where relevant
-
Update requirements.md (if approved):
- Leave the numbered EARS Acceptance Criteria itemized and at their original numbers
- Add or adjust each requirement's closing note so it states the residual un-testable gap
- Remove an unimplemented requirement only when nothing in the repo cites its number, and do not renumber the survivors โ leave the gap in the sequence
- Preserve requirement objectives
-
Clean up design.md (if approved):
- Add the Write / Don't-Write test as the opening section if it is not already there
- Delete approved implementation-detail sections and any superseded sections (do not merely annotate them)
- Preserve: Architecture diagrams, Boundary Commitments, Out of Boundary, Allowed Dependencies, Revalidation Triggers, the File Structure Plan's boundary decision (not the file inventory), Component interfaces, Design decisions and their rejected alternatives, non-reconstructable verification procedures
- Integrate salvaged content from other files if relevant
-
Preserve tasks.md structure:
- Keep
## Implementation Notes intact
- Keep
_Boundary:_ and _Depends:_ annotations intact
- Keep task completion markers as historical record
-
Preserve brief.md:
- No modifications to the body โ discovery context is immutable
- The only permitted edit is adding a one-line header marking it as a discovery-time record superseded by design/requirements where they differ
Step 5: Generate Cleanup Summary
Provide summary report in the language specified in spec.json:
## Cleanup Summary for {feature-name}
### Files Modified
- file: action taken (lines changed)
### Information Salvaged
- Source โ destination mapping
### Information Preserved
- Architecture diagrams and boundary commitments
- Design decisions and rationale
- Implementation Notes and boundary annotations
- Brief (discovery context)
- Known limitations and trade-offs
### Next Steps
- Spec documents ready for future refactoring reference
Critical Constraints
- User approval required: Never delete or modify content without explicit confirmation
- Boundary metadata is sacred: Never remove Boundary Commitments, Out of Boundary, Allowed Dependencies, Revalidation Triggers, Boundary:, or Depends: annotations
- Implementation Notes are sacred: Never remove the
## Implementation Notes section from tasks.md
- Acceptance Criteria and requirement numbers are sacred: Never collapse
#### Acceptance Criteria into a summary paragraph, and never renumber requirements. tasks.md (_Requirements: N.M_), design.md, and code/test comments cite these numbers โ collapsing deletes what they point at, renumbering re-points them at the wrong requirement
- brief.md is near-immutable: Do not modify the body โ it records the original discovery context; the only permitted edit is a one-line header marking it as a discovery-time record superseded by design/requirements where they differ
- The Write / Don't-Write test is the standard for explanatory content: keep out anything a reader could reconstruct from the code and test files; when in doubt, leave it out. It applies to design.md and research.md โ not to requirements.md's Acceptance Criteria, which are the contract rather than a description of the code
- Remove, don't annotate, superseded sections: a section that has served its purpose is read as current even with a correction note โ drop it
- Language consistency: All prose content must match
spec.json.language; code blocks exempt
- Preserve history: Don't delete discovery rationale or design decisions (the WHY) โ this is distinct from point-in-time implementation history (diff/timing), which is removed
- Interactive workflow: Pause for user input rather than making assumptions
Safety & Fallback
Error Scenarios
Implementation Incomplete:
- Condition: Less than 90% of tasks marked
[x] in tasks.md
- Action: Warn: "Implementation appears incomplete (X/Y tasks done). Continue cleanup? [y/N]"
- Recommendation: Run
/kiro-validate-impl {feature} first
Spec Not Found:
- Message: "No spec found for
$ARGUMENTS. Available specs:"
- Action: List available spec directories in
.kiro/specs/
Missing Critical Files:
- Condition: requirements.md or design.md missing
- Action: Skip cleanup for missing files, proceed with available files
- Warning: "{file} missing โ cannot clean up"
Backup Recommendation
Before cleanup:
- Recommend user commit current state: "This will modify spec files. Consider committing current state for easy rollback."
- Undo path:
git checkout HEAD -- .kiro/specs/{feature}/
Related Commands
/kiro-validate-impl {feature} โ run before cleanup to confirm GO
/kiro-spec-status {feature} โ check implementation progress