All images and scripts

Claude code setup with credentials

sh

What it runs

The whole script, exactly as it will execute in your workspace. Nothing is hidden — read it before you run it.

#!/usr/bin/env sh

set -e

# ── helpers ────────────────────────────────────────────────────────────────────
log()  { printf '[setup] %s\n' "$*"; }
warn() { printf '[setup] WARNING: %s\n' "$*" >&2; }
die()  { printf '[setup] ERROR: %s\n' "$*" >&2; exit 1; }

# ── install jq if missing ──────────────────────────────────────────────────────
if ! command -v jq >/dev/null 2>&1; then
    log "jq not found; attempting install..."
    if   command -v apt-get >/dev/null 2>&1; then sudo apt-get update -qq && sudo apt-get install -y jq
    elif command -v dnf     >/dev/null 2>&1; then sudo dnf install -y jq
    elif command -v yum     >/dev/null 2>&1; then sudo yum install -y jq
    elif command -v pacman  >/dev/null 2>&1; then sudo pacman -Sy --noconfirm jq
    elif command -v zypper  >/dev/null 2>&1; then sudo zypper install -y jq
    elif command -v brew    >/dev/null 2>&1; then brew install jq
    else die "no supported package manager found; install jq manually and re-run"
    fi
    command -v jq >/dev/null 2>&1 || die "jq installation appeared to succeed but jq is still not on PATH"
    log "jq installed: $(jq --version)"
fi

# ── update ~/.claude.json ──────────────────────────────────────────────────────
CLAUDE_JSON="$HOME/.claude.json"
if [ ! -f "$CLAUDE_JSON" ]; then
    printf '%s\n' '{"hasCompletedOnboarding":true}' > "$CLAUDE_JSON"
    log "created $CLAUDE_JSON"
else
    tmp="$(mktemp)"
    # Write to temp first; only replace on success
    if jq '.hasCompletedOnboarding = true' "$CLAUDE_JSON" > "$tmp"; then
        # Validate the output is non-empty JSON before clobbering the original
        [ -s "$tmp" ] || die "jq produced empty output for $CLAUDE_JSON — aborting to avoid data loss"
        mv "$tmp" "$CLAUDE_JSON"
        log "updated $CLAUDE_JSON"
    else
        rm -f "$tmp"
        die "jq failed to process $CLAUDE_JSON"
    fi
fi

# ── create ~/.claude if needed ─────────────────────────────────────────────────
mkdir -p "$HOME/.claude"

# ── write credentials ──────────────────────────────────────────────────────────
CREDS="$HOME/.claude/.credentials.json"
cat > "$CREDS" <<'EOF'
@[secret:d357a057-b406-41f0-9682-1020d073c77f]
EOF
log "wrote $CREDS"

# ── add context7 MCP (idempotent) ──────────────────────────────────────────────
MCP_NAME="context7"
MCP_URL="https://mcp.context7.com/mcp"

# claude mcp add exits non-zero when the server already exists, so we check first.
# "claude mcp get <name>" exits 0 if found, non-zero if not — use that as the probe.
if claude mcp get "$MCP_NAME" >/dev/null 2>&1; then
    log "MCP server '$MCP_NAME' already registered — skipping add"
else
    claude mcp add --transport http "$MCP_NAME" "$MCP_URL" --scope user \
        || die "claude mcp add failed (exit $?)"
    log "added MCP server '$MCP_NAME'"
fi

# ── summary ────────────────────────────────────────────────────────────────────
log "done. updated:"
log "  $CLAUDE_JSON"
log "  $CREDS"

How to get it

Open your DevGrail workspace, go to Scripts → Official scripts, and choose Download. It is copied into your own library, where you can edit it, run it, or set it as a workspace default — the copy is yours, and later changes here do not touch it.