Skip to content

Latest commit

 

History

12 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

llama-swap-sync

Automatically keep your opencode model list in sync with your llama-swap configuration — no manual editing required.


How it works

Whenever you save your config.yaml, a systemd path unit detects the change and runs a sync script that:

  1. Parses all models from the models: block in your llama-swap config.yaml
  2. Extracts each model's context size from -c / --ctx-size arguments
  3. Derives the model display name from the .gguf filename
  4. Adds new models, removes deleted ones, and updates context sizes in opencode.json
  5. Backs up opencode.json before every change
config.yaml saved → systemd detects change → llama-swap-sync.sh runs → opencode.json updated

Requirements

  • Linux with systemd (user units)
  • python3 — stdlib only, no extra packages
  • bash

Install

git clone https://github.com/janvitos/llama-swap-sync
cd llama-swap-sync
chmod +x install.sh
./install.sh

The installer will:

  • Copy llama-swap-sync.sh to ~/.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

First-time setup

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.


Usage

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

Useful systemd commands

# 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 30

What gets written to opencode.json

Given 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 }
        }
      }
    }
  }
}

Notes

  • JSONC supportedopencode.json files with // comments and trailing commas are handled correctly
  • Backups — a timestamped .bak file is created next to opencode.json before 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.yaml directly; it does not query the llama-swap API

Files

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

License

MIT

About

Auto-sync llama-swap models to opencode.json

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages