You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ive tested it with your json and just changed the model definitions to the new gpt-oss variants and it works - not good in terms of model capability - but the communication to ollama works.
Here is how I achieved it:
Installed ollama and opencode
Started ollama (ollama start) and pulled the gpt-oss 20b model (ollama run gpt-oss:20b).
Created a the opencode.jsonconfig file in my project folder with:
I would recommend for testing to leave the terminal with the ollama start open to see the logs. There you can see if your model gets used by opencode and if its working at the moment.
✅ Auto-generate opencode.json for Ollama (via Bash)
This script allows you to automatically create a valid opencode.json configuration for [OpenCode](https://opencode.ai), based on the models currently available in your local [Ollama](https://ollama.com) instance.
🧠 What it does
Connects to your local Ollama server (IP or localhost)
Retrieves available model names via API
Lets you select a model using fzf
Writes a proper opencode.json file in the required format
📜 The Bash Script
#!/bin/bash# OLLAMA Host/IP (adjust if needed)
OLLAMA_HOST="http://localhost:11434"# Get list of available models
MODELS=$(curl -s "$OLLAMA_HOST/api/tags"| jq -r '.models[].name')# Select model using fuzzy finder (fzf)
SELECTED=$(echo "$MODELS"| fzf --prompt="Choose a model > ")# Exit if no model is selectedif [ -z"$SELECTED" ];thenecho"❌ No model selected – aborting."exit 1
fi# Write opencode.json
cat > opencode.json <<EOF{ "\$schema": "https://opencode.ai/config.json", "provider": { "ollama": { "npm": "@ai-sdk/openai-compatible", "name": "Ollama (local)", "options": { "baseURL": "$OLLAMA_HOST/v1" }, "models": { "$SELECTED": { "name": "$SELECTED" } } } }, "model": "ollama/$SELECTED"}EOFecho"✅ opencode.json created with model: $SELECTED"
LM studio seems much more reliable, I consistently see people having ollama issues because they arent handling certain models correctly, like they had some issue with qwen models (or some other one) were they didnt parse out tool calls properly and it was an issue for a while…
if i have a webui as frontend to ollama. My gpt-oss keeps returning "max_tokens must be at least 1, got -1928." even though I can connect it with my zed or even via cli.
I'll help you analyze your codebase. To do this properly, I'll need to explore your project structure and files. Let me start by examining what files and directories you have.
⚙ invalid [tool=todolist, error=Model tried to call unavailable tool 'todolist'. Available tools: invalid, bash, read, glob, grep, list, edit, write, task, webfetch, todowrite, todoread.]
I'll help you analyze your codebase. To do this properly, I'll need to explore your project structure and files. Let me start by examining what files and directories you have.
⚙ invalid [tool=todolist, error=Model tried to call unavailable tool 'todolist'. Available tools: invalid, bash, read, glob, grep, list, edit, write, task, webfetch, todowrite, todoread.]
Activity
tommyboylab commentedon Aug 7, 2025
Something like this, adjust for gpt based model:
https://opencode.ai/docs/providers/#ollama
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"ollama": {
"npm": "@ai-sdk/openai-compatible",
"name": "Ollama (local)",
"options": {
"baseURL": "http://localhost:11434/v1"
},
"models": {
"qwen3-coder:30b": {
"name": "Qwen3-Coder 30B (MoE 3.3B active)"
}
}
}
},
"model": "ollama/qwen3-coder:30b"
}
ghwiegand commentedon Aug 7, 2025
Thank you @tommyboylab !
Ive tested it with your json and just changed the model definitions to the new gpt-oss variants and it works - not good in terms of model capability - but the communication to ollama works.
Here is how I achieved it:
ollama start) and pulled the gpt-oss 20b model (ollama run gpt-oss:20b).opencode.jsonconfig file in my project folder with:{ "$schema": "https://opencode.ai/config.json", "provider": { "ollama": { "npm": "@ai-sdk/openai-compatible", "name": "Ollama (local)", "options": { "baseURL": "http://localhost:11434/v1" }, "models": { "gpt-oss:20b": { "name": "gpt-oss 20b local" } } } }, "model": "ollama/gpt-oss:20b" }opencodein the project directory.I would recommend for testing to leave the terminal with the
ollama startopen to see the logs. There you can see if your model gets used by opencode and if its working at the moment.Happy coding 👨💻
Gaetner84 commentedon Aug 7, 2025
✅ Auto-generate
opencode.jsonfor Ollama (via Bash)This script allows you to automatically create a valid
opencode.jsonconfiguration for [OpenCode](https://opencode.ai), based on the models currently available in your local [Ollama](https://ollama.com) instance.🧠 What it does
fzfopencode.jsonfile in the required format📜 The Bash Script
⚙️ Requirements
Make sure the following tools are installed:
[jq](https://stedolan.github.io/jq/)– for JSON parsing[fzf](https://github.com/junegunn/fzf)– for model selectioncurl,bashollama start)🧪 How to use
Save the script as
generate-opencode.shMake it executable:
Run it:
After running, you'll have a valid
opencode.jsonthat points to the exact Ollama model you selected.You can now launch OpenCode and it will use that model directly.
🧩 Example
opencode.jsonOutput{ "$schema": "https://opencode.ai/config.json", "provider": { "ollama": { "npm": "@ai-sdk/openai-compatible", "name": "Ollama (local)", "options": { "baseURL": "http://localhost:11434/v1" }, "models": { "llama3:8b": { "name": "llama3:8b" } } } }, "model": "ollama/llama3:8b" }thdxr commentedon Aug 7, 2025
don't use ollama use LM studio
Gaetner84 commentedon Aug 8, 2025
no i use ollama it is better on server and works perfect!
chbornman commentedon Aug 8, 2025
This clearly works, so probably just close the issue?
Any suggestions on how to get opencode to work better with local models? I've only ever had good performance using opencode with Anthropic models
nathfavour commentedon Aug 20, 2025
Why tho
rekram1-node commentedon Aug 20, 2025
LM studio seems much more reliable, I consistently see people having ollama issues because they arent handling certain models correctly, like they had some issue with qwen models (or some other one) were they didnt parse out tool calls properly and it was an issue for a while…
vpereira commentedon Nov 30, 2025
if i have a webui as frontend to ollama. My gpt-oss keeps returning "max_tokens must be at least 1, got -1928." even though I can connect it with my zed or even via cli.
rekram1-node commentedon Dec 2, 2025
@vpereira can you send me output of:
opencode debug configvpereira commentedon Dec 4, 2025
sure, here it is:
rekram1-node commentedon Dec 4, 2025
@vpereira im guessing u had the error w/
qwen3-coder:30b? I think that's because there is no limit set therevpereira commentedon Dec 5, 2025
Hi @rekram1-node
No unfortunately, i get the following error:
My Prompt was: "Please analyse my code base"
vpereira commentedon Dec 5, 2025
with the model
gpt-oss, i get the error "max_tokens must be at least 1, got -2490."OpenCode version 1.0.133
With aider I am able to use the model and interact with my file system
Kaszanas commentedon Jan 5, 2026
I have the same issue.
github-actions commentedon Mar 25, 2026
To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one.
fix(composer): prevent cursor jumping to position 0 on multiline paste (