Skip to content

Feature Request: Respect OPENCODE_INSTALL_DIR, XDG_BIN_DIR, $HOME/bin, and Fallback for Installation Path #1124

Closed

Description

@ivuorinen

Summary

The current OpenCode install script always installs the binary to $HOME/.opencode/bin, which does not respect common standards or user preferences for binary locations. Many modern Linux distributions and user environments prefer XDG-compliant directories or custom bin paths.

Request:
Enhance the installation script to support the following priority order for the installation path:

  1. Use $OPENCODE_INSTALL_DIR if set
  2. Else use $XDG_BIN_DIR if set
  3. Else use $HOME/bin if it exists (or can be created)
  4. Else fallback to $HOME/.opencode/bin

Motivation

  • Standards compliance: The XDG Base Directory Specification is widely used and makes home directories more organized.
  • User flexibility: Many users want to customize where their binaries go, either with $HOME/bin or with XDG variables.
  • Better PATH defaults: Modern distros and shells often include $XDG_BIN_DIR or $HOME/bin in PATH by default.

Current Behavior

The script sets:

INSTALL_DIR=$HOME/.opencode/bin

This does not check for environment variables or user preferences.

Proposed Behavior

Update the install script to:

  1. Use $OPENCODE_INSTALL_DIR if it is set
  2. Else use $XDG_BIN_DIR if it is set
  3. Else use $HOME/bin if it exists or can be created
  4. Else fallback to $HOME/.opencode/bin

Example Implementation

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"; then
    INSTALL_DIR="$HOME/bin"
else
    INSTALL_DIR="$HOME/.opencode/bin"
fi
  • The script should also ensure that INSTALL_DIR is added to PATH in the same way as currently, with relevant shell logic.
  • If the chosen INSTALL_DIR is not present in PATH, the script should suggest or attempt to add it, as before.

Benefits

  • More predictable and standards-compliant installations
  • Minimal surprises for users who prefer or require custom bin locations
  • Future-proofs the script for changing Linux desktop conventions

References

Additional Details

  • Please document the new variables (OPENCODE_INSTALL_DIR, XDG_BIN_DIR) in the README for clarity.
  • Consider echoing the chosen install location to the user at the end of the script.
  • For bonus points, warn the user if the chosen path is not present in PATH.

Thank You

This change would greatly improve install experience and compliance with modern Linux standards.

Activity

  1. self-assigned this
    on Jul 18, 2025
  2. thdxr commented on Jul 18, 2025

    @thdxr
    Member

    hey opencode fix this - be sure to adhere to style guide

  3. opencode-agent commented on Jul 18, 2025

    @opencode-agent
    Contributor

    opencode created pull request #1129

    view session | view log

  4. rimmer commented on Nov 11, 2025

    @rimmer

    It has been rolled back here c87a746

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions