#!/usr/bin/env bash # qbraid-code installer — Claude Code, powered by the qBraid AI gateway. # # curl -fsSL https://qbraid.com/code.sh | bash # # Claude models use the gateway's Anthropic-compatible surface. GPT models # use an on-demand loopback translation proxy. The double `v1` in # /api/v1/ai/v1/messages is deliberate because Claude Code appends # /v1/messages to ANTHROPIC_BASE_URL. # # Everything this writes lives in ~/.qbraid-code and ~/.local/bin. # Re-running is safe. set -euo pipefail GATEWAY_HOST="api-v2.qbraid.com" API_BASE="https://${GATEWAY_HOST}/api/v1" GATEWAY_URL="${API_BASE}/ai" MCP_NAME="qbraid" # Local translation proxy for the gateway's GPT models. Claude Code speaks the # Anthropic Messages API; the gateway serves GPT only on its OpenAI-compat # surface. CLIProxyAPI bridges the two on loopback. Port is qbraid-code's own — # claudeseek and other tools use neighbouring ports. PROXY_PORT_OVERRIDE="${QBRAID_CODE_PROXY_PORT:-}" PROXY_PORT="" PROXY_REPO="router-for-me/CLIProxyAPI" MCP_URL="https://mcp.qbraid.com/mcp" KEYS_URL="https://account.qbraid.com/account/api-keys" CLAUDE_RELEASES_URL="https://downloads.claude.ai/claude-code-releases" CLAUDE_MIN_VERSION="2.1.186" CLAUDE_TESTED_MAX="2.1.238" # Companion files are fetched from qbraid.com first. That is the whole point # of the proxy: on a campus network that blocks raw.githubusercontent.com, an # install that got this far would otherwise die on its last step. SITE_BASE="https://qbraid.com/code" RAW_BASE="https://raw.githubusercontent.com/qBraid/qbraid-code/main" GH_CONTENTS="/repos/qBraid/qbraid-code/contents" HOME_DIR="${QBRAID_CODE_HOME:-$HOME/.qbraid-code}" BIN_DIR="${QBRAID_CODE_BIN_DIR:-$HOME/.local/bin}" CLAUDE_DIR="$HOME/.claude" SETTINGS="$CLAUDE_DIR/settings.json" CLAUDE_JSON="$HOME/.claude.json" PROFILE="${QBRAID_CODE_PROFILE:-}" PROFILE_OPTION=0 UPDATE_KEY=0 while [ "$#" -gt 0 ]; do case "$1" in --global) printf 'error: --global was removed because project settings can exfiltrate its credential. Use qbraid-code.\n' >&2; exit 1 ;; --profile) [ "$#" -ge 2 ] || { printf 'error: --profile needs a name\n' >&2; exit 1; } PROFILE_OPTION=1; PROFILE="$2"; shift 2 ;; --profile=*) PROFILE_OPTION=1; PROFILE="${1#--profile=}"; shift ;; --update-key) UPDATE_KEY=1; shift ;; --help|-h) cat <<'EOF' qbraid-code installer --profile NAME create or update a named qBraid profile --update-key require a replacement key for an existing profile --global removed. Use the isolated qbraid-code wrapper. --help show this message Environment: QBRAID_API_KEY use this key instead of prompting QBRAID_CODE_MODEL use this model instead of prompting QBRAID_CODE_PROFILE_LABEL readable local account label QBRAID_CODE_CLAUDE_POLICY prompt, upgrade, fail, or continue QBRAID_CODE_HOME config directory (default ~/.qbraid-code) QBRAID_CODE_BIN_DIR install directory (default ~/.local/bin) EOF exit 0 ;; *) printf 'error: unknown option: %s\n' "$1" >&2; exit 1 ;; esac done [ "$PROFILE_OPTION" -eq 0 ] || [ -n "$PROFILE" ] || { printf 'error: invalid empty profile\n' >&2; exit 1; } shell_quote() { printf "'" printf '%s' "$1" | sed 's/'"'"'/'"'"'\\'"'"''"'"'/g' printf "'" } json_escape_value() { printf '%s' "$1" | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g' -e 's/ /\\t/g' } valid_profile_slug() { local LC_ALL=C case "${1:-}" in ''|[!A-Za-z0-9]*|*[!A-Za-z0-9._-]*) return 1 ;; esac [ "${#1}" -le 32 ] } sanitize_profile_label() { # sanitize_profile_label