Syntax
Description
Thesync command manages data flow between sudocode’s 3-layer storage system:
Markdown Files ↔ JSONL Files ↔ SQLite Database
Use sync to:
- Synchronize after git pull (update local database)
- Sync after manual markdown edits
- Force a specific sync direction
- Watch for changes and auto-sync
- Troubleshoot sync issues
Storage Architecture
sudocode uses a 3-layer storage system:Layer 1: Markdown Files
.sudocode/specs/ and .sudocode/issues/Purpose: Version control, human editing, readabilityLayer 2: JSONL Files
.sudocode/specs.jsonl and .sudocode/issues.jsonlPurpose: Git-friendly structured data, source of truthLayer 3: SQLite Database
.sudocode/sudocode.dbPurpose: Fast queries, relationships, views- User edits markdown → Sync to JSONL → Import to database
- CLI updates database → Export to JSONL → Sync to markdown
Options
--watchStarts a file watcher that automatically syncs when files change. Press Ctrl+C to stop.Debounce: 2000ms (2 seconds) delay to batch rapid changes--from-markdownAlways syncs in this direction, regardless of file modification times.Use after: Manual markdown edits, git pull with markdown changes--to-markdownAlways syncs in this direction, regardless of file modification times.Use after: CLI operations that updated database onlyExamples
Automatic Direction Detection
Let sudocode determine sync direction:Expected output (markdown is newer)
Expected output (markdown is newer)
Expected output (already in sync)
Expected output (already in sync)
After Git Pull
Sync database with pulled changes:Expected output
Expected output
Force Sync from Markdown
After manually editing markdown files:Expected output
Expected output
Force Sync to Markdown
Regenerate markdown from database:Expected output
Expected output
Watch Mode
Auto-sync on file changes:Expected output
Expected output
JSON Output
Get machine-readable output:JSON output
JSON output
How Sync Direction is Determined
When you runsync without flags, it automatically detects the correct direction:
Compare file modification times
- Get most recent markdown file modification time
- Get JSONL file modification time
Determine direction for each type
- If markdown is newer → sync FROM markdown
- If JSONL is newer → sync TO markdown
- If timestamps match → no sync needed
Handle conflicts
- Prefer FROM markdown (preserves user edits)
- Reason: User edits in markdown take precedence
Decision Matrix
| Markdown State | JSONL State | Direction | Reason |
|---|---|---|---|
| Newer | Older | from-markdown | User edited markdown |
| Older | Newer | to-markdown | Database updated (git pull) |
| Same | Same | no-sync | Already in sync |
| Missing | Exists | to-markdown | Regenerate markdown |
| Exists | Missing | from-markdown | Import to JSONL |
| Mixed | Mixed | from-markdown | Prefer user edits |
Common Workflows
Daily Development
Start work
Make changes
Sync before commit
After Manual Markdown Edits
Edit markdown
Sync to database
Verify changes
Troubleshoot Sync Issues
Force resync from JSONL
Check for errors
Manually inspect
Development with Watch Mode
For active development:Understanding Sync Behavior
Auto-Sync in Commands
Most commands auto-sync as needed:- Creating entities: Database → JSONL → Markdown
- Updating entities: Database → JSONL → Markdown
- After operations: JSONL export triggered automatically
- After
git pull(external changes) - After manual markdown edits
- Troubleshooting inconsistencies
Sync Operations
From Markdown:Read markdown files
.sudocode/specs/ and .sudocode/issues/Update database
Export to JSONL
specs.jsonl and issues.jsonlRead from database
Generate markdown
Write files
.sudocode/specs/ and .sudocode/issues/Watch Mode Details
Watch mode monitors file changes and auto-syncs: Configuration:- Debounce delay: 2000ms (2 seconds)
- Waits 2 seconds after last change before syncing
- Prevents excessive syncs during rapid edits
- Watched directories:
.sudocode/specs/.sudocode/issues/.sudocode/*.jsonl
- File creation
- File modification
- File deletion
- Press Ctrl+C to stop
- Ensures clean exit
Common Questions
When do I need to run sync manually?
When do I need to run sync manually?
- After
git pull(pulled JSONL changes) - After editing markdown files directly
- Troubleshooting sync inconsistencies
- Regenerating markdown from database
What's the difference between sync, export, and import?
What's the difference between sync, export, and import?
- sync: Bidirectional, auto-detects direction, handles markdown ↔ database
- export: Database → JSONL only
- import: JSONL → Database only
sync for normal operations, export/import for manual data migration.Can sync cause data loss?
Can sync cause data loss?
- Syncing FROM markdown overwrites database changes
- Syncing TO markdown overwrites markdown edits
- Always commit to git before major sync operations
- JSONL files are the source of truth - never deleted
Why does sync prefer from-markdown in conflicts?
Why does sync prefer from-markdown in conflicts?
How do I recover from bad sync?
How do I recover from bad sync?
Can I sync individual files?
Can I sync individual files?
Troubleshooting
Sync says 'everything in sync' but files differ
Sync says 'everything in sync' but files differ
Sync errors on specific files
Sync errors on specific files
- Check file format:
- Fix frontmatter issues
- Resync:
Watch mode not detecting changes
Watch mode not detecting changes
- Restart watch mode
- Use manual sync instead
- Check editor settings (some use atomic writes that may not trigger watchers)
Sync takes very long
Sync takes very long
- Archiving old entities
- Splitting into multiple projects
- Using watch mode instead of manual sync
Database out of sync after git merge conflict
Database out of sync after git merge conflict
- Resolve JSONL conflicts in git
- Force import from JSONL:
Related Commands
Next Steps
Pull latest changes
Sync database
Verify sync
Start work

