Ollama: Increase context for a model to use with Opencode

by default, ollama sets a very low context size with any model it launches. To change this, set the num_ctx parameter on a model and save it as a new model:

ollama run modelname:12b

/set parameter num_ctx 32768

/save modelname:12b-32k

Update .ollama/config.json to include the new model.

Start new model with ‘ollama launch opencode’ pick newly configured model from the list

Running local LLMs: ollama + opencode with gemma4:e2b

Assuming you have ollama installed and a local model already downloaded, install opencode following steps here.

Create an opencode.json with config pointing to your downloaded model:

{
"$schema": "https://opencode.ai/config.json",
"provider": {
"ollama": {
"npm": "@ai-sdk/openai-compatible",
"name": "Ollama",
"options": {
"baseURL": "http://localhost:11434/v1"
},
"models": {
"gemma4": {
"name": "gemma4:e4b"
}
}
}
}
}

Start opencode from ollama with:

ollama launch opencode

Scroll down to other models and select the model you configured above.