Skip to content

Instantly share code, notes, and snippets.

@JavaGT
Created June 11, 2026 21:50
Show Gist options
  • Select an option

  • Save JavaGT/5e76c5880f771cd01a969edd8c454d56 to your computer and use it in GitHub Desktop.

Select an option

Save JavaGT/5e76c5880f771cd01a969edd8c454d56 to your computer and use it in GitHub Desktop.
Create a second opencode instance with a separate account
#!/bin/bash
set -euo pipefail
# setup-opencode2.sh
# Creates a second opencode instance that shares config but uses a separate account.
#
# Usage:
# bash setup-opencode2.sh
#
# Then:
# opencode2 providers login # log in with second account
# opencode2 # use second instance
OPENCODE_BIN="$(command -v opencode)"
if [ -z "$OPENCODE_BIN" ]; then
echo "Error: opencode not found on PATH. Install opencode first."
exit 1
fi
OPENCODE_BIN="$(realpath "$OPENCODE_BIN")"
SCRIPT_PATH="${XDG_DATA_HOME:-$HOME/.local/share}/opencode2"
mkdir -p "$SCRIPT_PATH"
WRAPPER="${HOME}/.local/bin/opencode2"
mkdir -p "$(dirname "$WRAPPER")"
cat > "$WRAPPER" << 'WRAPPER'
#!/bin/bash
export XDG_DATA_HOME="$HOME/.local/share/opencode2"
mkdir -p "$XDG_DATA_HOME"
exec /Users/user/.opencode/bin/opencode "$@"
WRAPPER
# Fix the hardcoded path to the actual opencode binary
sed -i '' "s|/Users/user/.opencode/bin/opencode|$OPENCODE_BIN|" "$WRAPPER"
chmod +x "$WRAPPER"
echo "Created $WRAPPER"
echo ""
echo "Next steps:"
echo " 1. opencode2 providers login # log in with second account"
echo " 2. opencode2 # use second instance"
echo ""
echo "Both instances share config (~/.config/opencode/) but keep separate accounts."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment