OpenCode + Ollama Troubleshooting 2026: Provider Errors, Tool Calls, Models & Logs
If OpenCode works for normal chat but fails when it has to edit a file, run a command, reason through a long task, or discover an Ollama model, the problem is usually at a specific boundary: provider configuration, model capability, context length, tool-call formatting, streaming, or a version-specific regression.
This guide is for the moment when Ollama and OpenCode are installed but the workflow is unreliable. Instead of reinstalling everything, isolate the stack from the Ollama API upward.
Start by identifying the broken layer
| Symptom | Likely layer | First test |
|---|---|---|
| Ollama works but OpenCode cannot see the model | Provider discovery/configuration | ollama list and /v1/models |
| OpenCode requests fail immediately | Base URL, model ID or API compatibility | Call Ollama's OpenAI-compatible endpoint directly |
| Chat works but file edits fail | Tool calling/model capability | Try one simple file creation task |
| Reasoning model hangs or loops | Provider/model/streaming compatibility | Compare OpenCode with direct /v1/chat/completions |
| It broke after an update | Version regression | Record both versions and reproduce the smallest failure |
Reinstalling OpenCode will not make a model suddenly gain reliable tool calling. Increasing context will not repair a wrong URL. Changing models will not fix an unreachable server. Find the boundary first.
1. Verify Ollama before touching OpenCode
Run the basic checks:
ollama --version
ollama list
ollama ps
Then run the exact model directly:
ollama run qwen3-coder
If the direct Ollama test fails, stay on the Ollama side. OpenCode adds another layer and should not be your first diagnostic tool.
Test the OpenAI-compatible endpoint
OpenCode can use Ollama through its OpenAI-compatible API. A normal local endpoint is http://localhost:11434/v1.
curl http://localhost:11434/v1/models
You should get JSON describing the models exposed by Ollama. If this request fails, OpenCode cannot repair the underlying connectivity problem.
2. Try the current Ollama integration path
Ollama provides a direct launcher for OpenCode:
ollama launch opencode
For configuration without immediately launching a session:
ollama launch opencode --config
Ollama's current integration documentation says this launcher creates inline configuration for the selected model and does not overwrite your existing OpenCode configuration. If you maintain a custom configuration, inspect the effective behavior rather than assuming the launcher replaced it.
3. When OpenCode cannot find your Ollama model
Keep three names separate: the Ollama model tag, the OpenCode provider ID, and the display name.
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"ollama": {
"npm": "@ai-sdk/openai-compatible",
"name": "Ollama",
"options": {
"baseURL": "http://localhost:11434/v1"
},
"models": {
"qwen3.5": {
"name": "qwen3.5"
}
}
}
}
}
Match the configured model identifier against ollama list and /v1/models. Do not copy an old model name from a tutorial and assume it still exists.
Provider configuration has also evolved. A February 2026 OpenCode GitHub issue reported confusion around multiple Ollama provider configurations and provider IDs. That is a useful warning against treating old examples as permanent contracts.
4. OpenCode connects, but tool calls fail
Normal generation and agentic tool use are different capabilities. OpenCode needs the model to receive a tool description, select a tool, emit a structured call, wait for the result, and continue. A model that replies “run npm test” has not actually run the tool.
Start with a tiny test:
Create a file named tool-test.txt containing exactly: TOOL_OK
Then:
Read tool-test.txt and tell me its exact contents.
Only after those work should you test a large repository task.
Context length can break tool loops
OpenCode's current Ollama provider documentation recommends increasing Ollama's num_ctx when tool calls do not work, with 16K–32K as a starting point. Ollama's OpenCode integration guidance recommends at least 64K for coding tools when the hardware permits it.
These are recommendations, not guarantees. Context consumes memory. Increase it gradually and watch system RAM or VRAM rather than setting an enormous value automatically.
5. Raw tool JSON, blank replies and strange loops
If you see raw tool-call structures instead of a normal answer, investigate compatibility before assuming the whole application is broken.
- Model: Is it trained for function/tool calling?
- Provider: Are you using Ollama's integration or an OpenAI-compatible provider?
- Context: Is the conversation plus tool schema consuming the available window?
- Streaming: Does the same request work without OpenCode?
- Reasoning: Does the model expose reasoning in the field the provider expects?
OpenCode's model documentation notes that OpenAI-compatible reasoning models may need a configured reasoning field when streamed reasoning uses a custom assistant-message field. This can explain why direct inference succeeds while an agent loop behaves differently.
6. Reasoning models that hang or enter generation loops
Compare OpenCode with the underlying API. A current OpenCode GitHub issue reports cases where Ollama reasoning models became extremely slow or entered a generation loop through the OpenAI-compatible provider while direct /v1/chat/completions remained fast. Treat this as an attributed configuration/model-path report, not a universal Ollama bug.
curl http://localhost:11434/v1/chat/completions -H "Content-Type: application/json" -d '{
"model": "YOUR_MODEL",
"messages": [{"role": "user", "content": "Reply with exactly OK"}],
"stream": false
}'
If direct inference is fast but OpenCode hangs, investigate provider configuration, streaming, reasoning fields, context size, and exact versions. If direct inference also hangs, the failure is lower in the stack.
7. Diagnose update regressions without guessing
Local AI stacks change quickly. OpenCode, Ollama, model templates and compatibility layers can update independently. If a previously working setup breaks, stop changing several variables at once.
opencode --version
ollama --version
ollama list
ollama ps
Save the effective OpenCode configuration and exact model tag. Then test one known-good model and the target model.
| Test | Meaning |
|---|---|
| Ollama direct chat | Basic runtime |
/v1/models | API availability/discovery |
Direct /v1/chat/completions | OpenAI-compatible inference path |
| OpenCode simple chat | Provider integration |
| One file tool | Tool-call capability |
| Multi-step repository task | Context and agent-loop stability |
This gives you a reproducible boundary. If direct chat and API calls pass but the first file tool fails, networking is unlikely to be the cause.
8. Logs and memory pressure
Collect the real error before reinstalling. Run OpenCode from the terminal and preserve its output. Check Ollama with ollama ps to confirm the expected model is loaded.
Repeated model unloading, heavy swapping, or system-wide memory pressure can look like an application failure. Also distinguish connection refused, timeout, DNS/address errors, and HTTP 4xx/5xx responses. They point to different layers and require different fixes.
9. Docker, remote Ollama and localhost mistakes
If OpenCode and Ollama both run directly on the host, localhost:11434 is normally simplest. If one component runs in Docker, localhost means the container itself. On Docker Desktop, host.docker.internal can route from a container to the host; Linux may need another network configuration.
For remote Ollama, expose the service deliberately and protect it. Do not make an unauthenticated inference API publicly reachable simply to make OpenCode connect.
10. Security matters because OpenCode is an agent
A local model does not automatically make an agent safe. OpenCode can work with files, commands and other tools. Test in a dedicated project directory and avoid running it from a directory containing SSH keys, production credentials, API secrets or unrelated private documents.
If Ollama is remote, restrict network access and use appropriate authentication or a private network. Local inference can improve data locality, but it does not remove the risks created by granting an agent filesystem and shell access.
11. If an update really is the problem
If the same model and configuration worked before an update and fail immediately afterward, capture the versions and reproduce the smallest failing case. Check the exact OpenCode release notes and GitHub issues for that version and symptom.
If a newer release fixes the issue, upgrade deliberately. If a confirmed regression blocks your workflow, temporarily pinning the last known-good version can be reasonable while waiting for a fix. Avoid downgrading unrelated components without evidence.
12. Clean recovery sequence
- Run
ollama listand verify the exact model tag. - Run the model directly.
- Test
http://localhost:11434/v1/models. - Test one direct
/v1/chat/completionsrequest. - Record OpenCode and Ollama versions.
- Try
ollama launch opencodeif appropriate. - For manual setup, verify base URL and model ID.
- Test a one-file tool call.
- Increase context gradually if longer loops fail.
- Only then investigate streaming, reasoning-field and version-specific regressions.
FAQ
Why does OpenCode see Ollama but not my model?
Check the exact model tag with ollama list and compare it with the configured model ID. Test /v1/models directly as well.
Why can my Ollama model chat but not edit files?
Text generation and structured tool calling are different capabilities. Try a tiny file-creation task and use a model with strong tool-use support.
How much context should OpenCode use with Ollama?
OpenCode's current provider guidance suggests starting around 16K–32K for troubleshooting. Ollama recommends at least 64K for coding tools when hardware permits. More context consumes more memory.
Why does an Ollama reasoning model work through curl but hang in OpenCode?
That can indicate a provider-path compatibility problem involving streaming, reasoning fields, context or the agent loop. Compare the direct API result with OpenCode and then inspect exact versions.
Should I expose Ollama on 0.0.0.0?
Only when required by your network topology and with appropriate network protection. Do not treat an unauthenticated endpoint as safe for public exposure.
Official sources
- OpenCode Providers documentation
- OpenCode Models documentation
- Ollama OpenCode integration documentation
- Ollama launch command announcement
- OpenCode issue on Ollama reasoning-model behavior
Related GyanAangan guides
- OpenCode + Ollama setup guide
- Open WebUI + Ollama connection guide
- Open WebUI tool-calling and context troubleshooting
- AnythingLLM + Ollama RAG setup guide
Model selection and hardware sanity checks
Before spending an hour debugging OpenCode, make sure the model is a sensible match for the machine. A model can technically load and still be a poor coding-agent choice because its context window, tool behavior, or memory footprint leaves too little headroom for the agent loop.
| Situation | Better diagnostic choice | Why |
|---|---|---|
| Limited RAM/VRAM | Smaller instruction model with a moderate context | Leaves memory for the operating system and tool results |
| Tool calls fail on a large model | Test a smaller tool-capable model | Separates model capability from resource pressure |
| Long repository task | Model with reliable long-context behavior | Tool descriptions, files and previous results consume context |
| Reasoning model hangs | Compare with a non-reasoning model | Helps isolate reasoning/streaming compatibility |
Do not interpret “fits in VRAM” as “will work well as an agent.” OpenCode has to maintain conversation history, tool definitions and tool results in addition to the model itself. A configuration that is comfortable for a one-shot chat request can become unstable during a long coding session.
Windows, macOS and Linux differences
The diagnostic logic is the same across operating systems, but the network boundary can differ. On Windows and macOS, Docker Desktop commonly provides host.docker.internal for reaching a host service from a container. On Linux, a container-to-host route may need explicit Docker networking configuration. If OpenCode is running natively, start with the native Ollama endpoint instead of introducing Docker networking unnecessarily.
On Apple Silicon, memory is shared between the operating system and GPU workloads, so a large context can affect the whole machine rather than only a discrete GPU. On systems with a discrete GPU, watch both GPU memory and system RAM because model offloading and operating-system activity can still create pressure.
Do not “fix” a tool problem by changing everything
A reliable troubleshooting session changes one variable at a time. Keep a short record of the model tag, OpenCode version, Ollama version, context size and provider URL for every test. Once you find a working combination, change only one item and retest. This is slower for the first ten minutes and much faster than trying five random fixes and losing track of which one actually mattered.