opencode icon indicating copy to clipboard operation
opencode copied to clipboard

Unexpected directory "bin" found in ~/.opencode

Open geclos opened this issue 1 year ago • 6 comments

Can't start opencode, get this error, did something change recently? Yesterday was working fine. Installed using curl command in mac os.

geclos avatar Sep 26 '25 10:09 geclos

This issue might be a duplicate of existing issues. Please check:

  • #2643: Latest 0.9.9 opencode bin shows bun command - user reports opencode bin showing bun instead of opencode functionality
  • #2766: Opencode just hangs - user reports opencode hanging during startup, specifically during bun package installation step
  • #2765: I removed bundle.pem from user folder and now opencode is not running - user reports startup issues after modifying files in ~/.opencode directory

Feel free to ignore if none of these address your specific case.

github-actions[bot] avatar Sep 26 '25 10:09 github-actions[bot]

same

jflaflamme avatar Sep 26 '25 10:09 jflaflamme

Seems like the install script ignores the variables mentioned in the README:

README:

XDG_BIN_DIR=$HOME/.local/bin curl -fsSL https://opencode.ai/install | bash

vs. install script:

INSTALL_DIR=$HOME/.opencode/bin
mkdir -p "$INSTALL_DIR"

sigg3net avatar Sep 26 '25 10:09 sigg3net

Seems to be this commit:

https://github.com/sst/opencode/commit/c87a7469a006b789e7235e03f453bdd52464d9b4#diff-1e142e6277b12b7e1110478a24caee8f006a9349e86970c890203d6266209463L44-R46

# Determine installation directory with priority order
if [ -n "${OPENCODE_INSTALL_DIR:-}" ]; then
    INSTALL_DIR="$OPENCODE_INSTALL_DIR"
elif [ -n "${XDG_BIN_DIR:-}" ]; then
    INSTALL_DIR="$XDG_BIN_DIR"
elif [ -d "$HOME/bin" ] || mkdir -p "$HOME/bin" 2>/dev/null; then
    INSTALL_DIR="$HOME/bin"

Was changed to:

INSTALL_DIR=$HOME/.opencode/bin
mkdir -p "$INSTALL_DIR"

Workaround, download the script locally:

$ curl -o opencode_install.sh -fsSL https://opencode.ai/install

then change opencode_install.sh lines

INSTALL_DIR=$HOME/.opencode/bin
mkdir -p "$INSTALL_DIR"

to

# Determine installation directory with priority order
if [ -n "${OPENCODE_INSTALL_DIR:-}" ]; then
    INSTALL_DIR="$OPENCODE_INSTALL_DIR"
elif [ -n "${XDG_BIN_DIR:-}" ]; then
    INSTALL_DIR="$XDG_BIN_DIR"
elif [ -d "$HOME/bin" ] || mkdir -p "$HOME/bin" 2>/dev/null; then
    INSTALL_DIR="$HOME/bin"
else
    INSTALL_DIR=$HOME/.opencode/bin
fi
mkdir -p "$INSTALL_DIR"

then execute e.g.

$ chmod +x opencode_install.sh
$ OPENCODE_INSATLL_DIR="$HOME/.local/bin" ./opencode_install.sh

sigg3net avatar Sep 26 '25 10:09 sigg3net

@sigg3net You are describing a different issue, which has been with us some time already.

The problem is probably with this change: https://github.com/sst/opencode/commit/70310a37b323f1c55a73ed3391dd956f1e0ae0ce#diff-2ca52542d251bb69bf981f39dd51de9943a6c2cb4ee53d7799c83bbf322a0891R121

In ALLOWED_DIRS likely "bin" entry is missing:

  async function assertValid(dir: string) {
    const ALLOWED_DIRS = new Set(["agent", "command", "mode", "plugin"])

lgladysz avatar Sep 26 '25 12:09 lgladysz

The last release fixes it.

arsham avatar Sep 26 '25 12:09 arsham