Skip to content

cli: opencode run hangs indefinitely with local Ollama model #65367

Open

Description

@TehseenTech

Summary

opencode run with the default local Ollama model produces no output and never exits. The same CLI completes normally with an HTTP-compatible remote model, and Ollama's own API answers the same prompt in seconds.

Environment

  • opencode version: 1.18.31 (opencode --version; executable resolved through %APPDATA%\npm\opencode.ps1). OpenCode Desktop 2.3.2 is also installed but its CLI is not the one on PATH.
  • OS: Microsoft Windows NT 10.0.26300.0 (Windows 11 x64). ver is unavailable in PowerShell, so [Environment]::OSVersion.VersionString was used.
  • Terminal: TERM=xterm-256color; TERM_PROGRAM, COLORTERM, and WT_SESSION unset. Command was launched from the OpenCode shell tool (non-interactive).
  • Shell: %COMSPEC% = C:\WINDOWS\system32\cmd.exe; OpenCode config sets "shell": "powershell" for its own shell tool.
  • Install/channel: npm global install, release channel (C:\Users\<user>\AppData\Roaming\npm\opencode.ps1).
  • Active plugins: None found. No plugins key in ~/.config/opencode/opencode.json or opencode.jsonc; no .opencode/plugin, .opencode/plugins, plugin, or plugins directories under the global config directory.

Reproduction

  1. Install Ollama 0.40.16 and pull qwen2.5-coder:7b (4.7 GB). Run ollama serve with OLLAMA_HOST=127.0.0.1:11434; confirm GET http://127.0.0.1:11434/api/tags returns 200.
  2. In the global config, the resolved default model is ollama/qwen2.5-coder:7b (opencode debug config confirms this).
  3. Run opencode run "Reply with exactly: LOCAL_OK" from any directory.
  4. Wait several minutes. No output is produced and the prompt never returns.
  5. Control A: direct POST http://127.0.0.1:11434/api/generate with {"model":"qwen2.5-coder:7b","prompt":"Say OK","stream":false,"options":{"num_predict":8}} returns HTTP 200, body {"response":"OK"}, in about 19 seconds.
  6. Control B: opencode run -m freellmapi/nemotron-3-ultra-550b "Reply with exactly: SAFE_OK" prints SAFE_OK and exits normally.

Expected Behavior

opencode run should print the model's reply and exit, or surface a clear timeout/connection error if the model cannot be reached.

Actual Behavior

The process stayed alive for about 8 minutes with no stdout and no error. Get-Process showed the opencode.exe process alive with Responding = True and roughly 22 seconds of cumulative CPU time. The parent shell also stayed alive with no output because the pipeline buffers until the child exits. Both were terminated manually; the shell reported exit code 4294967295.

Additional Context

  • Frequency: observed once; not re-run after restarting Ollama.
  • Ollama was listening only on 127.0.0.1:11434 with an inbound firewall block, so this is not a network reachability problem.
  • Relevant global config (no credentials shown):
"model": "ollama/qwen2.5-coder:7b",
"provider": {
  "ollama": {
    "npm": "@ai-sdk/openai-compatible",
    "options": { "baseURL": "http://127.0.0.1:11434/v1" },
    "models": {
      "qwen2.5-coder:7b": { "name": "Qwen2.5 Coder 7B" }
    }
  }
},
"sandbox": {
  "enabled": true,
  "image": "langchain/langgraph-sandbox:latest",
  "resources": { "cpu": 2, "memory": "4GiB" }
}
  • Docker Desktop's engine was not running during the failing test (it was started afterwards for an unrelated container audit). If sandbox startup is involved in this hang, that is worth checking; the remote-model control succeeded under the same condition.
  • No custom plugins or provider overrides affect this model beyond the config above.

