opencode icon indicating copy to clipboard operation
opencode copied to clipboard

fix: respect install directory priority as documented in README

Open grgong opened this issue 3 months ago • 3 comments

Summary

Fixes the install script to respect the installation directory priority order as documented in the README.

Problem

The install script was hardcoding INSTALL_DIR=$HOME/.opencode/bin on line 68-69, completely ignoring the environment variables documented in the README:

  1. $OPENCODE_INSTALL_DIR - Custom installation directory
  2. $XDG_BIN_DIR - XDG Base Directory Specification compliant path
  3. $HOME/bin - Standard user binary directory (if exists or can be created)
  4. $HOME/.opencode/bin - Default fallback

Solution

This PR implements the documented priority order with proper validation:

  • Checks $OPENCODE_INSTALL_DIR first (highest priority)
  • Falls back to $XDG_BIN_DIR if not set
  • Falls back to $HOME/bin if it exists or can be created
  • Falls back to $HOME/.opencode/bin as final default

Additional Improvements

  • Directory creation validation: Ensures the installation directory can be created, with clear error messages if it fails
  • Write permission check: Verifies the directory is writable before proceeding with installation
  • Better error messages: Informs users to use OPENCODE_INSTALL_DIR if default paths fail

Testing

  • Verified bash syntax is valid (bash -n install)
  • Tested priority logic with unit tests
  • Tested with --help flag to ensure no regressions
  • All tests pass ✓

Impact

Users can now properly customize their installation directory as documented, and will receive clear error messages if there are permission issues.

Fixes #7675

grgong avatar Jan 05 '26 20:01 grgong

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found.

The searches returned only the current PR (#6993) and one unrelated PR about a TUI layout system. This indicates that:

  • PR #6993 appears to be the only PR addressing the install directory priority issue
  • There are no other open PRs fixing the OPENCODE_INSTALL_DIR, XDG_BIN_DIR, or installation script environment variable handling

This PR is ready to proceed without concerns about duplicates.

github-actions[bot] avatar Jan 05 '26 20:01 github-actions[bot]

I tried OPENCODE_INSTALL_DIR=$HOME/.local/bin curl -fsSL https://opencode.ai/install | env -u VERSION bash, but it still installed into $HOME/.opencode/bin/ This is nice. BTW, I really hate it when someone touches my ~/.bashrc.

alzee avatar Jan 09 '26 13:01 alzee

Please merge this, guys! 🙏

levifig avatar Jan 13 '26 21:01 levifig