OpenCode Plugin
Theopencode-sync-plugin syncs your OpenCode sessions to OpenSync automatically. Every session, message, and token count is pushed to your dashboard in real time.
Source identifier: opencode
Installation
Install globally with npm:Setup
Generate an API key
Log in to opensync.dev, go to Settings, and click Generate API Key. Copy the key (starts with
osk_).Run login
- Convex URL:
https://polished-penguin-622.convex.cloud(for hosted) or your self-hosted URL - API Key: The key you copied from Settings
Config file
Credentials are stored in~/.opencode-sync/config.json:
login command and removed by logout.
Commands
opencode-sync login
Stores your Convex URL and API key. Prompts interactively if values are not provided as flags.opencode-sync status
Shows connection state and sync statistics:opencode-sync sync
Manually triggers a sync of all sessions. Useful after a network interruption or if you notice missing sessions.Sessions sync automatically as you work. You only need to run manual sync if something got out of step.
opencode-sync logout
Removes stored credentials from~/.opencode-sync/config.json.
How syncing works
- OpenCode stores session data in
~/.opencode/sessions/as JSON files. - The plugin reads session and message data from this directory.
- Each session is pushed to the
/sync/sessionHTTP endpoint on your Convex deployment. - Each message within the session is pushed to
/sync/message. - The plugin uses
externalIdfor deduplication, so re-syncing the same session is safe.
What gets synced
| Data | Source | Mapped to |
|---|---|---|
| Session metadata | OpenCode session JSON | sessions table |
| Messages | OpenCode message entries | messages table |
| Message parts | Text, tool calls, tool results | parts table |
| Token counts | Per-message and per-session | promptTokens, completionTokens |
| Cost | Calculated from model pricing | sessions.cost |
| Project path | Working directory from OpenCode | sessions.projectPath |
| Model name | Model identifier from each message | sessions.model |
URL normalization
The plugin converts your Convex URL from.convex.cloud to .convex.site for HTTP endpoints:
.convex.cloud URL during login.
Troubleshooting
Plugin not syncing
- Run
opencode-sync statusto check the connection. - Verify your API key is still valid in the dashboard Settings.
- Check that OpenCode is writing to
~/.opencode/sessions/. - Try
opencode-sync syncto force a manual sync.
Sessions missing
- OpenCode may buffer session data. Wait a few seconds after ending a session, then run
opencode-sync sync. - Check that the session directory (
~/.opencode/sessions/) contains JSON files.
Permission errors
The plugin needs read access to~/.opencode/sessions/. On macOS, this is usually granted automatically. On Linux, check file permissions:
Network errors
If you seeECONNREFUSED or timeout errors:
- Verify your Convex deployment is running (
GET /healthon your Convex site URL should return{"status": "ok"}). - Check your firewall or proxy settings.
- For self-hosted deployments, ensure the Convex URL is correct.