Activity

  1. opencodejr commented on Nov 21, 2026

    @opencodejr
    Contributor

    Thanks for the detailed report and the two control tests.

    The opencode on your PATH is 1.18.31, which is OpenCode v1 (the opencode-ai npm package). v1 now only gets fixes for critical bugs, such as data loss, security problems or breakage with no workaround. This hang has workarounds, so it's unlikely to be fixed on v1.

    Please try the same thing on v2:

    npm uninstall -g opencode-ai
    npm install -g @opencode/cli
    

    Then open a new terminal and check that opencode --version shows 2.x. Other install options are at https://opencode.ai/docs/, and the changes from v1 are described at https://opencode.ai/docs/migrate-v1/. For example, v1 plugins don't run in v2.

    Related: #56448 was a v2 report (2.0.32, now closed) of a headless server stalling with a local Ollama model on Windows. If v2 behaves the same way for you, that issue may be useful for comparison.

    I'm closing this issue now. If it also happens on v2, or if you think this is critical, reply here and the issue will reopen. Please include the v2 opencode --version and the exact command you ran.

  2. TehseenTech commented on Nov 21, 2026

    @TehseenTech
    Author

    Reproduced on v2 as well.

    • opencode --version → opencode v2.3.2 (@opencode/cli, channel latest)
    • Exact command: opencode run "Reply with exactly: LOCAL_OK" (from ~/.config/opencode)
    • Result: no output, never exits. After ~2 minutes the process was still alive (Responding=True, 0.89s CPU), so I terminated it.
    • Default model is local ollama/qwen2.5-coder:7b (Ollama 0.40.16, 127.0.0.1:11434).

    Additional evidence:

    • Ollama's server log shows no request from this run; its last entry is an earlier direct POST /api/generate at 03:47:41 that returned 200 with OK in 19s.
    • ~/.local/share/opencode/log/opencode.log records cli starting version=2.3.2 channel=latest args=["run","Reply with exactly: LOCAL_OK"] and then nothing — no creating instance, no session, no model stream.
    • The same command on v1 (1.18.31) hung identically, while opencode run -m freellmapi/nemotron-3-ultra-550b "..." completes normally with SAFE_OK.

    This appears different from #56448: that report involved a custom client polling /api/session//message; here it is the CLI itself and no session is ever created.

  3. opencodejr commented on Nov 21, 2026

    @opencodejr
    Contributor

    Thanks for testing on v2 and for the log details.

    I tried to reproduce this on Linux with @opencode/cli 2.3.2 and the config from your report: the ollama provider via @ai-sdk/openai-compatible as the default model, plus the sandbox block with Docker not running. I ran opencode run "Reply with exactly: LOCAL_OK" from ~/.config/opencode, with an OpenAI-compatible stand-in for Ollama on 127.0.0.1:11434. It printed LOCAL_OK and exited within a second. So the sandbox setting, the default local model and the working directory don't cause the hang by themselves, at least on Linux.

    Your log points somewhere else. In a working run, opencode run starts a local server as a child process. That child writes its own cli starting ... args=["serve","--stdio","--port","0"] line to the same log, followed by its startup messages. Your log stops after the run line, which suggests the child server never starts (or never reports that it's ready) on your Windows setup. The model would never be called in that case, which fits Ollama seeing no request. This looks Windows-specific, so it needs a maintainer with a Windows machine.

    These would help whoever picks this up:

    • While it hangs, is there a second opencode process (for example in Get-Process opencode or Task Manager), and what is its command line?
    • Run the same command with $env:OPENCODE_PRINT_LOGS="1" set in PowerShell first, and paste any output.
    • Does it also hang when you run it from a normal PowerShell or Windows Terminal window rather than from inside OpenCode's shell tool?
    • Does opencode run -m freellmapi/nemotron-3-ultra-550b "..." still finish on 2.3.2? Your earlier remote-model test was with the 1.18.31 CLI.
  4. TehseenTech commented on Nov 21, 2026

    @TehseenTech
    Author

    Answers to the four checks, all on opencode v2.3.2 (@opencode/cli, installed via npm with scripts enabled):

    1. Second process while hanging: no. The only CLI process was opencode.exe run "Reply with exactly: LOCAL_OK" (PID 21324). There was no child opencode.exe serve --stdio --port 0 — the same process tree also contains OpenCode Desktop's own opencode-cli.exe serve --service, but nothing spawned by this run.

    2. OPENCODE_PRINT_LOGS=1: the only output was timestamp=2026-11-21T10:35:51.856Z level=INFO run=68bb182d message="cli starting" version=2.3.2 channel=latest local=false args="[\"run\",\"Reply with exactly: LOCAL_OK\"]" role=cli and then nothing.

    3. Normal PowerShell rather than the shell tool: also hangs. I started a separate hidden powershell.exe -NoProfile -Command '$env:OPENCODE_PRINT_LOGS="1"; opencode run "Reply with exactly: LOCAL_OK" 2>&1' and redirected its stdout/stderr. It was still running after 60s, with the same single cli starting log line. (PowerShell's -ArgumentList quoting split the prompt into several argv tokens in this variant, but it still produced no child server.) So the shell tool is not the trigger.

    4. Remote model on v2.3.2: opencode run -m freellmapi/nemotron-3-ultra-550b "Reply with exactly: SAFE_OK" printed SAFE_OK and exited in 12.3s. So the CLI and session machinery do work on this machine; the stall is specific to the local-model/default path and happens before the child server starts.

  5. TehseenTech commented on Nov 21, 2026

    @TehseenTech
    Author

    Possible lead for whoever picks this up: this may share a root cause with #64686 ("every session method hangs forever on Windows — Bun fetch starved by the /global/event SSE stream"). Our symptom fits that family: the CLI never spawns the serve --stdio --port 0 child and no session is ever created, so it stalls before any model call.

    Related PRs: #64984 and #64994 (node:http transport for ACP) were both closed without merge, and #63477 (cli: port to native) is still open — that would remove the Bun runtime from this path entirely.

    If a build from that PR, or a beta/dev channel build, is available, I'm happy to test opencode run "Reply with exactly: LOCAL_OK" on Windows 11 with the local Ollama model and report back. I can also provide process listings, OPENCODE_PRINT_LOGS=1 output, or opencode.log excerpts if useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions