Automatically keep your opencode model list in sync with your llama-swap configuration — no manual editing required.
Whenever you save your config.yaml, a systemd path unit detects the change and runs a sync script that:
- Parses all models from the
models:block in your llama-swapconfig.yaml - Extracts each model's context size from
-c/--ctx-sizearguments - Derives the model display name from the
.gguffilename - Adds new models, removes deleted ones, and updates context sizes in
opencode.json - Backs up
opencode.jsonbefore every change
config.yaml saved → systemd detects change → llama-swap-sync.sh runs → opencode.json updated
- Linux with systemd (user units)
python3— stdlib only, no extra packagesbash
git clone https://github.com/janvitos/llama-swap-sync
cd llama-swap-sync
chmod +x install.sh
./install.shThe installer will:
- Copy
llama-swap-sync.shto~/.local/bin/ - Install the systemd units to
~/.config/systemd/user/ - Enable and start the file watcher
- Run first-time interactive setup, then do the initial sync
On first run you'll be prompted for:
| Prompt | Default |
|---|---|
Path to opencode.json |
~/.config/opencode/opencode.json |
Path to config.yaml |
~/llama-swap/config.yaml |
| llama-swap baseURL | http://127.0.0.1:41234/v1 |
| Provider ID | llama-swap |
| Provider display name | llama-swap |
Settings are saved to ~/.config/llama-swap-sync/settings.conf.
| Command | Description |
|---|---|
(edit and save config.yaml) |
Sync runs automatically |
llama-swap-sync.sh |
Run sync manually |
llama-swap-sync.sh --reconfigure |
Reset saved settings |
llama-swap-sync.sh --help |
Show usage |
# Check watcher status
systemctl --user status llama-swap-sync.path
# Follow sync logs live
journalctl --user -u llama-swap-sync.service -f
# View last sync output
journalctl --user -u llama-swap-sync.service -n 30Given this config.yaml:
models:
"qwen3-coder":
cmd: |
llama-server --port ${PORT} -c 32768 \
-m /models/Qwen3-Coder-30B-Q4_K_M.gguf
proxy: http://127.0.0.1:${PORT}
"gemma3-4b":
cmd: llama-server --port ${PORT} -c 8192 -m /models/gemma-3-4b-it-Q8_0.gguf
proxy: http://127.0.0.1:${PORT}The script produces this provider block in opencode.json:
{
"provider": {
"llama-swap": {
"npm": "@ai-sdk/openai-compatible",
"name": "llama-swap",
"options": {
"baseURL": "http://127.0.0.1:41234/v1"
},
"models": {
"qwen3-coder": {
"name": "Qwen3-Coder-30B-Q4_K_M",
"limit": { "context": 32768 }
},
"gemma3-4b": {
"name": "gemma-3-4b-it-Q8_0",
"limit": { "context": 8192 }
}
}
}
}
}- JSONC supported —
opencode.jsonfiles with//comments and trailing commas are handled correctly - Backups — a timestamped
.bakfile is created next toopencode.jsonbefore every write - Both write styles detected — the systemd path unit watches for both in-place writes and temp-file-rename writes (vim, nano, VS Code, etc.)
- No network calls — the script reads
config.yamldirectly; it does not query the llama-swap API
| File | Description |
|---|---|
llama-swap-sync.sh |
Main sync script |
llama-swap-sync.path |
systemd unit — watches config.yaml for changes |
llama-swap-sync.service |
systemd unit — runs the sync script |
install.sh |
Installs everything and runs first-time setup |
MIT