Update Doc
Transform any markdown document into an AI-optimized version using research-backed best practices.
When to Use
Invoke when user says:
- "update doc"
- "optimize doc"
- "rewrite for claude"
- "AI optimize"
- "make this doc AI-friendly"
Workflow
| Phase |
Action |
Gate |
| 0 |
Find recent .md files, prompt user to select |
User select |
| 1 |
Read original, detect document type |
- |
| 1.5 |
Verify accuracy against codebase |
User choice |
| 2 |
Generate optimized version to .optimized.md |
- |
| 3 |
Compare original vs optimized for gaps |
- |
| 4 |
Second pass: fill any gaps found |
- |
| 5 |
Present summary with key changes |
User approval |
| 6 |
Replace original (with backup) or discard |
- |
Phase Details
Phase 0: File Selection
- Use Glob to find
.md files modified in last 30 days
- Exclude:
node_modules/, .git/, *.optimized.md, *.backup.md
- Use AskUserQuestion to present top 10 most recently modified files
- Store selected file path for subsequent phases
Phase 1: Analysis
- Read the selected document completely
- Detect document type (see references/document-types.md):
- CLAUDE.md → Apply progressive disclosure rules
- Skill file → Ensure frontmatter and XML tags
- Pattern file → Add [OK]/[FAIL] examples
- General markdown → Apply standard optimization
- Count lines, headings, code blocks, links
Phase 1.5: Accuracy Verification (Pattern Files)
For pattern files only (claude-patterns/ path), verify content against codebase:
Use AskUserQuestion: "This is a pattern file. Verify accuracy against codebase first?"
- Yes (Recommended): Proceed to verification
- Skip: Jump to Phase 2
If verifying, spawn Explore agent with Task tool:
- Extract key claims from pattern (function names, file paths, type names, workflows)
- Search codebase for actual implementations
- Compare pattern claims vs actual code
Report findings:
## Accuracy Check
| Claim | Status | Finding |
| --------------------- | ----------- | ------------------------------- |
| Uses `functionName()` | ✅ Verified | Found at `src/path/file.ts:123` |
| Type `TypeName` | ❌ Outdated | Type renamed to `NewTypeName` |
If inaccuracies found:
- Fix the original file first (correct function names, type names, file paths)
- Then proceed to Phase 2 with accurate content
Why this matters: Optimizing inaccurate documentation propagates errors. The email-patterns.md bug showed pattern files can drift from code over time.
Phase 2: Transformation
Apply rules from references/transformation-rules.md:
- Structure: Fix heading hierarchy, convert prose to tables/bullets
- Content: Consistent terminology, explicit references, imperative form
- Format: XML tags, fenced code blocks, target length
Write output to [original-name].optimized.md in same directory.
Phase 3: Comparison
Follow references/comparison-checklist.md:
- Extract all elements from original (headings, code, commands, links, facts)
- Verify each element present in optimized (may be reformatted)
- Create gap list of missing items
Phase 4: Second Pass
For each gap identified:
- Determine if omission was intentional (redundant, outdated)
- If needed, add missing content to optimized document
- Apply formatting rules to added content
Phase 5: Summary
Present to user:
## Optimization Summary
**Original**: [filename] ([X] lines)
**Optimized**: [filename].optimized.md ([Y] lines)
**Reduction**: [Z]%
### Key Changes
1. [Change 1]
2. [Change 2]
3. [Change 3]
### Content Verified
- Headings: [count] preserved
- Code examples: [count] intact
- Commands: [count] included
- Links: [count] working
Phase 6: Finalization
Based on user choice:
- Replace: Rename original to
.backup.md, rename optimized to original name, then delete the backup
- Keep both: Leave both files in place
- Discard: Delete
.optimized.md, keep original unchanged
Important: After successful replacement, delete the .backup.md file. The backup is only needed temporarily during the rename operation. Keeping backups clutters the repository.
Approval Gates
| Gate |
Phase |
Question |
| Selection |
0 |
"Which file do you want to optimize?" |
| Accuracy |
1.5 |
"Verify accuracy against codebase first?" |
| Replace |
5 |
"Replace original? / Keep both? / Discard changes?" |
Document Types
| Type |
Detection |
Key Transformations |
| CLAUDE.md |
Filename |
< 300 lines, progressive disclosure |
| Skill file |
.claude/skills/ path |
Frontmatter, XML tags, references/ |
| Pattern file |
claude-patterns/ path |
[OK]/[FAIL] examples, numbered rules |
| General |
.md extension |
Standard optimization |
For full details: references/document-types.md
Quick Reference
Transformation Rules Summary
Structure:
- Strict heading hierarchy (H1 → H2 → H3, avoid H4+)
- Blockquote summary after H1 title
- Tables over prose
- Bullets over paragraphs
- Single topic per section
- End-load actionable instructions (checklists, summaries at END)
Content:
- Consistent terminology (no synonyms)
- Eliminate vague pronouns (it, this, that, they → specific nouns)
- Imperative form ("Run X" not "You should run X")
- Positive framing ("Use X" not "Don't use Y")
Format:
- XML tags for semantic sections
- Fenced code blocks with language
- Target length by type
For full rules: references/transformation-rules.md
References
- references/transformation-rules.md - Complete transformation rules
- references/document-types.md - Type detection and handling
- references/comparison-checklist.md - Gap detection and validation
Version History
v1.3.0 (2026-01-18): Add accuracy verification phase
- New Phase 1.5: Verify pattern file accuracy against codebase before optimizing
- Spawn Explore agent to check function names, types, file paths
- Fix inaccuracies before optimization (prevents propagating errors)
- Added Task tool to allowed-tools for agent spawning
v1.2.0 (2025-01-18): Research-backed transformation updates
- Add blockquote summary rule after H1 (llms.txt standard)
- Add end-loading rule for actionable instructions (U-shaped attention)
- Enhance pronoun elimination guidance
- Update heading hierarchy to avoid H4+
v1.1.0 (2025-01-09): Delete backup after replacement
- Backup files are now deleted after successful replacement
- Prevents repository clutter from accumulating .backup.md files
v1.0.0 (2025-01-09): Initial release
- 6-phase workflow with file selection
- Support for CLAUDE.md, skill, pattern, and general markdown
- Comparison-based gap detection
- Backup on replace
1---2name: update-doc3description: Transform documentation into AI-optimized format for Claude Code. Use when user says "update doc", "optimize doc", "rewrite for claude", or "AI optimize". Shows recently modified .md files for selection, verifies accuracy against codebase, generates optimized version, compares for completeness, then replaces with approval.4---56# Update Doc78Transform any markdown document into an AI-optimized version using research-backed best practices.910<when_to_use>1112## When to Use1314Invoke when user says:1516- "update doc"17- "optimize doc"18- "rewrite for claude"19- "AI optimize"20- "make this doc AI-friendly"2122</when_to_use>2324<workflow>2526## Workflow2728| Phase | Action | Gate |29| ----- | --------------------------------------------- | ------------- |30| 0 | Find recent .md files, prompt user to select | User select |31| 1 | Read original, detect document type | - |32| 1.5 | Verify accuracy against codebase | User choice |33| 2 | Generate optimized version to `.optimized.md` | - |34| 3 | Compare original vs optimized for gaps | - |35| 4 | Second pass: fill any gaps found | - |36| 5 | Present summary with key changes | User approval |37| 6 | Replace original (with backup) or discard | - |3839</workflow>4041<phase_details>4243## Phase Details4445### Phase 0: File Selection46471. Use Glob to find `.md` files modified in last 30 days482. Exclude: `node_modules/`, `.git/`, `*.optimized.md`, `*.backup.md`493. Use AskUserQuestion to present top 10 most recently modified files504. Store selected file path for subsequent phases5152### Phase 1: Analysis53541. Read the selected document completely552. Detect document type (see [references/document-types.md](references/document-types.md)):56 - CLAUDE.md → Apply progressive disclosure rules57 - Skill file → Ensure frontmatter and XML tags58 - Pattern file → Add [OK]/[FAIL] examples59 - General markdown → Apply standard optimization603. Count lines, headings, code blocks, links6162### Phase 1.5: Accuracy Verification (Pattern Files)6364**For pattern files only** (`claude-patterns/` path), verify content against codebase:65661. Use AskUserQuestion: "This is a pattern file. Verify accuracy against codebase first?"67 - **Yes (Recommended)**: Proceed to verification68 - **Skip**: Jump to Phase 269702. If verifying, spawn Explore agent with Task tool:71 - Extract key claims from pattern (function names, file paths, type names, workflows)72 - Search codebase for actual implementations73 - Compare pattern claims vs actual code74753. Report findings:7677 ```markdown78 ## Accuracy Check7980 | Claim | Status | Finding |81 | --------------------- | ----------- | ------------------------------- |82 | Uses `functionName()` | ✅ Verified | Found at `src/path/file.ts:123` |83 | Type `TypeName` | ❌ Outdated | Type renamed to `NewTypeName` |84 ```85864. If inaccuracies found:87 - Fix the original file first (correct function names, type names, file paths)88 - Then proceed to Phase 2 with accurate content8990**Why this matters**: Optimizing inaccurate documentation propagates errors. The email-patterns.md bug showed pattern files can drift from code over time.9192### Phase 2: Transformation9394Apply rules from [references/transformation-rules.md](references/transformation-rules.md):95961. **Structure**: Fix heading hierarchy, convert prose to tables/bullets972. **Content**: Consistent terminology, explicit references, imperative form983. **Format**: XML tags, fenced code blocks, target length99100Write output to `[original-name].optimized.md` in same directory.101102### Phase 3: Comparison103104Follow [references/comparison-checklist.md](references/comparison-checklist.md):1051061. Extract all elements from original (headings, code, commands, links, facts)1072. Verify each element present in optimized (may be reformatted)1083. Create gap list of missing items109110### Phase 4: Second Pass111112For each gap identified:1131141. Determine if omission was intentional (redundant, outdated)1152. If needed, add missing content to optimized document1163. Apply formatting rules to added content117118### Phase 5: Summary119120Present to user:121122```markdown123## Optimization Summary124125**Original**: [filename] ([X] lines)126**Optimized**: [filename].optimized.md ([Y] lines)127**Reduction**: [Z]%128129### Key Changes1301311. [Change 1]1322. [Change 2]1333. [Change 3]134135### Content Verified136137- Headings: [count] preserved138- Code examples: [count] intact139- Commands: [count] included140- Links: [count] working141```142143### Phase 6: Finalization144145Based on user choice:146147- **Replace**: Rename original to `.backup.md`, rename optimized to original name, then **delete the backup**148- **Keep both**: Leave both files in place149- **Discard**: Delete `.optimized.md`, keep original unchanged150151**Important**: After successful replacement, delete the `.backup.md` file. The backup is only needed temporarily during the rename operation. Keeping backups clutters the repository.152153</phase_details>154155<approval_gates>156157## Approval Gates158159| Gate | Phase | Question |160| --------- | ----- | --------------------------------------------------- |161| Selection | 0 | "Which file do you want to optimize?" |162| Accuracy | 1.5 | "Verify accuracy against codebase first?" |163| Replace | 5 | "Replace original? / Keep both? / Discard changes?" |164165</approval_gates>166167<document_types>168169## Document Types170171| Type | Detection | Key Transformations |172| ------------ | ----------------------- | ------------------------------------ |173| CLAUDE.md | Filename | < 300 lines, progressive disclosure |174| Skill file | `.claude/skills/` path | Frontmatter, XML tags, references/ |175| Pattern file | `claude-patterns/` path | [OK]/[FAIL] examples, numbered rules |176| General | `.md` extension | Standard optimization |177178For full details: [references/document-types.md](references/document-types.md)179180</document_types>181182<quick_reference>183184## Quick Reference185186### Transformation Rules Summary187188**Structure**:189190- Strict heading hierarchy (H1 → H2 → H3, avoid H4+)191- Blockquote summary after H1 title192- Tables over prose193- Bullets over paragraphs194- Single topic per section195- End-load actionable instructions (checklists, summaries at END)196197**Content**:198199- Consistent terminology (no synonyms)200- Eliminate vague pronouns (it, this, that, they → specific nouns)201- Imperative form ("Run X" not "You should run X")202- Positive framing ("Use X" not "Don't use Y")203204**Format**:205206- XML tags for semantic sections207- Fenced code blocks with language208- Target length by type209210For full rules: [references/transformation-rules.md](references/transformation-rules.md)211212</quick_reference>213214<references>215216## References217218- [references/transformation-rules.md](references/transformation-rules.md) - Complete transformation rules219- [references/document-types.md](references/document-types.md) - Type detection and handling220- [references/comparison-checklist.md](references/comparison-checklist.md) - Gap detection and validation221222</references>223224<version_history>225226## Version History227228- **v1.3.0** (2026-01-18): Add accuracy verification phase229 - New Phase 1.5: Verify pattern file accuracy against codebase before optimizing230 - Spawn Explore agent to check function names, types, file paths231 - Fix inaccuracies before optimization (prevents propagating errors)232 - Added Task tool to allowed-tools for agent spawning233234- **v1.2.0** (2025-01-18): Research-backed transformation updates235 - Add blockquote summary rule after H1 (llms.txt standard)236 - Add end-loading rule for actionable instructions (U-shaped attention)237 - Enhance pronoun elimination guidance238 - Update heading hierarchy to avoid H4+239240- **v1.1.0** (2025-01-09): Delete backup after replacement241 - Backup files are now deleted after successful replacement242 - Prevents repository clutter from accumulating .backup.md files243244- **v1.0.0** (2025-01-09): Initial release245 - 6-phase workflow with file selection246 - Support for CLAUDE.md, skill, pattern, and general markdown247 - Comparison-based gap detection248 - Backup on replace249250</version_history>