Multi-file rule organization
Instead of maintaining all rules in a single AGENTS.md file, AlignTrue supports organizing rules across multiple markdown files. This is especially useful for large projects with many rules or teams where different people own different rule categories.
Overview
Multi-file organization allows you to:
- Split rules into logical categories (e.g.,
architecture.md,security.md,coding-standards.md) - Reduce merge conflicts when multiple people edit rules
- Make it easier to find and update specific rule types
- Maintain clear ownership of different rule categories
Configuration
Configure multi-file sources in .aligntrue/config.yaml:
sync:
source_files: "rules/*.md" # Glob pattern for source files
source_order: # Optional: custom merge order
- architecture.md
- security.md
- coding-standards.mdSource file patterns
The source_files field accepts:
- Single file:
"AGENTS.md"(default) - Glob pattern:
"rules/*.md"(all.mdfiles inrules/directory) - Array of patterns:
["arch.md", "security.md"](specific files)
Source order
By default, files are merged alphabetically by basename. Use source_order to specify a custom order:
sync:
source_order:
- important-first.md
- then-this.md
- finally-this.mdFiles not listed in source_order are appended alphabetically at the end.
How it works
Discovery
AlignTrue discovers source files using the configured patterns:
- Resolves glob patterns relative to workspace root
- Reads all matching markdown files
- Parses sections from each file
Merging
Source files are merged into a single internal representation:
- Files are ordered (alphabetically or by
source_order) - Sections from each file are concatenated in order
- Each section tracks its source file for provenance
Provenance
Every section includes metadata about its source file:
sections:
- heading: "Architecture Guidelines"
content: "..."
vendor:
aligntrue:
source_file: "architecture.md" # Tracks originThis metadata helps with:
- Debugging which file a section came from
- Two-way sync (editing the right source file)
- Conflict resolution
CLI Commands
List source files
View all configured source files and their section counts:
aligntrue sources listOutput:
Source patterns: rules/*.md
Custom order: architecture.md, security.md, coding-standards.md
Found 3 source files:
rules/architecture.md (5 sections)
rules/security.md (8 sections)
rules/coding-standards.md (6 sections)Split existing AGENTS.md
Convert a single AGENTS.md file into multiple files:
# Interactive (prompts for confirmation and target directory)
aligntrue sources split
# Non-interactive
aligntrue sources split --yesThis command:
- Parses sections from
AGENTS.md - Creates a separate file for each section
- Updates config to use the new files
- Optionally backs up the original
AGENTS.md
Example project structure
project/
├── .aligntrue/
│ └── config.yaml
├── rules/
│ ├── architecture.md
│ ├── security.md
│ └── coding-standards.md
├── .cursor/
│ └── rules/
│ └── combined.mdc (generated)
└── AGENTS.md (generated)Two-Way Sync
Multi-file sources work seamlessly with two-way sync:
- Edit any source file: Make changes to
rules/security.md - Run sync:
aligntrue sync - Changes propagate: Updates sync to all agent files
AlignTrue tracks which file each section came from, so edits to agent files can be merged back to the correct source file.
Best practices
File organization
- Group related rules: Put all security rules in
security.md - Use clear names:
security.mdnotrules1.md - Keep files focused: One concern per file
- Limit file count: 3-10 files is ideal; too many becomes hard to navigate
Naming conventions
- Use lowercase with hyphens:
coding-standards.md - Be descriptive:
api-design-guidelines.md - Avoid abbreviations unless well-known:
security.mdnotsec.md
Team collaboration
- Assign ownership: Use
CODEOWNERSto assign file ownership - Custom order: Use
source_orderto prioritize important files - Clear boundaries: Make it obvious which rules belong in which file
Migration strategy
When migrating from single-file to multi-file:
- Start small: Split into 3-5 logical categories
- Test thoroughly: Run
aligntrue syncand verify outputs - Update team docs: Document the new structure
- Keep backup: Don’t delete
AGENTS.mdimmediately
Comparison with Single-File
| Aspect | Single File (AGENTS.md) | Multi-File |
|---|---|---|
| Setup | Simpler | Requires config |
| Navigation | Scroll through one file | Jump between files |
| Merge Conflicts | More frequent | Less frequent |
| Ownership | Shared | Can be per-file |
| Organization | Sections within file | Files and sections |
| Best For | Small projects (< 20 rules) | Large projects (20+ rules) |
Troubleshooting
Files not found
If aligntrue sources list shows no files:
- Check the glob pattern in
sync.source_files - Verify files exist relative to workspace root
- Check file extensions match the pattern
Wrong merge order
If sections appear in the wrong order:
- Add or update
sync.source_orderin config - List files in desired order
- Run
aligntrue syncto regenerate
Section conflicts
If you see “Section conflict” warnings:
- Check if the same section heading exists in multiple files
- Rename one of the headings to make them unique
- Or merge the duplicate sections into one file
Related Features
- Two-Way Sync - Edit agent files or source files
- Scopes - Path-based rule application for monorepos
- Team Mode - Lockfile validation and drift detection
Example
See the multi-file-rules example for a complete working example with:
- Multiple source files organized by concern
- Custom merge order
- Documentation and best practices