Skip to main content
Document sharding splits large markdown files into smaller, organized files based on section headings for better context management in AI workflows.
Deprecated approach: This is no longer recommended. With updated workflows and modern LLMs supporting larger context windows and subprocesses, sharding will soon be unnecessary.

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
Before sharding, try:
  • 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:
After Sharding:

Index File Structure

The generated index.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:
Open 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:
  1. Try whole document first - Look for document-name.md
  2. Check for sharded version - Look for document-name/index.md
  3. Priority rule - Whole document takes precedence if both exist
To use sharded version:
To use whole document:
Keep the original file as backup until you’ve validated that workflows work correctly with the sharded version.

How Workflows Use Sharded Documents

All BMad workflows support both formats transparently:

Workflow Discovery Process

Selective Loading

Workflows load only needed sections:
This selective loading reduces context consumption and improves performance.

Best Practices

Document Structure for Clean Sharding

Organize documents with consistent level 2 headings: Good structure:
Problematic 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 Requirementsfunctional-requirements.md
  • ## API Specificationsapi-specifications.md
  • ## User Storiesuser-stories.md
Rules:
  • Lowercase
  • Hyphens instead of spaces
  • Special characters removed
  • .md extension added

Maintain Cross-References

Update internal links after sharding: Before sharding:
After sharding:
The shard tool attempts to update references automatically, but verify correctness.

Workflow Support

Workflows that support both whole and sharded documents:

Troubleshooting

Workflows Don’t Find Sharded Document

Problem: Workflow says “PRD not found” but prd/ directory exists. Solution:
  • Ensure index.md exists 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:
Upcoming improvements:
  • 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
Timeline: Most users won’t need sharding by Q3 2024 as these improvements roll out.

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
For most users, keeping documents whole is simpler and works fine with modern models and updated workflows.