anomalyco / anomalyco/opencode

[Ollama] /thinking toggle and think parameter not passed to local Ollama provider API requests

Open
#47,359 2 comments 0 reactions 1 assignee View on GitHub

@jlongster is already working on this.

Since Sep 4, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Problem

When using OpenCode with a local Ollama provider (not ollama-cloud), the /thinking toggle has no effect. The think parameter is never included in API requests sent to the Ollama Chat API (POST /api/chat).

This means there is no way to control reasoning behavior for thinking-capable models (Qwen3, QwQ, DeepSeek-R1, etc.) served via a local Ollama instance.

Additionally, OpenCode does not parse <think>...</think> tags from the model's response stream — reasoning content is dumped inline with the regular response text, making it unreadable.

Note: Issue #36638 describes a similar problem for ollama-cloud variants. This issue is specifically about the local Ollama provider (@ai-sdk/openai-compatible), which has the same underlying problem but through a different code path.

Steps to Reproduce
  1. Configure a local Ollama provider in ~/.config/opencode/config.json:
{
  "provider": {
    "ollama": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Ollama",
      "options": {
        "baseURL": "http://192.168.1.90:11434/v1"
      },
      "models": {
        "qwen3.8:27b": {
          "name": "qwen3.8:27b"
        }
      }
    }
  }
}
  1. Launch opencode and select the model
  2. Toggle /thinking on
  3. Send any prompt (e.g., "Solve 2+2 step by step")
  4. Observe the response
Expected Behavior
  • The /thinking toggle sends "think": true (or "think": false when off) as a top-level field in the Ollama Chat API request body
  • When think is enabled, <think>...</think> blocks in the model output are parsed and rendered separately (dimmed text, collapsible section, etc.)
  • The /thinking toggle provides the same level of control as the Ollama CLI (ollama run --think=true) or the raw API ("think": true in JSON)
Actual Behavior
  • The think parameter is absent from the API request — confirmed by inspecting Ollama server logs
  • The /thinking toggle has zero effect on model behavior
  • When the model produces <think>...</think> blocks (thinking-enabled models), the reasoning content appears inline as raw text mixed with the actual response
  • The only workaround is embedding /no_think in the model's system prompt via Ollama Modelfile, which is unreliable (soft instruction, not enforced)
Workaround

Currently, the only way to suppress reasoning output is to bake a system prompt into the model via Ollama Modelfile:

FROM qwen3.8:27b
SYSTEM You are a helpful coding assistant. Provide direct answers without any internal reasoning, thoughts, or <think> tags.

This is a soft instruction that the model may ignore. There is no reliable workaround for enabling/disabling thinking on demand.

Environment
Component Version
OpenCode latest
Ollama 0.32.13
Model qwen3.8:27b (supports think parameter)
OS Debian Linux
Provider local Ollama (@ai-sdk/openai-compatible)
Proposed Fix
  1. Pass think parameter: When the active provider targets an Ollama instance, translate the /thinking toggle into "think": true/false in the API request body. This aligns with the Ollama Chat API spec where think is a top-level parameter.

  2. Parse <think> tags: Implement stream parsing for <think>...</think> markers in the response. Display reasoning content in a visually distinct block (dimmed, collapsible, or prefixed). This would match the behavior of other terminal coding agents (e.g., Pi Coding Agent) that already handle this correctly.

  3. Add think to provider config: Allow explicit configuration in opencode.json:

{
  "provider": {
    "ollama": {
      "models": {
        "qwen3.8:27b": {
          "name": "qwen3.8:27b",
          "reasoning": true,
          "variants": {
            "high": { "think": true },
            "off": { "think": false }
          }
        }
      }
    }
  }
}
References

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.