A bash script that automatically configures opencode to use a local llama-swap instance. It detects the currently running model, resolves context window metadata for auto-compaction, and launches opencode with a generated config.
- Auto-detects the active model from llama-swap's
/runningendpoint - Resolves context length for opencode auto-compaction via a fallback chain:
LOCAL_CONTEXTenvironment variablemeta.llamaswap.context_lengthfrom llama-swap's/v1/modelsmetadata--ctx-sizeparsed from the running llama-server command line
- Generates a temporary
opencode.jsonconfig and cleans up on exit - Can be sourced or executed directly
- llama-swap running locally (or remotely)
- opencode installed and in
PATH curlandjq
# Basic usage (auto-detects model from llama-swap)
./oc.sh
# Override the llama-swap endpoint
LOCAL_ENDPOINT=http://host:port ./oc.sh
# Specify a model explicitly
LOCAL_MODEL=my-model ./oc.sh
# Override context/output limits
LOCAL_CONTEXT=16384 LOCAL_OUTPUT=4096 ./oc.sh
# Resume an existing opencode session
./oc.sh -s <session-id>| Variable | Default | Description |
|---|---|---|
LOCAL_ENDPOINT |
http://localhost:8080 |
llama-swap API endpoint |
LOCAL_MODEL |
(auto-detected) | Model ID to use |
LOCAL_CONTEXT |
(auto-detected) | Context window size (tokens) |
LOCAL_OUTPUT |
(auto-detected) | Max output tokens |
For best results, configure metadata in your llama-swap YAML so the script can automatically pick up context and output limits:
models:
my-model:
cmd: "llama-server --ctx-size 16384 ..."
metadata:
context_length: 16384
output_length: 4096Contributions are welcome! Feel free to open an issue or submit a pull request.