Skip to content

Opencode TUI cannot be started with opencode v2 #55973

Closed

Description

@DaniloMurer

Description

When trying to start opencode in WSL Ubuntu following error appears:

Error: Server process exited with code 1
Error: Managed service port 49374 on 127.0.0.1 is already in use by another process. Configure another port with `opencode service set port <port>` and start the service again.
    at <anonymous> (/$bunfs/root/chunk-x6242730.js:2:8786) {
  [cause]: ServeError:
      at N (/$bunfs/root/chunk-q8wzwtww.js:52:7706)
      at applyHandlers (node:events:64:20)
      at emitError (node:events:44:27)
      at emitListenErrorNextTick (node:_http_server:134:12)
      at processTicksAndRejections (unknown:7:39) {
    [cause]: Error: Failed to start server. Is port 49374 in use?
        at serve (unknown)
        at <anonymous> (node:_http_server:359:39)
        at <anonymous> (node:_http_server:332:33)
        at <anonymous> (/$bunfs/root/chunk-q8wzwtww.js:52:7744)
  }
}
    at map (unknown:1:11)
    at reap (/$bunfs/root/chunk-b5fy5cjh.js:2:1203)
    at <anonymous> (/$bunfs/root/chunk-b5fy5cjh.js:3:6711)
    at service.ensure (/$bunfs/root/chunk-tbc1ctg4.js:3:690)
    at service.ensure (definition) (/$bunfs/root/chunk-b5fy5cjh.js:3:5523)
    at cli.server-connection.resolve (/$bunfs/root/chunk-r0qkjn9z.js:96:6563)
    at cli.server-connection.resolve (definition) (/$bunfs/root/chunk-tbc1ctg4.js:2:402)

This issue arises when opencode tries to use it's own default port or configuring a own port.

I've read in another open issue that a potential cause for this could be the port generation of opencode and what WSL / Windows reserves for some HyperV stuff. Thus i tried to set the port myself using opencode service set port in different ranges, all to no avail.

Maybe the issue is another with my networking mode on wsl being mirrored. It looks like the background service can be started, it's not alive from opencodes standpoint and tries to restart it.

Here the logs from my attempts using different ports and the opencode assigned port:

timestamp=2026-10-16T05:46:35.320Z level=ERROR run=04f5b91d message="cli process failed" cause="Cause([Fail(Error: Managed service port 49374 on 127.0.0.1 is already in use by another process. Configure another port with `opencode service set port <port>` and start the service again. (cause: ServeError (cause: Error: Failed to start server. Is port 49374 in use?)))])" args="[\"serve\",\"--service\"]" role=cli
timestamp=2026-10-16T05:48:14.928Z level=ERROR run=9f177f90 message="cli process failed" cause="Cause([Fail(Error: Server process exited with code 1\nError: Managed service port 49374 on 127.0.0.1 is already in use by another process. Configure another port with `opencode service set port <port>` and start the service again.\n    at <anonymous> (/$bunfs/root/chunk-x6242730.js:2:8786) {\n  [cause]: ServeError: \n      at N (/$bunfs/root/chunk-q8wzwtww.js:52:7706)\n      at applyHandlers (node:events:64:20)\n      at emitError (node:events:44:27)\n      at emitListenErrorNextTick (node:_http_server:134:12)\n      at processTicksAndRejections (unknown:7:39) {\n    [cause]: Error: Failed to start server. Is port 49374 in use?\n        at serve (unknown)\n        at <anonymous> (node:_http_server:359:39)\n        at <anonymous> (node:_http_server:332:33)\n        at <anonymous> (/$bunfs/root/chunk-q8wzwtww.js:52:7744)\n  }\n})])" args=[] role=cli
timestamp=2026-10-16T05:51:02.104Z level=INFO run=560dc207 message="cli starting" version=2.0.29 channel=latest local=false args="[\"--version\"]" role=cli
timestamp=2026-10-16T05:55:04.009Z level=INFO run=8b76da0e message="cli starting" version=2.0.29 channel=latest local=false args="[\"service\",\"set\",\"port\",\"12000\"]" role=cli
timestamp=2026-10-16T05:55:06.432Z level=INFO run=cab7c3cb message="cli starting" version=2.0.29 channel=latest local=false args=[] role=cli
timestamp=2026-10-16T05:55:06.506Z level=INFO run=cab7c3cb message="background service starting" reason=missing previousVersion=undefined role=cli
timestamp=2026-10-16T05:55:06.572Z level=INFO run=5b9a17d1 message="cli starting" version=2.0.29 channel=latest local=false args="[\"serve\",\"--service\"]" role=cli
timestamp=2026-10-16T05:55:11.581Z level=INFO run=798b104a message="cli starting" version=2.0.29 channel=latest local=false args="[\"serve\",\"--service\"]" role=cli
timestamp=2026-10-16T05:55:26.791Z level=ERROR run=798b104a message="cli process failed" cause="Cause([Fail(Error: Managed service port 12000 on 127.0.0.1 is already in use by another process. Configure another port with `opencode service set port <port>` and start the service again. (cause: ServeError (cause: Error: Failed to start server. Is port 12000 in use?)))])" args="[\"serve\",\"--service\"]" role=cli
timestamp=2026-10-16T05:57:06.550Z level=ERROR run=cab7c3cb message="cli process failed" cause="Cause([Fail(Error: Server process exited with code 1\nError: Managed service port 12000 on 127.0.0.1 is already in use by another process. Configure another port with `opencode service set port <port>` and start the service again.\n    at <anonymous> (/$bunfs/root/chunk-x6242730.js:2:8786) {\n  [cause]: ServeError: \n      at N (/$bunfs/root/chunk-q8wzwtww.js:52:7706)\n      at applyHandlers (node:events:64:20)\n      at emitError (node:events:44:27)\n      at emitListenErrorNextTick (node:_http_server:134:12)\n      at processTicksAndRejections (unknown:7:39) {\n    [cause]: Error: Failed to start server. Is port 12000 in use?\n        at serve (unknown)\n        at <anonymous> (node:_http_server:359:39)\n        at <anonymous> (node:_http_server:332:33)\n        at <anonymous> (/$bunfs/root/chunk-q8wzwtww.js:52:7744)\n  }\n})])" args=[] role=cli
timestamp=2026-10-16T05:59:34.209Z level=INFO run=d1751cac message="cli starting" version=2.0.29 channel=latest local=false args="[\"service\",\"set\",\"port\",\"65891\"]" role=cli
timestamp=2026-10-16T05:59:34.214Z level=ERROR run=d1751cac message="cli process failed" cause="Cause([Die(Error: Port must be between 1 and 65535)])" args="[\"service\",\"set\",\"port\",\"65891\"]" role=cli
timestamp=2026-10-16T05:59:42.297Z level=INFO run=4b451abb message="cli starting" version=2.0.29 channel=latest local=false args="[\"service\",\"set\",\"port\",\"64256\"]" role=cli
timestamp=2026-10-16T05:59:46.790Z level=INFO run=ac5519f6 message="cli starting" version=2.0.29 channel=latest local=false args=[] role=cli
timestamp=2026-10-16T05:59:46.857Z level=INFO run=ac5519f6 message="background service starting" reason=missing previousVersion=undefined role=cli
timestamp=2026-10-16T05:59:46.921Z level=INFO run=b7bff5f6 message="cli starting" version=2.0.29 channel=latest local=false args="[\"serve\",\"--service\"]" role=cli
timestamp=2026-10-16T05:59:51.988Z level=INFO run=9422340f message="cli starting" version=2.0.29 channel=latest local=false args="[\"serve\",\"--service\"]" role=cli
timestamp=2026-10-16T06:00:07.288Z level=ERROR run=9422340f message="cli process failed" cause="Cause([Fail(Error: Managed service port 64256 on 127.0.0.1 is already in use by another process. Configure another port with `opencode service set port <port>` and start the service again. (cause: ServeError (cause: Error: Failed to start server. Is port 64256 in use?)))])" args="[\"serve\",\"--service\"]" role=cli
timestamp=2026-10-16T06:01:46.911Z level=ERROR run=ac5519f6 message="cli process failed" cause="Cause([Fail(Error: Server process exited with code 1\nError: Managed service port 64256 on 127.0.0.1 is already in use by another process. Configure another port with `opencode service set port <port>` and start the service again.\n    at <anonymous> (/$bunfs/root/chunk-x6242730.js:2:8786) {\n  [cause]: ServeError: \n      at N (/$bunfs/root/chunk-q8wzwtww.js:52:7706)\n      at applyHandlers (node:events:64:20)\n      at emitError (node:events:44:27)\n      at emitListenErrorNextTick (node:_http_server:134:12)\n      at processTicksAndRejections (unknown:7:39) {\n    [cause]: Error: Failed to start server. Is port 64256 in use?\n        at serve (unknown)\n        at <anonymous> (node:_http_server:359:39)\n        at <anonymous> (node:_http_server:332:33)\n        at <anonymous> (/$bunfs/root/chunk-q8wzwtww.js:52:7744)\n  }\n})])" args=[] role=cli

Starting the background server using opencode serve does work though. So i think the issue is that TUI cannot attach to the background server and maybe tries to restart it? I don't think the issue is with the server itself based on this behaviour.

Plugins

None

OpenCode version

2.0.29

Steps to reproduce

  1. Install opencode 2.0.29
  2. Start opencode tui via opencode

Screenshot and/or share link

No response

Operating System

WSL Ubuntu 24.04.4 LTS

Terminal

Windows Terminal for opening WSL. WSL uses bash

Activity

  1. changed the title [-]Opencode TUI cannot be started in opencode v2[/-] [+]Opencode TUI cannot be started with opencode v2[/+] on Oct 16, 2026
  2. opencode-agent commented on Oct 16, 2026

    @opencode-agent
    Contributor

    Thanks for the detailed logs, they made this much easier to track down. I could reproduce the same failure on 2.0.29, and it still happens on the latest dev (f09eee5). In my case the cause was an HTTP proxy set in the environment.

    What happens:

    • The first background service starts and takes the port.
    • OpenCode then checks http://127.0.0.1:<port>, but because HTTP_PROXY/http_proxy is set and NO_PROXY isn't, that check goes through the proxy and never reaches the service.
    • After 5 s OpenCode starts a second service. That one fails with "port … already in use", and after 2 minutes that's the error you see.

    This matches your logs exactly, including the timing, and explains why opencode serve on its own works.

    Could you check whether proxy variables are set in your WSL shell? WSL can set them automatically when it copies the Windows proxy settings:

    env | grep -i proxy

    If they are, this should work around it for now:

    export NO_PROXY=127.0.0.1,localhost no_proxy=127.0.0.1,localhost
    opencode

    The script below reproduces it with an unreachable proxy.

    Related issues, most closely related first:

    Reproduction script (repro.sh)
    #!/usr/bin/env bash
    # Repro for #55973: with an HTTP proxy in the environment (as WSL mirrored/autoProxy
    # commonly sets), `opencode` can't start its background service. The first
    # `serve --service` binds the port, but the client's readiness probe of
    # http://127.0.0.1:<port> goes through the (unreachable) proxy, so after 5 s it
    # spawns a second contender, which fails with "port ... already in use", and the
    # CLI reports that error after ~2 minutes.
    #
    # Usage: ./repro.sh            (uses `opencode` from PATH, e.g. @opencode/cli@2.0.29)
    #        OC_DEV=/workspace/repo ./repro.sh   (runs the CLI from a source checkout)
    set -u
    export HOME=$(mktemp -d)
    cd "$HOME"
    if [ -n "${OC_DEV:-}" ]; then
      cd "$OC_DEV/packages/cli"  # so the spawned service child picks up bunfig preload
      OC=(bun --conditions=browser --preload="$OC_DEV/packages/tui/node_modules/@opentui/solid/scripts/preload.js" "$OC_DEV/packages/cli/src/index.ts")
    else
      OC=(opencode)
    fi
    PORT=${PORT:-49374}
    "${OC[@]}" service set port "$PORT" >/dev/null
    # A proxy that is not reachable; NO_PROXY is not set.
    export HTTP_PROXY=http://127.0.0.1:9 http_proxy=http://127.0.0.1:9 HTTPS_PROXY=http://127.0.0.1:9 https_proxy=http://127.0.0.1:9
    unset NO_PROXY no_proxy
    time timeout 170 "${OC[@]}" service start 2>&1 | head -5
    echo "--- log ---"
    grep -rh 'serve\\\|ERROR' "$HOME/.local/share/opencode/log/" | cut -c1-220
    # Workaround check: export NO_PROXY=127.0.0.1,localhost and it starts immediately.

    Run it: bash repro.sh

  3. DaniloMurer commented on Oct 16, 2026

    @DaniloMurer
    Author

    Yes the issue is with Proxy env variables. I had no NO_PROXY env variable set. After setting it to NO_PROXY=127.0.0.1 the TUI worked as expected

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