When to Use Document Sharding
Only use sharding if you notice your chosen tool/model combination is failing to load and read all the documents as input when needed. Symptoms that might indicate sharding is needed:- Workflows fail to load complete PRD or architecture documents
- Agents reference only partial content from large files
- Context length errors during workflow execution
- Inconsistent results when working with 30k+ token documents
- Using a model with larger context window (Claude Sonnet 3.5, GPT-4 Turbo)
- Breaking your content into more focused documents naturally
- Upgrading to latest workflow versions with better context handling
Most users don’t need document sharding. Modern workflows handle large documents effectively.
What is Document Sharding?
Document sharding takes a single large markdown file and splits it into multiple smaller files organized in a directory structure. How it works:- Splits on level 2 headings (
## Heading) - Creates a directory with the original filename
- Generates individual files for each section
- Creates an index file with table of contents
Before and After Structure
Before Sharding:Index File Structure
The generatedindex.md provides navigation:
How to Shard a Document
Step 1: Run the Shard-Doc Tool
Step 2: Follow Interactive Prompts
The workflow guides you through the process:Step 3: Verify Results
Check the generated files:index.md to review table of contents and descriptions.
Spot-check a few section files to ensure splits are clean.
Step 4: Choose Version Priority
BMad workflows use a dual discovery system:- Try whole document first - Look for
document-name.md - Check for sharded version - Look for
document-name/index.md - Priority rule - Whole document takes precedence if both exist
How Workflows Use Sharded Documents
All BMad workflows support both formats transparently:Workflow Discovery Process
Selective Loading
Workflows load only needed sections:Best Practices
Document Structure for Clean Sharding
Organize documents with consistent level 2 headings: Good structure:Section Size Guidelines
Ideal section size: 2k-8k tokens- Too small (less than 1k tokens): Excessive file fragmentation, navigation overhead
- Just right (2k-8k tokens): Good balance between file size and organization
- Too large (greater than 10k tokens): Consider adding more level 2 headings to split further
Naming Conventions
The shard tool auto-generates filenames from headings:## Functional Requirements→functional-requirements.md## API Specifications→api-specifications.md## User Stories→user-stories.md
- Lowercase
- Hyphens instead of spaces
- Special characters removed
.mdextension added
Maintain Cross-References
Update internal links after sharding: Before sharding:Workflow Support
Workflows that support both whole and sharded documents:Troubleshooting
Workflows Don’t Find Sharded Document
Problem: Workflow says “PRD not found” butprd/ directory exists.
Solution:
- Ensure
index.mdexists in the sharded directory - Check filename matches expected pattern (lowercase, hyphens)
- Verify original whole document is removed or renamed
- Check workflow logs for exact path it’s looking for
Sections Split Incorrectly
Problem: Content that should be together is split across files. Solution:- Review original document heading structure
- Use level 3 headings (
###) for subsections that should stay together - Reserve level 2 headings (
##) for major sections you want split - Re-run sharding after adjusting heading levels
Cross-References Broken
Problem: Links between sections don’t work after sharding. Solution:- Update anchor links to file links:
#section→./section.md - Use relative paths:
./data-model.md, not/prd/data-model.md - Verify all referenced sections exist as files
- Test links by opening files in markdown preview
Sharding Created Too Many Files
Problem: 50+ small files make navigation difficult. Solution:- Consolidate related sections under fewer level 2 headings
- Use level 3 headings for subsections
- Aim for 8-15 section files as sweet spot
- Consider if sharding is actually needed
Migration Strategy
If you have existing large documents:Option 1: Shard Selectively
Only shard documents causing context issues:Option 2: Shard Everything
Create consistent structure across all documents:Option 3: Hybrid Approach
Use whole documents during active development, shard for reference:Future Direction
Document sharding is a temporary workaround for context limitations. Future improvements will eliminate the need:
- Subprocess agents - Workflows spawn focused agents with narrower context needs
- Dynamic section loading - Load document sections on-demand rather than upfront
- Improved context management - Better pruning and summarization of large documents
- Larger context windows - Models with 200k+ token windows make sharding unnecessary
Summary
Document sharding:- Use case: Large documents causing context issues in older model/tool combinations
- Process: Split on level 2 headings into directory of smaller files
- Support: All BMad workflows support both whole and sharded documents
- Best practice: Only shard if you experience context problems
- Future: Soon unnecessary as workflows and models improve
