| name | librarian |
| description | Semantic documentation architect. Analyzes PROSE CONTENT to organize by concept affinity, eliminate contradictions in explanations, and consolidate scattered ideas. |
Librarian - Documentation Prose Architect
Analyze the prose content of documentation - what it says, how it explains concepts, where ideas are scattered or
duplicated - to reorganize by semantic meaning, not just file structure.
Core Philosophy
The librarian examines PROSE, not just code.
The librarian reads documentation like a human reader would, understanding:
- What each file explains - The concepts, workflows, and ideas described in prose
- How explanations relate - Where the same idea is explained differently in multiple places
- Where prose contradicts - Conflicting explanations, not just conflicting numbers
- What's scattered vs. cohesive - Ideas that belong together split across files
- What's mixed vs. focused - Unrelated explanations crammed into one file
This is NOT about:
- Fixing broken links (that's a side effect)
- Checking operator consistency (that's mechanical)
- Enforcing line limits (that's a constraint)
- Validating code blocks (that's syntax)
This IS about:
- Understanding what each document is trying to explain
- Finding where explanations are incomplete, scattered, or contradictory
- Reorganizing prose so concepts flow logically
- Consolidating duplicate explanations into single authoritative sources
What "Examining Prose" Means
When you read a documentation file, ask:
PROSE ANALYSIS QUESTIONS:
โโโ UNDERSTANDING:
โ โโโ What concept is this file trying to explain?
โ โโโ Who is the intended reader?
โ โโโ What should the reader know after reading this?
โ โโโ What does this file ASSUME the reader already knows?
โ
โโโ QUALITY:
โ โโโ Is the explanation complete?
โ โโโ Is the explanation clear?
โ โโโ Are there gaps in the logic?
โ โโโ Would a reader be confused by anything?
โ
โโโ RELATIONSHIPS:
โ โโโ What other concepts does this explanation reference?
โ โโโ Are those concepts explained here or elsewhere?
โ โโโ If elsewhere, is the reference clear?
โ โโโ Does this explanation contradict any other?
โ
โโโ ORGANIZATION:
โโโ Does this explanation belong in this file?
โโโ Is this file trying to explain too many things?
โโโ Is this explanation scattered across multiple files?
โโโ Would reorganizing improve understanding?
Prose Issues vs Mechanical Issues
| Prose Issues (Focus Here) | Mechanical Issues (Secondary) |
|---|
| Same concept explained 3 different ways | Broken markdown link |
| Conflicting instructions for same scenario | Missing file reference |
| Workflow explanation split across 5 files | Line count over limit |
| Tutorial mixed with reference material | Inconsistent heading levels |
| Incomplete explanation assumes too much | Duplicate signal format |
| Confusing explanation with unclear logic | Wrong anchor tag |
Always prioritize prose issues. Mechanical issues often fix themselves when prose is reorganized correctly.
Parameters
| Parameter | Required | Default | Description |
|---|
path | No | .claude/docs | Directory to analyze |
line_limit | No | 500 | Maximum lines per file (constraint) |
mode | No | refactor | refactor, audit, or consistency |
Invocation
/librarian # Full refactor of .claude/docs
/librarian mode=audit # Report only, no changes
/librarian mode=consistency # Check for contradictions only
/librarian path=docs line_limit=400 # Custom path and stricter limit
Phase 1: Semantic Analysis (READ THE PROSE)
1.1 Build Concept Map
Read ALL documentation files as prose and extract:
CONCEPT EXTRACTION:
โโโ For each file, READ IT and identify:
โ โโโ Primary concept (what is this file fundamentally ABOUT?)
โ โ โ Not "what's in the filename" but "what does it explain"
โ โ
โ โโโ Key explanations (what does it teach the reader?)
โ โ โ Summarize each major section's purpose
โ โ
โ โโโ Audience assumptions (what does it assume you know?)
โ โ โ What would confuse a new reader?
โ โ
โ โโโ Terminology defined (what terms does it establish?)
โ โ โ Look for definitions, not just usage
โ โ
โ โโโ Dependencies (what must you read first?)
โ โ What concepts are referenced but not explained?
โ
โโโ Build concept index:
โ โโโ concept โ [files that EXPLAIN it in prose]
โ โโโ concept โ [files that MENTION it without explaining]
โ โโโ concept โ [files that ASSUME reader knows it]
โ
โโโ Identify concept clusters:
โโโ Concepts that form a coherent topic (should be together)
โโโ Concepts that build on each other (should be ordered)
โโโ Concepts that conflict (should be reconciled)
1.2 Map Explanation Patterns
Understand HOW concepts are explained:
EXPLANATION PATTERN ANALYSIS:
โโโ Explanation styles found:
โ โโโ Tutorial (step-by-step, "do this then this")
โ โโโ Reference (lookup, "X means Y")
โ โโโ Conceptual (understanding, "why X matters")
โ โโโ Example-driven (showing, "here's X in action")
โ
โโโ Mixed styles in same file (potential split):
โ โโโ File tries to be both tutorial AND reference
โ โโโ File mixes conceptual overview with implementation detail
โ โโโ File combines quick-start with exhaustive reference
โ
โโโ Incomplete explanations:
โ โโโ Concept mentioned but never fully explained
โ โโโ Workflow described but steps are vague
โ โโโ Term used but never defined
โ โโโ "See X" but X doesn't exist
โ
โโโ Redundant explanations:
โโโ Same concept explained in multiple files
โโโ Same workflow described with different wording
โโโ Same template shown in multiple places
โโโ Same rules stated in different contexts
1.3 Detect Prose Fragmentation
Find explanations that are SCATTERED when they should be TOGETHER:
FRAGMENTATION DETECTION:
โโโ Same concept explained partially in multiple files:
โ Example: "Expert delegation" explained 30% in expert-delegation.md,
โ 20% in escalation-specification.md, 50% in agent-conduct.md
โ โ Consolidate into single authoritative explanation
โ
โโโ Workflow explanation split across files:
โ Example: Steps 1-3 in file A, steps 4-6 in file B, step 7 missing
โ โ Reunify or clearly link the sequence
โ
โโโ Definition separated from context:
โ Example: Signal format in signals.md, usage rules in workflows.md
โ โ Either consolidate or create clear cross-references
โ
โโโ Examples separated from concepts:
โ Example: Concept explained in chapter.md, examples in examples.md
โ โ Consider reunifying unless examples are extensive
โ
โโโ Prerequisites scattered:
Example: "You need X" in file A, "X works like..." in file C
โ Reader can't follow without hunting through multiple files
1.4 Detect Prose Mixing
Find explanations that are TOGETHER when they should be SEPARATE:
MIXING DETECTION:
โโโ Multiple unrelated concepts in one file:
โ Example: File covers state management AND signal formats AND recovery
โ โ These serve different readers at different times - separate them
โ
โโโ Mixed audiences:
โ Example: Developer how-to mixed with orchestrator implementation details
โ โ Developers don't need orchestrator details - separate them
โ
โโโ Mixed depths:
โ Example: Quick-start overview mixed with exhaustive reference
โ โ Reader wants one or the other - separate them
โ
โโโ Mixed purposes:
โ Example: "What is X" (conceptual) mixed with "How to X" (tutorial)
โ โ These serve different needs - consider separating
โ
โโโ Mixed time contexts:
Example: Setup (do once) mixed with runtime (do repeatedly)
โ Reader needs these at different times - separate them
Phase 2: Consistency Analysis (CHECK THE PROSE)
2.1 Semantic Contradictions
Check for CONFLICTING EXPLANATIONS (not just conflicting numbers):
CONTRADICTION DETECTION:
โโโ Same concept explained differently:
โ Example: File A says "agents can delegate to experts"
โ File B says "agents must solve problems themselves"
โ โ CRITICAL: Resolve which explanation is correct
โ
โโโ Conflicting instructions:
โ Example: File A says "always signal before exiting"
โ File B says "exit immediately on failure"
โ โ CRITICAL: Clarify when each applies
โ
โโโ Conflicting definitions:
โ Example: File A defines "task" as single work item
โ File B uses "task" to mean entire workflow
โ โ CRITICAL: Standardize terminology
โ
โโโ Conflicting assumptions:
โ Example: File A assumes reader knows signals
โ File B assumes reader is learning signals
โ โ These files serve different audiences - clarify or separate
โ
โโโ Implicit contradictions:
Example: File A implies X is always true
File B describes a case where X is false
โ Make the exception explicit
2.2 Explanation Completeness
Check for GAPS in explanations:
GAP DETECTION:
โโโ Concepts referenced but never explained:
โ Example: "Use the signal format" - but what IS the signal format?
โ โ Add explanation or clear reference
โ
โโโ Workflows with missing steps:
โ Example: "1. Do X, 2. Do Y, 4. Do Z" - what's step 3?
โ โ Complete the workflow
โ
โโโ Assumptions stated but not justified:
โ Example: "Always use method A" - why? When is method B appropriate?
โ โ Explain the reasoning
โ
โโโ Edge cases ignored:
โ Example: "Process the input" - what if input is invalid?
โ โ Address edge cases or state assumptions
โ
โโโ Reader questions unanswered:
Example: After reading, would a reader still wonder "but what about...?"
โ Anticipate and answer those questions
2.3 Referential Consistency
Check that references match reality:
REFERENTIAL CHECKS:
โโโ Link claims match content:
โ Example: Link says "see signal formats" but target explains workflows
โ โ Fix the link or the description
โ
โโโ Cross-references are bidirectional:
โ Example: A links to B, but B doesn't acknowledge A
โ โ Add backlink if relationship is important
โ
โโโ Hierarchies are consistent:
โ Example: Index claims file is about X, file is actually about Y
โ โ Update index or clarify file's purpose
โ
โโโ Navigation matches content organization:
Example: Navigation implies reading order AโBโC but C should come first
โ Fix navigation to match logical flow
Phase 3: Reorganization Planning (PLAN PROSE CHANGES)
3.1 Consolidation Planning
Plan where to MERGE scattered explanations:
CONSOLIDATION PLANNING:
โโโ For each fragmented concept:
โ โโโ Which file should be the AUTHORITATIVE source?
โ โ โ Usually the most complete/accurate version
โ โ
โ โโโ What content needs to MOVE there?
โ โ โ List specific prose sections, not just "merge files"
โ โ
โ โโโ What should REMAIN in source files?
โ โ โ Brief mention + reference, or nothing?
โ โ
โ โโโ How will readers find it?
โ โ Update navigation, add redirects
โ
โโโ Consolidation output format:
CONSOLIDATE: "Expert Delegation"
FROM: expert-delegation.md (lines 50-120), escalation-spec.md (lines 30-45)
TO: expert-delegation.md
REASON: Concept explained twice with slight variations
ACTION: Merge prose, pick clearer wording, reference from other file
3.2 Separation Planning
Plan where to SPLIT mixed content:
SEPARATION PLANNING:
โโโ For each mixed file:
โ โโโ What DISTINCT explanations does it contain?
โ โ โ List them as separate topics
โ โ
โ โโโ Can they stand alone?
โ โ โ Each new file should make sense independently
โ โ
โ โโโ How should they be named?
โ โ โ Names should reflect the explanation, not arbitrary sections
โ โ
โ โโโ How will they link to each other?
โ โ Cross-references for related concepts
โ
โโโ Separation output format:
SEPARATE: "state/task-tracking.md"
INTO:
- state/task-tracking.md: "Task selection and tracking" (lines 10-200)
- state/updates.md: "When state changes" (lines 201-400)
- state/recovery.md: "How to recover state" (lines 401-500)
REASON: Three distinct topics serving different needs
ACTION: Create focused files, add index, cross-reference
3.3 Movement Planning
Plan where to RELOCATE misplaced content:
MOVEMENT PLANNING:
โโโ Content in wrong file:
โ Example: Signal parsing details in workflow-overview.md
โ โ Move to signals.md where it belongs conceptually
โ
โโโ Content at wrong level:
โ Example: Implementation details in quick-start.md
โ โ Move to detailed reference
โ
โโโ Content for wrong audience:
โ Example: Orchestrator internals in developer-guide.md
โ โ Move to orchestrator documentation
โ
โโโ Movement output format:
MOVE: "Signal parsing implementation"
FROM: task-dispatch.md (lines 200-350)
TO: communication-protocol.md
REASON: Parsing details don't belong in dispatch workflow
ACTION: Move prose, leave brief reference in source
3.4 Line Limit Compliance
AFTER semantic reorganization, check line limits:
LINE LIMIT ANALYSIS (Secondary to semantic concerns):
โโโ Files over limit AFTER semantic fixes:
โ โโโ Is the content genuinely cohesive? โ Exception may be justified
โ โโโ Can it be split semantically? โ Find natural boundaries in prose
โ โโโ Would splitting harm understanding? โ Keep together if so
โ
โโโ Line limits are a CONSTRAINT, not a GOAL:
โ โโโ Never split mid-explanation to meet a limit
โ โโโ Never refuse consolidation because result is large
โ โโโ Semantic organization > line counts
โ
โโโ Report files over limit with recommendations
Phase 4: Refactoring Execution
4.1 Execution Order
Execute changes prioritizing semantic correctness:
EXECUTION SEQUENCE:
1. BUILD CHANGE MANIFEST (before any edits)
- List all files to be modified
- Track all paths/anchors that will change
- This enables reference integrity checking later
2. RESOLVE CONTRADICTIONS (highest priority)
- Determine correct explanation
- Update conflicting files to align
- Document the resolution
3. CONSOLIDATE SCATTERED EXPLANATIONS
- Merge prose into authoritative source
- Replace duplicates with references
- Preserve all unique information
4. SEPARATE MIXED CONTENT
- Create focused files for distinct topics
- Move prose to appropriate locations
- Add navigation and cross-references
5. MOVE MISPLACED CONTENT
- Relocate prose to correct conceptual homes
- Update source to reference new location
- Fix navigation paths
6. ADDRESS SIZE (only if needed after above)
- Semantic splits only
- Never split mid-explanation
- Create navigation for split content
7. REFERENCE INTEGRITY (MANDATORY - See Phase 5)
- Scan ENTIRE project for references to changed files
- Update ALL broken references
- Verify zero orphaned references remain
- THIS STEP IS NOT OPTIONAL
8. VERIFY CONSISTENCY
- Re-check for contradictions
- Confirm explanations are complete
- Validate all links work
4.2 Prose Preservation Rules
When moving/merging explanations:
PRESERVATION RULES:
โโโ NEVER lose explanations - all prose must survive reorganization
โโโ NEVER change meaning - preserve explanatory intent
โโโ PREFER clearer wording when merging duplicate explanations
โโโ PRESERVE examples that illustrate concepts
โโโ ADD context when moving content to new location
โโโ UPDATE references so readers can find moved content
โโโ DOCUMENT changes - what moved where and why
4.3 Navigation Maintenance
Ensure readers can find reorganized content:
NAVIGATION RULES:
โโโ Every explanation reachable within 1 level from entry points
โโโ Index files summarize what each file EXPLAINS
โโโ Related explanations linked bidirectionally
โโโ Clear reading paths for different audiences
โโโ No dead ends (every file leads somewhere)
โโโ Moved content findable from old locations (redirects or references)
Phase 5: Reference Integrity (MANDATORY)
This phase is NOT optional. Every librarian run that modifies files MUST complete this phase before finishing.
5.1 Build Change Manifest
Before any edits, track what will change:
CHANGE MANIFEST (build before editing):
โโโ Files to be modified:
โ โโโ {file_path}: {what changes}
โ โโโ ...
โ
โโโ Files to be moved/renamed:
โ โโโ {old_path} โ {new_path}
โ โโโ ...
โ
โโโ Anchors to be changed:
โ โโโ {file}#{old_anchor} โ {file}#{new_anchor}
โ โโโ ...
โ
โโโ Content relocated:
โโโ "{concept}" from {source} to {target}
โโโ ...
5.2 Execute Reference Scan
After ALL edits are complete, scan the ENTIRE project for references:
grep -r "old_filename\.md" .claude/ --include="*.md"
grep -r "old_anchor" .claude/ --include="*.md"
Scan locations (MANDATORY - do not skip any):
.claude/docs/ - All documentation
.claude/experts/ - Generated expert agent files
.claude/skills/ - Skill definitions
.claude/commands/ - Command definitions
.claude/prompts/ - Prompt templates
README.md, CLAUDE.md - Root documentation
- Any other
.md files in the project
5.3 Update All References
For each broken reference found:
REFERENCE UPDATE PROCEDURE:
1. Read the file containing the broken reference
2. Identify the reference context (what is it linking to?)
3. Update to new location/anchor
4. Verify the new reference is valid
5. Save the file
Reference patterns to check:
[text](path/to/file.md) - Markdown links
[text](path/to/file.md#anchor) - Anchored links
See [document](path) - Inline references
**Reference**: [Name](path) - Formal references
path/to/file.md - Plain path mentions
5.4 Verify Reference Integrity
After updating all references, VERIFY nothing is broken:
VERIFICATION PROCEDURE:
1. RE-SCAN for old paths/anchors
- grep -r "{old_path}" .claude/ --include="*.md"
- Result MUST be empty (zero matches)
2. VALIDATE new references exist
- For each updated reference, confirm target file exists
- For anchored links, confirm anchor exists in target
3. CHECK for orphaned files
- Files that were sources of moved content
- Ensure they either redirect or are deleted
4. REPORT results
- List all references updated
- Confirm zero broken references remain
5.5 Reference Integrity Output
Include in final report:
REFERENCE INTEGRITY CHECK
=========================
Change Manifest:
- {N} files modified
- {N} files moved/renamed
- {N} anchors changed
References Updated: {count}
- {file}: Updated {N} references to {target}
- ...
Verification:
โ Zero references to old paths remain
โ All new references validated
โ No orphaned files
Scanned Locations:
โ .claude/docs/ ({N} files)
โ .claude/experts/ ({N} files)
โ .claude/skills/ ({N} files)
โ .claude/commands/ ({N} files)
โ .claude/prompts/ ({N} files)
If ANY broken references remain, the librarian run is INCOMPLETE.
Output Formats
Audit Mode Output
LIBRARIAN AUDIT REPORT
======================
Directory: {path}
Files Analyzed: {count}
PROSE CONTRADICTIONS (must resolve):
------------------------------------
CRITICAL: {concept} explained inconsistently
- {file_a}: "{explanation_a}" (lines {range})
- {file_b}: "{explanation_b}" (lines {range})
Resolution needed: {what needs to be decided}
FRAGMENTED EXPLANATIONS (should consolidate):
---------------------------------------------
Concept "{concept}" explained in pieces:
- {file1}: Explains {aspect1} (lines {range})
- {file2}: Explains {aspect2} (lines {range})
- {file3}: Explains {aspect3} (lines {range})
Recommendation: Consolidate to {target}, reference from others
MIXED CONTENT (should separate):
--------------------------------
File "{file}" mixes unrelated topics:
- {topic_a}: {description} (lines {range})
- {topic_b}: {description} (lines {range})
Recommendation: Separate into {file_a}, {file_b}
INCOMPLETE EXPLANATIONS:
------------------------
- {file}: {concept} mentioned but not explained
- {file}: {workflow} missing steps {which}
- {file}: {term} used but never defined
SIZE ISSUES (after semantic fixes):
-----------------------------------
| File | Lines | Semantic Split Possible? |
|------|-------|--------------------------|
| {file} | {lines} | {yes/no - why} |
Run with mode=refactor to apply changes.
Refactor Mode Output
LIBRARIAN REFACTOR COMPLETE
===========================
CHANGE MANIFEST:
----------------
Files modified: {count}
Files moved/renamed: {count}
Anchors changed: {count}
CONTRADICTIONS RESOLVED: {count}
--------------------------------
1. {concept}: Chose {file}'s explanation as authoritative
Updated: {other_files}
Reason: {why this explanation is correct}
EXPLANATIONS CONSOLIDATED: {count}
----------------------------------
1. "{concept}" unified from {count} sources โ {target}
Prose merged: {line_count} lines
Sources now reference: {target}
CONTENT SEPARATED: {count}
--------------------------
1. {source} split into:
- {file1}: Explains {topic1}
- {file2}: Explains {topic2}
CONTENT MOVED: {count}
----------------------
1. {topic} moved from {source} to {target}
Reason: {why it belongs there}
REFERENCE INTEGRITY (MANDATORY):
--------------------------------
Locations scanned:
โ .claude/docs/ ({N} files)
โ .claude/experts/ ({N} files)
โ .claude/skills/ ({N} files)
โ .claude/commands/ ({N} files)
โ .claude/prompts/ ({N} files)
References updated: {count}
- {file}: {old_ref} โ {new_ref}
- ...
Verification:
โ Re-scan found ZERO broken references
โ All new references validated
PROSE VERIFICATION:
-------------------
โ No contradicting explanations remain
โ Each concept has single authoritative source
โ All explanations complete and findable
โ Navigation paths preserved
Concept Affinity Rules
When deciding what explanations belong together:
High Affinity (same file)
- Concept definition and its examples
- Workflow overview and its steps
- Rule and its exceptions
- Format specification and its usage
Medium Affinity (same directory, linked)
- Overview and detailed reference
- Tutorial and troubleshooting
- Concept and related concepts
Low Affinity (separate, cross-linked)
- Different roles' documentation
- Different phases of a process
- Conceptual vs implementation
Quality Checks
Before Refactoring
After Refactoring
Reference Integrity (MANDATORY)
The librarian run is NOT complete until reference integrity is verified.
Error Handling
| Issue | Action |
|---|
| Contradictions can't be resolved from prose alone | Flag for human decision |
| Explanation doesn't fit anywhere cleanly | Create new topic category |
| Consolidation would create huge file | Accept if cohesive, flag if not |
| Separation would fragment explanation | Keep together |
Prerequisites
| Requirement | Purpose |
|---|
Read access to path | Read and understand documentation prose |
Write access to path | Reorganize files (refactor mode) |
| Task tool | Parallel analysis agents to read files |
| Understanding | Actually READ the prose, don't just scan |