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
Most commands automatically sync when needed. Use manual sync after external changes (git pull, manual file edits) or when troubleshooting.
Storage Architecture
sudocode uses a 3-layer storage system:Layer 1: Markdown Files
Human-readable spec and issue files in
.sudocode/specs/ and .sudocode/issues/Purpose: Version control, human editing, readabilityLayer 2: JSONL Files
Line-delimited JSON in
.sudocode/specs.jsonl and .sudocode/issues.jsonlPurpose: Git-friendly structured data, source of truth- User edits markdown → Sync to JSONL → Import to database
- CLI updates database → Export to JSONL → Sync to markdown
Options
Watch for file changes and auto-syncExample:
--watchStarts a file watcher that automatically syncs when files change. Press Ctrl+C to stop.Debounce: 2000ms (2 seconds) delay to batch rapid changesForce sync FROM markdown TO databaseExample:
--from-markdownAlways syncs in this direction, regardless of file modification times.Use after: Manual markdown edits, git pull with markdown changesForce sync FROM database TO markdownExample:
--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
For both specs and issues:
- 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
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
After Manual Markdown Edits
Troubleshoot Sync Issues
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:
To Markdown:
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?
Manual sync is needed when:
- 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?
Generally no, but:
- 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?
User edits in markdown are considered intentional and take precedence over database state. This protects manual work.
How do I recover from bad sync?
How do I recover from bad sync?
Use git:Or restore from JSONL:
Can I sync individual files?
Can I sync individual files?
Not directly. Sync operates on all files. For selective updates, use specific commands:
Troubleshooting
Sync says 'everything in sync' but files differ
Sync says 'everything in sync' but files differ
Cause: Modification times are equal despite content differencesSolution:
Force specific direction:
Sync errors on specific files
Sync errors on specific files
Cause: Invalid markdown format or corrupted dataSolution:
- Check file format:
- Fix frontmatter issues
- Resync:
Watch mode not detecting changes
Watch mode not detecting changes
Cause: File system watcher issues or editor behaviorSolution:
- 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
Cause: Large number of filesSolution:
Normal for large projects. Consider:
- 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
Cause: Merge conflict in JSONL filesSolution:
- Resolve JSONL conflicts in git
- Force import from JSONL:
Related Commands
Next Steps
Storage Model
Learn more about sudocode’s 3-layer storage architecture

