Guide for developers and LLM coding agents to set up a local development environment for oc-sync.
- Node.js 18+
- npm
- GitHub Personal Access Token with
reposcope - OpenCode installed
git clone https://github.com/ErcinDedeoglu/opencode-sync.git
cd opencode-sync
npm install
npm run buildCreate or edit ~/.config/opencode/opencode.json:
{
"plugin": [
"file:///absolute/path/to/opencode-sync/dist/index.js"
]
}Replace /absolute/path/to/opencode-sync with the actual path to your cloned repo.
export GITHUB_TOKEN=ghp_your_token_hereThe token needs repo scope to create and access the private sync repository.
opencodeCheck the log file:
cat ~/.local/share/opencode/log/opencode-sync.logExpected output:
[opencode-sync] Plugin starting...
[opencode-sync] Token loaded from: environment variable
[opencode-sync] Setting up sync storage...
[opencode-sync] Creating sync repository...
[opencode-sync] Linked to repo: username/.opencode-sync
[opencode-sync] Plugin ready
Run TypeScript compiler in watch mode for automatic rebuilds:
npm run devAfter each rebuild, restart OpenCode to pick up changes.
npm run buildnpm run check # Run all checks (typecheck + lint + format)
npm run typecheck # TypeScript type checking
npm run lint # ESLint
npm run format # Prettiersrc/
├── plugin/ # OpenCode plugin integration
│ ├── plugin.ts # Main plugin entry point
│ └── state-manager.ts
├── sync/
│ ├── engine/ # Core sync orchestration
│ ├── merge/ # Three-way merge logic
│ ├── operations/ # Push/pull operations
│ └── watcher/ # File system watcher
├── storage/ # GitHub repo backend
├── data/ # Local data loading/saving
├── crypto/ # Encryption for credentials
└── types/ # TypeScript type definitions
All plugin logs go to:
~/.local/share/opencode/log/opencode-sync.log
Tail logs in real-time:
tail -f ~/.local/share/opencode/log/opencode-sync.logAfter first run, the plugin creates ~/.config/opencode/opencode-sync.json:
{
"token": "ghp_...",
"machineId": "hostname-abc123",
"repoOwner": "username",
"repoName": ".opencode-sync",
"autoSyncOnStartup": true,
"continuousSync": true,
"syncIntervalMinutes": 5,
"sync": {
"config": true,
"state": true,
"credentials": true,
"sessions": true,
"messages": true,
"projects": true,
"todos": true
}
}To rotate encryption keys without losing access to credentials:
- Add both keys to config on ALL machines:
{
"encryptionKey": "new-key-here",
"oldEncryptionKey": "old-key-here"
}-
Restart OpenCode on each machine - it will:
- Decrypt using
oldEncryptionKey(fallback) - Re-encrypt using
encryptionKeyon next push
- Decrypt using
-
After all machines have synced, remove
oldEncryptionKey
- Check
opencode.jsonhas correct absolute path todist/index.js - Ensure
npm run buildcompleted successfully - Check OpenCode logs:
~/.local/share/opencode/log/*.log
Set GITHUB_TOKEN environment variable or create config file manually.
- Verify token has
reposcope - Check if repo already exists at
github.com/username/.opencode-sync
- Run
npm run build - Restart OpenCode completely (not just the TUI)