#!/bin/bash # Register AKOS in Claude Code WITHOUT touching existing settings: adds only the `akos` MCP server (user scope) and, # with --with-hooks, merges one SessionStart hook into ~/.claude/settings.json (backup written first, existing hooks kept). # AKOS_TOKEN=akos_… integrations/claude-code/install.sh [--url https://akos.spboucher.ai] [--scope user|project|local] [--with-hooks] [--uninstall] set -euo pipefail URL="${AKOS_URL:-https://akos.spboucher.ai}"; SCOPE="user"; HOOKS=0; UNINSTALL=0 while [ $# -gt 0 ]; do case "$1" in --url) URL="$2"; shift 2;; --scope) SCOPE="$2"; shift 2;; --with-hooks) HOOKS=1; shift;; --uninstall) UNINSTALL=1; shift;; *) echo "unknown arg $1"; exit 2;; esac; done command -v claude >/dev/null || { echo "claude CLI not found"; exit 1; } HERE="$(cd "$(dirname "$0")" && pwd)" if [ "$UNINSTALL" = 1 ]; then claude mcp remove akos -s "$SCOPE" 2>/dev/null || true python3 "$HERE/merge_hooks.py" --remove echo "akos removed from Claude Code ($SCOPE scope); hooks removed if present"; exit 0 fi TOKEN="${AKOS_TOKEN:-$(python3 -c 'import json,os;p=os.path.expanduser(os.environ.get("AKOS_CONFIG","~/.config/akos/config.json"));print(json.load(open(p)).get("token","")) if os.path.exists(p) else print("")')}" [ -n "$TOKEN" ] || { echo "AKOS_TOKEN not set and no ~/.config/akos/config.json — run 'akos login' first"; exit 1; } curl -fsS -m 15 "$URL/api/v1/health" >/dev/null || { echo "AKOS not reachable at $URL"; exit 1; } claude mcp remove akos -s "$SCOPE" >/dev/null 2>&1 || true claude mcp add --transport http akos "$URL/mcp" --header "Authorization: Bearer $TOKEN" -s "$SCOPE" >/dev/null echo "MCP server 'akos' registered ($SCOPE scope) → $URL/mcp" if [ "$HOOKS" = 1 ]; then python3 "$HERE/merge_hooks.py" --add "$HERE/session_start.sh"; fi claude mcp get akos | head -5 echo "Verify inside a session: /mcp → akos should be connected; tools: search_knowledge, inspect_api, discover_api, execute_api, …"