spawn/local/claude.sh
A 55d5c123f7
fix: Improve UX for local cloud quick-start and env var messaging (#385)
- Fix cmdCloudInfo quick-start showing "none" as a command for local cloud
- Always show OPENROUTER_API_KEY in cloud quick-start (needed for all agents)
- Update local scripts to explicitly say "Appending environment variables to ~/.zshrc"
- Update local README with spawn CLI usage and "What It Does" section
- Add 3 tests for quick-start auth display (none auth, env var auth)

Agent: ux-engineer

Co-authored-by: A <6723574+louisgv@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-11 01:02:45 -08:00

76 lines
2.2 KiB
Bash

#!/bin/bash
set -eo pipefail
# Source common functions - try local file first, fall back to remote
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" 2>/dev/null && pwd)"
if [[ -f "${SCRIPT_DIR}/lib/common.sh" ]]; then
source "${SCRIPT_DIR}/lib/common.sh"
else
eval "$(curl -fsSL https://raw.githubusercontent.com/OpenRouterTeam/spawn/main/local/lib/common.sh)"
fi
log_info "Claude Code on local machine"
echo ""
# 1. Ensure local prerequisites
ensure_local_ready
# 2. Install Claude Code if not already installed
if command -v claude &>/dev/null; then
log_info "Claude Code already installed"
else
log_warn "Installing Claude Code..."
curl -fsSL https://claude.ai/install.sh | bash
export PATH="${HOME}/.local/bin:${PATH}"
fi
# Verify installation
if ! command -v claude &>/dev/null; then
log_error "Claude Code installation failed"
log_error "The 'claude' command is not available"
log_error "Try installing manually: curl -fsSL https://claude.ai/install.sh | bash"
exit 1
fi
log_info "Claude Code installation verified"
# 3. Get OpenRouter API key
echo ""
if [[ -n "${OPENROUTER_API_KEY:-}" ]]; then
log_info "Using OpenRouter API key from environment"
else
OPENROUTER_API_KEY=$(get_openrouter_api_key_oauth 5180)
fi
# 4. Inject environment variables
log_warn "Appending environment variables to ~/.zshrc..."
inject_env_vars_local upload_file run_server \
"OPENROUTER_API_KEY=${OPENROUTER_API_KEY}" \
"ANTHROPIC_BASE_URL=https://openrouter.ai/api" \
"ANTHROPIC_AUTH_TOKEN=${OPENROUTER_API_KEY}" \
"ANTHROPIC_API_KEY=" \
"CLAUDE_CODE_SKIP_ONBOARDING=1" \
"CLAUDE_CODE_ENABLE_TELEMETRY=0"
# 5. Configure Claude Code settings
setup_claude_code_config "${OPENROUTER_API_KEY}" \
"upload_file" \
"run_server"
echo ""
log_info "Local setup completed successfully!"
echo ""
# 6. Start Claude Code
if [[ -n "${SPAWN_PROMPT:-}" ]]; then
log_warn "Executing Claude Code with prompt..."
export PATH="${HOME}/.local/bin:${PATH}"
source ~/.zshrc 2>/dev/null || true
claude -p "${SPAWN_PROMPT}"
else
log_warn "Starting Claude Code..."
sleep 1
clear 2>/dev/null || true
export PATH="${HOME}/.local/bin:${PATH}"
source ~/.zshrc 2>/dev/null || true
exec claude
fi