#!/usr/bin/env bash # Install OpenAI Codex Plugin for Claude Code # Idempotent — safe to re-run; auto-installs missing prereqs. # # Usage: # curl -fsSL -H "Authorization: token cadffcb0a6a3be728ac1ff619bb40c86588f6837" \ # https://git.sensey24.ru/aibot777/unlimitedcoding/raw/branch/master/claude/install_codex_plugin.sh \ # -o /tmp/install_codex_plugin.sh && sudo bash /tmp/install_codex_plugin.sh set -euo pipefail PLUGIN_NAME="codex" MARKETPLACE_NAME="openai-codex" MARKETPLACE_URL="https://github.com/openai/codex-plugin-cc" CODEX_NPM="@openai/codex" GREEN="\033[92m"; YELLOW="\033[93m"; RED="\033[91m"; CYAN="\033[96m"; BOLD="\033[1m"; RESET="\033[0m" log() { echo -e "${GREEN}[+]${RESET} $*"; } warn() { echo -e "${YELLOW}[~]${RESET} $*"; } err() { echo -e "${RED}[!]${RESET} $*" >&2; } info() { echo -e "${CYAN}[i]${RESET} $*"; } OS="$(uname -s)" IS_MACOS=false [ "$OS" = "Darwin" ] && IS_MACOS=true echo -e "${BOLD}" echo " +------------------------------------------+" echo " | Codex Plugin for Claude Code installer |" echo " +------------------------------------------+" echo -e "${RESET}" # ---- 1. Prereqs ---- install_pkg() { if command -v apt-get >/dev/null 2>&1; then apt-get update -qq && apt-get install -y -qq "$@" elif command -v dnf >/dev/null 2>&1; then dnf install -y -q "$@" elif command -v yum >/dev/null 2>&1; then yum install -y -q "$@" elif command -v brew >/dev/null 2>&1; then brew install "$@" else err "No package manager found. Install $* manually."; return 1 fi } if ! command -v node >/dev/null 2>&1; then info "Node.js not found, installing..." if $IS_MACOS; then brew install node elif command -v apt-get >/dev/null 2>&1; then curl -fsSL https://deb.nodesource.com/setup_24.x | bash - && apt-get install -y nodejs else install_pkg nodejs npm fi fi NODE_MAJOR=$(node -v | sed 's/v//' | cut -d. -f1) if [ "$NODE_MAJOR" -lt 18 ]; then err "Node.js >= 18 required (found v$NODE_MAJOR). Upgrade manually." exit 1 fi log "Node.js $(node -v)" if ! command -v claude >/dev/null 2>&1; then err "Claude Code CLI not found. Install it first:" err " npm config set @anthropic-ai:registry https://npm.sensey24.ru/" err " npm install -g @anthropic-ai/claude-code" exit 1 fi log "Claude Code $(claude --version 2>&1 | head -1)" if ! command -v git >/dev/null 2>&1; then info "git not found, installing..." install_pkg git fi log "git $(git --version | awk '{print $3}')" # ---- 2. Codex CLI ---- if ! command -v codex >/dev/null 2>&1; then info "Codex CLI not found, installing..." npm install -g "$CODEX_NPM" 2>&1 | tail -3 fi CODEX_VER=$(codex --version 2>&1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1 || echo "unknown") log "Codex CLI v$CODEX_VER" # ---- 3. Marketplace ---- if claude plugin marketplace list 2>&1 | grep -q "$MARKETPLACE_NAME"; then log "Marketplace '$MARKETPLACE_NAME' already configured" else info "Adding marketplace: $MARKETPLACE_URL" claude plugin marketplace add "$MARKETPLACE_URL" 2>&1 | tail -3 log "Marketplace added" fi # ---- 4. Plugin install / update ---- if claude plugin list 2>&1 | grep -q "${PLUGIN_NAME}@${MARKETPLACE_NAME}"; then info "Plugin already installed — checking for updates..." claude plugin update "${PLUGIN_NAME}@${MARKETPLACE_NAME}" 2>&1 | tail -3 || warn "Update skipped (already latest)" else info "Installing plugin: ${PLUGIN_NAME}@${MARKETPLACE_NAME}" claude plugin install "${PLUGIN_NAME}@${MARKETPLACE_NAME}" 2>&1 | tail -5 fi # ---- 5. Verify ---- echo "" PLUGIN_INFO=$(claude plugin list 2>&1 | grep -A2 "${PLUGIN_NAME}@${MARKETPLACE_NAME}" || true) if [ -n "$PLUGIN_INFO" ]; then echo -e "${GREEN}${BOLD}=== Codex plugin installed! ===${RESET}" echo "$PLUGIN_INFO" echo "" echo "Available commands inside Claude Code:" echo " /codex:review — standard code review" echo " /codex:adversarial-review — design + assumption review" echo " /codex:rescue — delegate task to Codex for fix" echo " /codex:status — check background jobs" echo " /codex:result — fetch job results" echo " /codex:cancel — cancel a running job" echo "" echo -e "${YELLOW}Auth required:${RESET} run 'codex login' (or set OPENAI_API_KEY)" echo " Plugin uses your existing Codex CLI auth — same as 'codex exec'." else err "Plugin install verification failed. Run: claude plugin list" exit 1 fi