Skip to content

Cant start opencode. #6211

Closed
Closed

Description

@mattiasmicu

Description

Today when i wanted to continue on a project of mine, i could not start opencode for some reason cause of bun i think. i am not sure if its opencodes fault or bun. this is what i got: mattias@Mattiass-MacBook-Pro Beam % arc
1855 | })
1856 | return result
1857 | }
1858 |
1859 | export function listen(opts: { port: number; hostname: string }) {
1860 | const server = Bun.serve({
^
error: Failed to start server. Is port 0 in use?
syscall: "listen",
errno: 0,
code: "EADDRINUSE"

  at listen (src/server/server.ts:1860:24)
  at server (src/cli/cmd/tui/worker.ts:36:23)
  at server (src/cli/cmd/tui/worker.ts:33:16)
  at <anonymous> (src/util/rpc.ts:10:41)
  at onmessage (src/util/rpc.ts:7:24)

OpenCode version

1.0.203

Steps to reproduce

  1. go in to any directory
  2. type start opencode
  3. and get the error

Screenshot and/or share link

Image

Operating System

MacOS 21.1

Terminal

The cursor terminal and the default terminal that comes with macos

Activity

  1. added
    perfIndicates a performance issue or need for optimization
    on Dec 26, 2025
  2. rekram1-node commented on Dec 26, 2025

    @rekram1-node
    Contributor

    What if you try running like:

    opencode --port 5811 or something that'd be free?

  3. removed
    perfIndicates a performance issue or need for optimization
    on Dec 26, 2025
  4. mattiasmicu commented on Dec 26, 2025

    @mattiasmicu
    Author

    Still doesnt work even if i use other ports that are free on my system:

    mattias@Mattiass-MacBook-Pro Beam % opencode --
    port 5811
    2073 | })
    2074 | return result
    2075 | }
    2076 |
    2077 | export function listen(opts: { port: number; hostname: string }) {
    2078 | const server = Bun.serve({
    ^
    error: Failed to start server. Is port 5811 in use?
    syscall: "listen",
    errno: 0,
    code: "EADDRINUSE"

      at listen (src/server/server.ts:2078:24)
      at server (src/cli/cmd/tui/worker.ts:34:23)
      at server (src/cli/cmd/tui/worker.ts:31:16)
      at <anonymous> (src/util/rpc.ts:10:41)
      at onmessage (src/util/rpc.ts:7:24)
    
  5. rekram1-node commented on Dec 26, 2025

    @rekram1-node
    Contributor

    Do u have too many open files or something?

    maybe try:

    pkill -f opencode

    And then try again

  6. mattiasmicu commented on Dec 26, 2025

    @mattiasmicu
    Author

    i do not have many files open. i recently restarted my system and tried again but it still did not work.

    mattias@Mattiass-MacBook-Pro Beam % pkill -f opencode
    mattias@Mattiass-MacBook-Pro Beam % opencode
    2073 | })
    2074 | return result
    2075 | }
    2076 |
    2077 | export function listen(opts: { port: number; hostname: string }) {
    2078 | const server = Bun.serve({
    ^
    error: Failed to start server. Is port 0 in use?
    syscall: "listen",
    errno: 0,
    code: "EADDRINUSE"

      at listen (src/server/server.ts:2078:24)
      at server (src/cli/cmd/tui/worker.ts:34:23)
      at server (src/cli/cmd/tui/worker.ts:31:16)
      at <anonymous> (src/util/rpc.ts:10:41)
      at onmessage (src/util/rpc.ts:7:24)
    
  7. anntnzrb commented on Dec 26, 2025

    @anntnzrb
    Contributor

    This looks like corrupted state rather than an actual port conflict (errno: 0 is unusual). Try these in order:

    1. Clear opencode state directories:
    rm -rf ~/Library/Application\ Support/opencode
    rm -rf ~/Library/Caches/opencode
    rm -rf ~/.local/state/opencode
    1. Clear Bun cache:
    rm -rf ~/.bun/install/cache
    1. Reinstall opencode:
    curl -fsSL https://opencode.ai/install | bash

    Also check if any firewall/security software (Little Snitch, Lulu, etc.) might be blocking socket creation.

    Let us know if that helps!

  8. mattiasmicu commented on Dec 26, 2025

    @mattiasmicu
    Author

    i have tried EVERY thing that you have listed there and still i am getting the same error as before.

  9. anntnzrb commented on Dec 26, 2025

    @anntnzrb
    Contributor

    A few more things to check:

    1. What Bun version is bundled?
    bun --version
    1. Check file permissions on opencode binary:
    ls -la ~/.local/bin/opencode
    ls -la ~/.opencode/bin/
    1. Test if Bun can bind to a socket at all (create a temp file and run):
    echo "Bun.serve({ port: 9999, fetch: () => new Response(\"ok\") }); console.log(\"works\")" | bun run -
    1. Try running opencode with sudo (just to rule out permission issues):
    sudo opencode

    The errno: 0 is very unusual — it might mean Bun is misreporting an EACCES (permission denied) as EADDRINUSE.

  10. mattiasmicu commented on Dec 26, 2025

    @mattiasmicu
    Author

    Hello, thanks for the reply but i have ran all of your commands now and i will paste them bellow: mattias@Mattiass-MacBook-Pro Beam % bun --version
    1.3.3
    mattias@Mattiass-MacBook-Pro Beam % ls -la ~/.local/bin/opencode
    ls -la ~/.opencode/bin/
    ls: /Users/mattias/.local/bin/opencode: No such file or directory
    total 186592
    drwxr-xr-x@ 3 mattias staff 96 Dec 26 18:36 .
    drwxr-xr-x@ 7 mattias staff 224 Dec 21 23:04 ..
    -rwxr-xr-x@ 1 mattias staff 95534832 Dec 26 05:08 opencode
    mattias@Mattiass-MacBook-Pro Beam % echo "Bun.serve({ port: 9999, fetch: () => new Response("ok") }); console.log("works")" | bun run -
    works
    ^C
    mattias@Mattiass-MacBook-Pro Beam % That command just hangs
    zsh: command not found: That
    mattias@Mattiass-MacBook-Pro Beam % sudo opencode
    Password:
    2073 | })
    2074 | return result
    2075 | }
    2076 |
    2077 | export function listen(opts: { port: number; hostname: string }) {
    2078 | const server = Bun.serve({
    ^
    error: Failed to start server. Is port 0 in use?
    syscall: "listen",
    errno: 0,
    code: "EADDRINUSE"

      at listen (src/server/server.ts:2078:24)
      at server (src/cli/cmd/tui/worker.ts:34:23)
      at server (src/cli/cmd/tui/worker.ts:31:16)
      at <anonymous> (src/util/rpc.ts:10:41)
      at onmessage (src/util/rpc.ts:7:24)
    

    ^C%
    mattias@Mattiass-MacBook-Pro Beam %

  11. anntnzrb commented on Dec 26, 2025

    @anntnzrb
    Contributor

    Good news: your system Bun works fine (the test printed "works"). The issue is specific to opencode's bundled runtime.

    A few more diagnostics:

    1. Check exact macOS version: (you mentioned 21.1 - that doesnt exist afaik??)
    sw_vers
    1. Check bundled opencode version:
    ~/.opencode/bin/opencode --version
    1. Try a completely clean reinstall (backup first):
    mv ~/.opencode ~/.opencode.bak
    curl -fsSL https://opencode.ai/install | bash
    1. Alternative: install via npm (uses system Bun instead of bundled):
    npm i -g opencode-ai

    If npm install works but curl doesn't, the bundled Bun binary might be incompatible with your macOS version.

  12. mattiasmicu commented on Dec 26, 2025

    @mattiasmicu
    Author

    ok i have ran you commands again. but macos 21.1 exists but its also called macos Tahoe.

    mattias@Mattiass-MacBook-Pro Beam % sw_vers
    ProductName: macOS
    ProductVersion: 26.1
    BuildVersion: 25B78
    mattias@Mattiass-MacBook-Pro Beam % ~/.opencode/bin/opencode --version
    1.0.203
    mattias@Mattiass-MacBook-Pro Beam % mv ~/.opencode ~/.opencode.bak
    curl -fsSL https://opencode.ai/install | bash
    Installed version: .

    Installing opencode version: 1.0.203
    ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 100%

                                 ▄     
    

    █▀▀█ █▀▀█ █▀▀█ █▀▀▄ █▀▀▀ █▀▀█ █▀▀█ █▀▀█
    █░░█ █░░█ █▀▀▀ █░░█ █░░░ █░░█ █░░█ █▀▀▀
    ▀▀▀▀ █▀▀▀ ▀▀▀▀ ▀ ▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀▀

    OpenCode includes free models, to start:

    cd # Open directory
    opencode # Run command

    For more information visit https://opencode.ai/docs

    mattias@Mattiass-MacBook-Pro Beam % npm i -g opencode-ai

    changed 2 packages in 3s
    npm notice
    npm notice New major version of npm available! 10.8.2 -> 11.7.0
    npm notice Changelog: https://github.com/npm/cli/releases/tag/v11.7.0
    npm notice To update run: npm install -g npm@11.7.0
    npm notice
    mattias@Mattiass-MacBook-Pro Beam % opencode
    2073 | })
    2074 | return result
    2075 | }
    2076 |
    2077 | export function listen(opts: { port: number; hostname: string }) {
    2078 | const server = Bun.serve({
    ^
    error: Failed to start server. Is port 0 in use?
    syscall: "listen",
    errno: 0,
    code: "EADDRINUSE"

      at listen (src/server/server.ts:2078:24)
      at server (src/cli/cmd/tui/worker.ts:34:23)
      at server (src/cli/cmd/tui/worker.ts:31:16)
      at <anonymous> (src/util/rpc.ts:10:41)
      at onmessage (src/util/rpc.ts:7:24)
    

    ^C%
    mattias@Mattiass-MacBook-Pro Beam %

  13. anntnzrb commented on Dec 26, 2025

    @anntnzrb
    Contributor

    Since system Bun works but opencode fails, let's see what's happening on your system:

    1. Check listening ports:
    netstat -an | grep LISTEN
    1. Check file descriptor limits:
    ulimit -n
    1. Check for zombie opencode processes:
    ps aux | grep -i opencode
    1. Try the spawn command directly:
    ~/.opencode/bin/opencode spawn --port 9999

    Also — do you have any VPN, antivirus, or security software running (Cisco AnyConnect, Little Snitch, etc.)?

  14. mattiasmicu commented on Dec 26, 2025

    @mattiasmicu
    Author

    Sorry for the wait i was away but here it is: mattias@Mattiass-MacBook-Pro Beam % netstat -an | grep LISTEN
    tcp6 0 0 *.54907 . LISTEN
    tcp4 0 0 *.54907 . LISTEN
    tcp46 0 0 *.58987 . LISTEN
    tcp46 0 0 *.3283 . LISTEN
    tcp6 0 0 *.5000 . LISTEN
    tcp4 0 0 *.5000 . LISTEN
    tcp6 0 0 *.7000 . LISTEN
    tcp4 0 0 *.7000 . LISTEN
    tcp46 0 0 *.58986 . LISTEN
    tcp4 0 0 *.88 . LISTEN
    tcp6 0 0 *.88 . LISTEN
    tcp6 0 0 ::1.8021 . LISTEN
    tcp4 0 0 *.5900 . LISTEN
    tcp6 0 0 *.5900 . LISTEN
    tcp4 0 0 *.22 . LISTEN
    tcp6 0 0 *.22 . LISTEN
    mattias@Mattiass-MacBook-Pro Beam % ulimit -n
    1048575
    mattias@Mattiass-MacBook-Pro Beam % ps aux | grep -i opencode
    mattias 56543 0.0 0.0 435300064 1296 s001 S+ 7:34PM 0:00.00 grep -i opencode
    mattias@Mattiass-MacBook-Pro Beam % ~/.opencode/bin/opencode spawn --port 9999
    Error: Unexpected error, check log file at /Users/mattias/.local/share/opencode/log/2025-12-26T183500.log for more details

    error: Failed to start server. Is port 9999 in use?
    syscall: "listen",
    errno: 0,
    code: "EADDRINUSE"

      at serve (unknown:1:1)
      at src/cli/cmd/tui/spawn.ts:27:27
      at handler (src/cli/cmd/tui/spawn.ts:25:19)
      at ../../node_modules/.bun/yargs@18.0.0/node_modules/yargs/build/lib/command.js:245:54
      at processTicksAndRejections (native:7:39)
    

    mattias@Mattiass-MacBook-Pro Beam %

  15. anntnzrb commented on Dec 26, 2025

    @anntnzrb
    Contributor

    The error is happening inside Bun's native serve function (at serve (unknown:1:1)), not opencode itself. Port 9999 isn't in use, so this looks like a Bun bug on macOS 26.

    Can you:

    1. Share the log file contents:
    cat /Users/mattias/.local/share/opencode/log/2025-12-26T183500.log
    1. Try upgrading Bun:
    bun upgrade
    1. Then retry opencode:
    opencode
  16. mattiasmicu commented on Dec 26, 2025

    @mattiasmicu
    Author

    Ok. But something is weird cause it worked before but just not now: mattias@Mattiass-MacBook-Pro Beam % cat /Users/mattias/.local/share/opencode/log/2025-12-26T183500.log
    INFO 2025-12-26T18:35:00 +630ms service=default version=1.0.203 args=["spawn","--port","9999"] opencode
    INFO 2025-12-26T18:35:00 +0ms service=config path=/Users/mattias/.config/opencode/config.json loading
    ERROR 2025-12-26T18:35:00 +8ms service=default name=Error message=Failed to start server. Is port 9999 in use? stack=Error: Failed to start server. Is port 9999 in use?
    at serve (unknown)
    at (src/cli/cmd/tui/spawn.ts:27:27)
    at handler (src/cli/cmd/tui/spawn.ts:25:19)
    at (../../node_modules/.bun/yargs@18.0.0/node_modules/yargs/build/lib/command.js:245:54)
    at processTicksAndRejections (native:7:39) fatal
    mattias@Mattiass-MacBook-Pro Beam % bun upgrade
    Bun v1.3.5 is out! You're on v1.3.3
    [2.43s] Upgraded.

    Welcome to Bun v1.3.5!

    What's new in Bun v1.3.5:

    https://bun.com/blog/release-notes/bun-v1.3.5
    

    Report any bugs:

    https://github.com/oven-sh/bun/issues
    

    Commit log:

    https://github.com/oven-sh/bun/compare/bun-v1.3.3...bun-v1.3.5
    

    mattias@Mattiass-MacBook-Pro Beam % opencode
    2073 | })
    2074 | return result
    2075 | }
    2076 |
    2077 | export function listen(opts: { port: number; hostname: string }) {
    2078 | const server = Bun.serve({
    ^
    error: Failed to start server. Is port 0 in use?
    syscall: "listen",
    errno: 0,
    code: "EADDRINUSE"

      at listen (src/server/server.ts:2078:24)
      at server (src/cli/cmd/tui/worker.ts:34:23)
      at server (src/cli/cmd/tui/worker.ts:31:16)
      at <anonymous> (src/util/rpc.ts:10:41)
      at onmessage (src/util/rpc.ts:7:24)
    

    ^C%
    mattias@Mattiass-MacBook-Pro Beam %

  17. rekram1-node commented on Dec 26, 2025

    @rekram1-node
    Contributor

    btw your local bun version shoudl have nothing to do w/ opencode, opencode has bun built into it so unless u are messing w/ bun env vars or special configs u shouldnt need to run bun upgrade ever (or even have it installed!)

  18. mattiasmicu commented on Dec 26, 2025

    @mattiasmicu
    Author

    then what do i do?

  19. mattiasmicu commented on Dec 26, 2025

    @mattiasmicu
    Author

    and i have not messed with anything

  20. mattiasmicu commented on Dec 26, 2025

    @mattiasmicu
    Author

    I have found a fix. I had do update my device from 21.1 to 21.2. But thanks for helping!

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions