opencode-cliproxyapi-sync
v1.3.0
Published
Auto-sync OpenCode configs from CLIProxyAPI Dashboard
Maintainers
Readme
opencode-cliproxyapi-sync
Auto-sync OpenCode configs from CLIProxyAPI Dashboard.
What it does
This plugin automatically syncs your OpenCode configuration (opencode.json and oh-my-opencode.json) from the CLIProxyAPI Dashboard. It checks for config updates on OpenCode startup and applies them automatically.
Features
- 🔄 Automatic Sync: Checks for config updates on OpenCode startup
- ⚡ Fast: Only syncs when configs actually change (version-based)
- 🔒 Secure: Uses sync tokens for authentication
- 📝 Smart Notifications: Only shows toast when
opencode.jsonchanges (requiring restart) - 💾 Atomic Writes: Safe config file updates (no partial writes)
Installation
Option 1: NPX Install (Recommended)
npx opencode install opencode-cliproxyapi-syncOption 2: Manual Configuration
Add to your opencode.jsonc plugin array:
{
"plugin": [
"opencode-cliproxyapi-sync@latest",
"oh-my-opencode@latest"
]
}Important: Place opencode-cliproxyapi-sync before oh-my-opencode in the plugins array to ensure config is synced before oh-my-opencode loads.
Setup
1. Generate Sync Token
- Open the CLIProxyAPI Dashboard
- Navigate to Settings → Config Sync
- Click Generate Sync Token
- Copy the token (it starts with
tok_...)
2. Create Plugin Config File
Create the plugin config file:
Standard location:
~/.config/opencode-cliproxyapi-sync/config.jsonWith OCX profile:
~/.config/opencode/profiles/<profilename>/opencode-cliproxyapi-sync/config.jsonConfig content:
{
"dashboardUrl": "https://dashboard.yourdomain.com",
"syncToken": "tok_abc123...",
"lastKnownVersion": null
}Config Fields:
dashboardUrl: Your CLIProxyAPI Dashboard URL (no trailing slash)syncToken: The sync token from Step 1lastKnownVersion: Leave asnull(plugin manages this automatically)
Security: The plugin automatically sets restrictive permissions (chmod 600) on the config file.
How it works
- On OpenCode Startup: Plugin loads and checks your config
- Version Check: Fetches current config version from dashboard
- Compare: If version differs from
lastKnownVersion, fetches full bundle - Write Configs: Atomically writes
opencode.jsonandoh-my-opencode.json - Notify: Shows toast if
opencode.jsonchanged (requiring restart) - Update Version: Saves new version to plugin config
Configuration Sync Behavior
- Sync Timing: Only on OpenCode startup (not while running)
- Network Timeout: 5s for version check, 10s for bundle download
- Retries: Up to 2 retries with exponential backoff (1s, 2s)
- Error Handling: All errors logged but never crash OpenCode
Notifications
The plugin shows a toast notification only when opencode.json changes:
⚠️ Config Sync
opencode.json updated. Restart OpenCode to apply provider changes.
If only oh-my-opencode.json changes, no notification is shown (those changes apply immediately on next session).
File Locations
Standard (no profile):
- Plugin Config:
~/.config/opencode-cliproxyapi-sync/config.json - OpenCode Config:
~/.config/opencode/opencode.json - Oh My OpenCode Config:
~/.config/opencode/oh-my-opencode.json
With OCX profile:
- Plugin Config:
~/.config/opencode/profiles/<name>/opencode-cliproxyapi-sync/config.json - OpenCode Config:
~/.config/opencode/profiles/<name>/opencode.json - Oh My OpenCode Config:
~/.config/opencode/profiles/<name>/oh-my-opencode.json
(Respects XDG_CONFIG_HOME and OPENCODE_CONFIG_DIR environment variables)
OCX Profile Support
When using OCX profiles, the plugin uses per-profile configuration. This means:
- Each profile has its own plugin config - you can sync different profiles to different dashboards or disable sync for some profiles
- Syncing only affects the active profile - starting
ocx oc -p workwill only update configs in theworkprofile directory - No cross-profile interference - the standard config is never touched when using a profile
Setup for OCX profiles:
# Create config for your profile
mkdir -p ~/.config/opencode/profiles/myprofile/opencode-cliproxyapi-sync
cat > ~/.config/opencode/profiles/myprofile/opencode-cliproxyapi-sync/config.json << 'EOF'
{
"dashboardUrl": "https://dashboard.yourdomain.com",
"syncToken": "your-token-here",
"lastKnownVersion": null
}
EOF
# Now start with profile - only this profile syncs
ocx oc -p myprofileDisable sync for a profile: Simply don't create a config.json in that profile's opencode-cliproxyapi-sync folder.
Troubleshooting
Plugin doesn't sync
Check config file exists and is valid:
# Standard location
cat ~/.config/opencode-cliproxyapi-sync/config.json
# Or with OCX profile
cat ~/.config/opencode/profiles/<profilename>/opencode-cliproxyapi-sync/config.jsonCheck OpenCode logs for sync messages:
# Look for lines like:
[cliproxyapi-sync] Synced to version abc123...
[cliproxyapi-sync] Failed to check version. Skipping sync.Authentication errors (401)
- Verify your
syncTokenis correct - Check if token was revoked in Dashboard → Settings → Config Sync
- Generate a new token if needed
Config not updating
- Ensure dashboard URL is correct (no trailing slash)
- Check firewall/network allows access to dashboard
- Verify dashboard is running and accessible
Notification not showing
- Notification only appears when
opencode.jsonchanges - If only
oh-my-opencode.jsonchanged, no notification is shown (expected)
Development
Build from source
cd plugin
bun install
bun build src/index.ts --outdir dist --target nodeLocal testing
- Build the plugin (see above)
- Link locally:
cd plugin npm link cd ~/.config/opencode npm link opencode-cliproxyapi-sync - Add
"opencode-cliproxyapi-sync"to youropencode.jsonplugins array - Restart OpenCode
License
MIT
Support
- Dashboard Issues: https://github.com/itsmylife44/opencode-cliproxyapi-sync/issues
- CLIProxyAPI: https://github.com/router-for-me/CLIProxyAPI
- OpenCode: https://opencode.ai
