Enhance install-claude-code.sh with provider switching and coding-helper

Major Features Added:
- Provider Switching: Detect current API provider (Anthropic/Z.AI) and offer switching
- API Key Update: Easy update of existing API keys without reinstalling
- Z.AI Coding-Helper Integration: Optional installation of @z_ai/coding-helper

Provider Detection:
- Detects Z.AI by checking for dashscope-intl.aliyuncs.com URL
- Detects Anthropic by checking for anthropic.com or ANTHROPIC_API_KEY
- Shows current provider and API key (masked) when script runs

Provider Switching Options:
1. Switch to Z.AI (GLM models: glm-4.5-air, glm-4.7)
2. Switch to Anthropic (Official Claude models)
3. Update API key only (keep current provider)
4. Skip configuration

Z.AI Coding-Helper Addons:
- Interactive wizard for easy setup
- Multi-tool management (Claude Code, OpenCode, Crush, Factory Droid)
- MCP service configuration
- API key management for Global and China plans
- Bilingual interface (English/Chinese)
- Automatic tool detection and installation
- Configuration backup and sync

Configuration Management:
- Automatic backup of settings.json before changes
- Smart merging of existing configurations
- Proper model switching (GLM ↔ Claude models)
- Base URL configuration for Z.AI

Enhanced Banner:
- Shows all three main features (Z.AI, Provider Switching, Coding-Helper)

README Updates:
- Documented new features in install-claude-code.sh section
- Added provider switching workflow explanation
- Listed coding-helper addon features
This commit is contained in:
uroma
2026-01-22 16:09:22 +00:00
Unverified
parent ddd42d0063
commit 2ad21eb5d1
2 changed files with 474 additions and 59 deletions

View File

@@ -180,26 +180,45 @@ curl -fsSL https://github.rommark.dev/admin/SuperCharged-Claude-Code-Upgrade/raw
``` ```
### install-claude-code.sh - Claude Code + Z.AI Installer ### install-claude-code.sh - Claude Code + Z.AI Installer
Installs Claude Code and configures Z.AI GLM models. Installs Claude Code and configures Z.AI GLM models or Anthropic API.
**New Features:**
- 🔀 **Provider Switching** - Switch between Anthropic and Z.AI APIs
- 🔑 **API Key Update** - Update existing API keys easily
- 🧩 **Coding-Helper Addons** - Optional Z.AI coding-helper installation
| Option | Description | | Option | Description |
|--------|-------------| |--------|-------------|
| `--auto` (default) | Automated installation with API key prompt | | `--auto` (default) | Automated installation with provider selection |
| `--manual` | Show manual installation steps only | | `--manual` | Show manual installation steps only |
| `--skip-install` | Skip Claude Code install, configure API only | | `--skip-install` | Skip Claude Code install, configure API only |
**One-liners:** **One-liners:**
```bash ```bash
# Auto install with API prompt # Auto install with provider selection
curl -fsSL https://github.rommark.dev/admin/SuperCharged-Claude-Code-Upgrade/raw/main/install-claude-code.sh | bash curl -fsSL https://github.rommark.dev/admin/SuperCharged-Claude-Code-Upgrade/raw/main/install-claude-code.sh | bash
# Show manual instructions # Show manual instructions
curl -fsSL https://github.rommark.dev/admin/SuperCharged-Claude-Code-Upgrade/raw/main/install-claude-code.sh | bash -s -- --manual curl -fsSL https://github.rommark.dev/admin/SuperCharged-Claude-Code-Upgrade/raw/main/install-claude-code.sh | bash -s -- --manual
# Configure API only # Configure API only (skip Claude Code install)
curl -fsSL https://github.rommark.dev/admin/SuperCharged-Claude-Code-Upgrade/raw/main/install-claude-code.sh | bash -s -- --skip-install curl -fsSL https://github.rommark.dev/admin/SuperCharged-Claude-Code-Upgrade/raw/main/install-claude-code.sh | bash -s -- --skip-install
``` ```
**Provider Switching:**
If Claude Code is already installed, the script will:
1. Detect your current API provider (Anthropic or Z.AI)
2. Offer to switch between providers
3. Allow you to update your API key
4. Optionally install Z.AI coding-helper addons
**Z.AI Coding-Helper Features:**
- Interactive wizard for easy setup
- Multi-tool management (Claude Code, OpenCode, etc.)
- MCP service configuration
- API key management for Global and China plans
- Bilingual interface (English/Chinese)
--- ---
## 🔧 Claude Code Installation Details ## 🔧 Claude Code Installation Details

View File

@@ -8,8 +8,10 @@
# Features: # Features:
# - Automated Claude Code installation via npm # - Automated Claude Code installation via npm
# - Z.AI API configuration (GLM models) # - Z.AI API configuration (GLM models)
# - Anthropic/Z.AI provider switching
# - API key update functionality
# - Z.AI coding-helper addon installation
# - Manual configuration instructions # - Manual configuration instructions
# - Model configuration for glm-4.5-air, glm-4.7
# #
# Usage: ./install-claude-code.sh [options] # Usage: ./install-claude-code.sh [options]
# --auto Automatic installation with API key prompt # --auto Automatic installation with API key prompt
@@ -31,6 +33,7 @@ NC='\033[0m' # No Color
# Claude config directory # Claude config directory
CLAUDE_DIR="${HOME}/.claude" CLAUDE_DIR="${HOME}/.claude"
SETTINGS_FILE="$CLAUDE_DIR/settings.json"
# Flags # Flags
AUTO_MODE=true AUTO_MODE=true
@@ -73,8 +76,10 @@ print_banner() {
║ ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═════╝ ║ ║ ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═════╝ ║
║ ║ ║ ║
║ + Z.AI API Integration (GLM Models) ║ + Z.AI API Integration (GLM Models)
║ + Provider Switching ║
║ + Coding-Helper Addons ║
║ ║ ║ ║
║ Installation Script Enhanced Installation Script ║
║ ║ ║ ║
╚═══════════════════════════════════════════════════════════════╝ ╚═══════════════════════════════════════════════════════════════╝
EOF EOF
@@ -113,6 +118,14 @@ check_nodejs() {
log_success "Node.js $(node -v) found" log_success "Node.js $(node -v) found"
} }
check_claude_code_installed() {
if command -v claude &> /dev/null; then
return 0
else
return 1
fi
}
install_claude_code() { install_claude_code() {
if [ "$SKIP_INSTALL" = true ]; then if [ "$SKIP_INSTALL" = true ]; then
log_info "Skipping Claude Code installation (--skip-install flag)" log_info "Skipping Claude Code installation (--skip-install flag)"
@@ -121,7 +134,7 @@ install_claude_code() {
log_step "Installing Claude Code..." log_step "Installing Claude Code..."
if command -v claude &> /dev/null; then if check_claude_code_installed; then
local current_version=$(claude --version 2>/dev/null | head -1 || echo "unknown") local current_version=$(claude --version 2>/dev/null | head -1 || echo "unknown")
log_info "Claude Code already installed: $current_version" log_info "Claude Code already installed: $current_version"
echo "" echo ""
@@ -142,7 +155,104 @@ install_claude_code() {
claude --version claude --version
} }
get_zai_api_key() { detect_current_provider() {
if [ -f "$SETTINGS_FILE" ]; then
if grep -q "dashscope-intl.aliyuncs.com" "$SETTINGS_FILE" 2>/dev/null; then
echo "zai"
elif grep -q "anthropic.com" "$SETTINGS_FILE" 2>/dev/null || \
grep -q "ANTHROPIC_API_KEY" "$SETTINGS_FILE" 2>/dev/null; then
echo "anthropic"
else
echo "unknown"
fi
else
echo "none"
fi
}
get_current_api_key() {
if [ -f "$SETTINGS_FILE" ]; then
# Try to extract API key using various methods
if command -v python3 &> /dev/null; then
python3 -c "
import json
import sys
try:
with open('$SETTINGS_FILE', 'r') as f:
settings = json.load(f)
key = settings.get('env', {}).get('ANTHROPIC_API_KEY', '')
if key:
print(key)
except:
pass
" 2>/dev/null
fi
fi
}
switch_provider() {
local current_provider=$(detect_current_provider)
local current_api_key=$(get_current_api_key)
log_step "Current Configuration"
echo ""
case $current_provider in
"anthropic")
echo -e "${GREEN}Current Provider:${NC} Anthropic (Official)"
if [ -n "$current_api_key" ]; then
echo -e "${CYAN}API Key:${NC} ${current_api_key:0:10}...${current_api_key: -4}"
fi
;;
"zai")
echo -e "${GREEN}Current Provider:${NC} Z.AI (GLM Models)"
if [ -n "$current_api_key" ]; then
echo -e "${CYAN}API Key:${NC} ${current_api_key:0:10}...${current_api_key: -4}"
fi
;;
"none")
echo -e "${YELLOW}No configuration found.${NC}"
;;
*)
echo -e "${YELLOW}Unknown configuration.${NC}"
;;
esac
echo ""
echo -e "${CYAN}${BOLD}Select your preferred API provider:${NC}"
echo " 1) Z.AI (GLM Models: glm-4.5-air, glm-4.7) - 🎁 10% OFF: https://z.ai/subscribe?ic=R0K78RJKNW"
echo " 2) Anthropic (Official Claude Models)"
echo " 3) Update API key only (keep current provider)"
echo " 4) Skip configuration"
echo ""
read -p "Choose option [1-4]: " -n 1 -r provider_choice
echo ""
echo ""
case $provider_choice in
1)
configure_zai_api
;;
2)
configure_anthropic_api
;;
3)
update_api_key_only
;;
4)
log_info "Skipping API configuration"
return 1
;;
*)
log_error "Invalid choice"
return 1
;;
esac
return 0
}
configure_zai_api() {
log_step "Z.AI API Configuration" log_step "Z.AI API Configuration"
echo "" echo ""
echo -e "${CYAN}To use Claude Code with Z.AI's GLM models, you need an API key.${NC}" echo -e "${CYAN}To use Claude Code with Z.AI's GLM models, you need an API key.${NC}"
@@ -158,36 +268,106 @@ get_zai_api_key() {
echo "" echo ""
if [ -z "$API_KEY" ]; then if [ -z "$API_KEY" ]; then
log_warn "No API key provided. You can configure it later manually." log_warn "No API key provided."
return 1 return 1
fi fi
return 0 apply_zai_config "$API_KEY"
log_success "Z.AI API configured"
log_info "API key set to: ${API_KEY:0:10}...${API_KEY: -4}"
} }
configure_zai_api() { configure_anthropic_api() {
log_step "Anthropic API Configuration"
echo ""
echo -e "${CYAN}To use Claude Code with Anthropic's official models, you need an API key.${NC}"
echo ""
echo -e "${YELLOW}Get your API key from:${NC} https://console.anthropic.com/"
echo ""
echo -e "${MAGENTA}Your API key format is: ${BOLD}sk-ant-api03-...${NC}"
echo ""
read -p "Enter your Anthropic API key (or press Enter to skip): " -r API_KEY
echo ""
if [ -z "$API_KEY" ]; then
log_warn "No API key provided."
return 1
fi
apply_anthropic_config "$API_KEY"
log_success "Anthropic API configured"
log_info "API key set to: ${API_KEY:0:10}...${API_KEY: -4}"
}
update_api_key_only() {
local current_provider=$(detect_current_provider)
log_step "Update API Key"
echo ""
case $current_provider in
"anthropic")
echo -e "${CYAN}Current provider: Anthropic${NC}"
echo -e "${YELLOW}Enter new Anthropic API key:${NC}"
;;
"zai")
echo -e "${CYAN}Current provider: Z.AI${NC}"
echo -e "${YELLOW}Enter new Z.AI API key:${NC}"
;;
*)
echo -e "${YELLOW}Could not detect current provider.${NC}"
echo "Which provider's API key do you want to update?"
echo " 1) Z.AI"
echo " 2) Anthropic"
read -p "Choose [1-2]: " -n 1 -r key_choice
echo ""
case $key_choice in
1) current_provider="zai" ;;
2) current_provider="anthropic" ;;
*) return 1 ;;
esac
;;
esac
read -p "Enter new API key: " -r API_KEY
echo ""
if [ -z "$API_KEY" ]; then
log_warn "No API key provided."
return 1
fi
if [ "$current_provider" = "zai" ]; then
apply_zai_config "$API_KEY"
else
apply_anthropic_config "$API_KEY"
fi
log_success "API key updated"
}
apply_zai_config() {
local api_key="$1" local api_key="$1"
log_step "Configuring Z.AI API..."
# Ensure .claude directory exists
mkdir -p "$CLAUDE_DIR" mkdir -p "$CLAUDE_DIR"
# Backup existing settings # Backup existing settings
if [ -f "$CLAUDE_DIR/settings.json" ]; then if [ -f "$SETTINGS_FILE" ]; then
cp "$CLAUDE_DIR/settings.json" "$CLAUDE_DIR/settings.json.backup-$(date +%Y%m%d_%H%M%S)" cp "$SETTINGS_FILE" "$SETTINGS_FILE.backup-$(date +%Y%m%d_%H%M%S)"
log_info "Backed up existing settings.json" log_info "Backed up existing settings.json"
fi fi
# Create or update settings.json with Z.AI configuration # Create or update settings.json with Z.AI configuration
if [ -f "$CLAUDE_DIR/settings.json" ]; then if [ -f "$SETTINGS_FILE" ]; then
# Merge with existing settings # Merge with existing settings
python3 -c " if command -v python3 &> /dev/null; then
python3 << PYTHON_SCRIPT
import json import json
import sys import sys
try: try:
with open('$CLAUDE_DIR/settings.json', 'r') as f: with open('$SETTINGS_FILE', 'r') as f:
settings = json.load(f) settings = json.load(f)
except: except:
settings = {} settings = {}
@@ -201,38 +381,192 @@ settings['env']['ANTHROPIC_API_KEY'] = '$api_key'
settings['env']['ANTHROPIC_DEFAULT_HAIKU_MODEL'] = 'glm-4.5-air' settings['env']['ANTHROPIC_DEFAULT_HAIKU_MODEL'] = 'glm-4.5-air'
settings['env']['ANTHROPIC_DEFAULT_SONNET_MODEL'] = 'glm-4.7' settings['env']['ANTHROPIC_DEFAULT_SONNET_MODEL'] = 'glm-4.7'
settings['env']['ANTHROPIC_DEFAULT_OPUS_MODEL'] = 'glm-4.7' settings['env']['ANTHROPIC_DEFAULT_OPUS_MODEL'] = 'glm-4.7'
settings['env']['ANTHROPIC_BASE_URL'] = 'https://dashscope-intl.aliyuncs.com/compatible-mode/v1'
with open('$CLAUDE_DIR/settings.json', 'w') as f: with open('$SETTINGS_FILE', 'w') as f:
json.dump(settings, f, indent=2) json.dump(settings, f, indent=2)
" 2>/dev/null || { PYTHON_SCRIPT
# Fallback if python3 not available
cat > "$CLAUDE_DIR/settings.json" << EOF
{
"env": {
"ANTHROPIC_API_KEY": "$api_key",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "glm-4.5-air",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "glm-4.7",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "glm-4.7"
}
}
EOF
}
else else
# Create new settings.json # Fallback if python3 not available
cat > "$CLAUDE_DIR/settings.json" << EOF cat > "$SETTINGS_FILE" << EOF
{ {
"env": { "env": {
"ANTHROPIC_API_KEY": "$api_key", "ANTHROPIC_API_KEY": "$api_key",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "glm-4.5-air", "ANTHROPIC_DEFAULT_HAIKU_MODEL": "glm-4.5-air",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "glm-4.7", "ANTHROPIC_DEFAULT_SONNET_MODEL": "glm-4.7",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "glm-4.7" "ANTHROPIC_DEFAULT_OPUS_MODEL": "glm-4.7",
"ANTHROPIC_BASE_URL": "https://dashscope-intl.aliyuncs.com/compatible-mode/v1"
} }
} }
EOF EOF
fi fi
else
# Create new settings.json
cat > "$SETTINGS_FILE" << EOF
{
"env": {
"ANTHROPIC_API_KEY": "$api_key",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "glm-4.5-air",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "glm-4.7",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "glm-4.7",
"ANTHROPIC_BASE_URL": "https://dashscope-intl.aliyuncs.com/compatible-mode/v1"
}
}
EOF
fi
}
log_success "Z.AI API configured" apply_anthropic_config() {
log_info "API key set to: ${api_key:0:10}...${api_key: -4}" local api_key="$1"
mkdir -p "$CLAUDE_DIR"
# Backup existing settings
if [ -f "$SETTINGS_FILE" ]; then
cp "$SETTINGS_FILE" "$SETTINGS_FILE.backup-$(date +%Y%m%d_%H%M%S)"
log_info "Backed up existing settings.json"
fi
# Create or update settings.json with Anthropic configuration
if [ -f "$SETTINGS_FILE" ]; then
# Merge with existing settings
if command -v python3 &> /dev/null; then
python3 << PYTHON_SCRIPT
import json
import sys
try:
with open('$SETTINGS_FILE', 'r') as f:
settings = json.load(f)
except:
settings = {}
# Add or update env section
if 'env' not in settings:
settings['env'] = {}
# Configure Anthropic (remove Z.AI specific settings if present)
settings['env']['ANTHROPIC_API_KEY'] = '$api_key'
# Remove Z.AI base URL if present
settings['env'].pop('ANTHROPIC_BASE_URL', None)
# Reset to default Anthropic models if they were set to GLM
if settings['env'].get('ANTHROPIC_DEFAULT_HAIKU_MODEL', '').startswith('glm-'):
settings['env']['ANTHROPIC_DEFAULT_HAIKU_MODEL'] = 'claude-3-5-haiku'
if settings['env'].get('ANTHROPIC_DEFAULT_SONNET_MODEL', '').startswith('glm-'):
settings['env']['ANTHROPIC_DEFAULT_SONNET_MODEL'] = 'claude-3-5-sonnet'
if settings['env'].get('ANTHROPIC_DEFAULT_OPUS_MODEL', '').startswith('glm-'):
settings['env']['ANTHROPIC_DEFAULT_OPUS_MODEL'] = 'claude-3-5-sonnet'
with open('$SETTINGS_FILE', 'w') as f:
json.dump(settings, f, indent=2)
PYTHON_SCRIPT
else
# Fallback minimal config
cat > "$SETTINGS_FILE" << EOF
{
"env": {
"ANTHROPIC_API_KEY": "$api_key"
}
}
EOF
fi
else
# Create new settings.json
cat > "$SETTINGS_FILE" << EOF
{
"env": {
"ANTHROPIC_API_KEY": "$api_key"
}
}
EOF
fi
}
check_coding_helper_installed() {
if command -v chelper &> /dev/null || npm list -g @z_ai/coding-helper &> /dev/null 2>&1; then
return 0
else
return 1
fi
}
offer_coding_helper_addons() {
log_step "Z.AI Coding-Helper Addons"
echo ""
echo -e "${CYAN}Z.AI's coding-helper (chelper) provides additional features:${NC}"
echo ""
echo " ${GREEN}${NC} Interactive wizard for easy setup"
echo " ${GREEN}${NC} Multi-tool management (Claude Code, OpenCode, etc.)"
echo " ${GREEN}${NC} MCP service configuration"
echo " ${GREEN}${NC} API key management for both Global and China plans"
echo " ${GREEN}${NC} Bilingual interface (English/Chinese)"
echo ""
echo -e "${YELLOW}Available addons/features:${NC}"
echo " • MCP servers integration (Blender, filesystem, etc.)"
echo " • Plugin marketplace access"
echo " • Automatic tool detection and installation"
echo " • Configuration backup and sync"
echo ""
read -p "Install Z.AI coding-helper? [y/N] " -n 1 -r install_helper
echo ""
if [[ ! $install_helper =~ ^[Yy]$ ]]; then
log_info "Skipping coding-helper installation"
return
fi
install_coding_helper
}
install_coding_helper() {
log_info "Installing @z_ai/coding-helper..."
echo ""
if check_coding_helper_installed; then
log_info "coding-helper already installed"
echo ""
read -p "Launch coding-helper wizard now? [y/N] " -n 1 -r launch_helper
echo ""
if [[ $launch_helper =~ ^[Yy]$ ]]; then
launch_coding_helper
fi
return
fi
# Install the helper
if npm install -g @z_ai/coding-helper 2>/dev/null; then
log_success "coding-helper installed successfully"
echo ""
echo -e "${CYAN}You can now run:${NC} ${YELLOW}chelper${NC} ${CYAN}or${NC} ${YELLOW}npx @z_ai/coding-helper${NC}"
echo ""
read -p "Launch coding-helper wizard now? [y/N] " -n 1 -r launch_helper
echo ""
if [[ $launch_helper =~ ^[Yy]$ ]]; then
launch_coding_helper
fi
else
log_warn "Installation completed. You can run manually with:"
echo " ${YELLOW}npx @z_ai/coding-helper${NC}"
fi
}
launch_coding_helper() {
log_info "Launching Z.AI coding-helper wizard..."
echo ""
echo -e "${CYAN}The wizard will guide you through:${NC}"
echo " 1. Selecting UI language"
echo " 2. Choosing coding plan (Global/China)"
echo " 3. Entering API key"
echo " 4. Selecting tools to manage"
echo " 5. Installing and configuring tools"
echo " 6. Managing MCP services"
echo ""
if command -v chelper &> /dev/null; then
chelper
else
npx @z_ai/coding-helper
fi
} }
show_manual_instructions() { show_manual_instructions() {
@@ -250,30 +584,37 @@ show_manual_instructions() {
echo " # Verify installation" echo " # Verify installation"
echo " claude --version" echo " claude --version"
echo "" echo ""
echo -e "${GREEN}Step 2: Get Z.AI API Key${NC}" echo -e "${GREEN}Step 2: Choose Your API Provider${NC}"
echo "─────────────────────────────────────────────────────────────────" echo "─────────────────────────────────────────────────────────────────"
echo "" echo ""
echo " Visit: https://docs.z.ai/devpack/tool/claude" echo -e "${CYAN}Option A: Z.AI (GLM Models)${NC}"
echo " Sign up and get your API key" echo " ${MAGENTA}${BOLD}🎁 Grab 10% OFF Token for z.ai coding plan:${NC}"
echo ""
echo -e "${MAGENTA}${BOLD}🎁 Grab 10% OFF Token for z.ai coding plan:${NC}"
echo " ${YELLOW}https://z.ai/subscribe?ic=R0K78RJKNW${NC}" echo " ${YELLOW}https://z.ai/subscribe?ic=R0K78RJKNW${NC}"
echo "" echo ""
echo -e "${GREEN}Step 3: Configure Z.AI API${NC}" echo " Get your API key: https://docs.z.ai/devpack/tool/claude"
echo "─────────────────────────────────────────────────────────────────"
echo ""
echo " Create or edit ~/.claude/settings.json:"
echo "" echo ""
echo " Configure ~/.claude/settings.json:"
echo -e "${YELLOW} {${NC}" echo -e "${YELLOW} {${NC}"
echo -e "${YELLOW} \"env\": {${NC}" echo -e "${YELLOW} \"env\": {${NC}"
echo -e "${YELLOW} \"ANTHROPIC_API_KEY\": \"your-zai-api-key-here\",${NC}" echo -e "${YELLOW} \"ANTHROPIC_API_KEY\": \"your-zai-api-key\",${NC}"
echo -e "${YELLOW} \"ANTHROPIC_DEFAULT_HAIKU_MODEL\": \"glm-4.5-air\",${NC}" echo -e "${YELLOW} \"ANTHROPIC_DEFAULT_HAIKU_MODEL\": \"glm-4.5-air\",${NC}"
echo -e "${YELLOW} \"ANTHROPIC_DEFAULT_SONNET_MODEL\": \"glm-4.7\",${NC}" echo -e "${YELLOW} \"ANTHROPIC_DEFAULT_SONNET_MODEL\": \"glm-4.7\",${NC}"
echo -e "${YELLOW} \"ANTHROPIC_DEFAULT_OPUS_MODEL\": \"glm-4.7\"${NC}" echo -e "${YELLOW} \"ANTHROPIC_DEFAULT_OPUS_MODEL\": \"glm-4.7\",${NC}"
echo -e "${YELLOW} \"ANTHROPIC_BASE_URL\": \"https://dashscope-intl.aliyuncs.com/compatible-mode/v1\"${NC}"
echo -e "${YELLOW} }${NC}" echo -e "${YELLOW} }${NC}"
echo -e "${YELLOW} }${NC}" echo -e "${YELLOW} }${NC}"
echo "" echo ""
echo -e "${GREEN}Step 4: Start Claude Code${NC}" echo -e "${CYAN}Option B: Anthropic (Official)${NC}"
echo " Get your API key: https://console.anthropic.com/"
echo ""
echo " Configure ~/.claude/settings.json:"
echo -e "${YELLOW} {${NC}"
echo -e "${YELLOW} \"env\": {${NC}"
echo -e "${YELLOW} \"ANTHROPIC_API_KEY\": \"sk-ant-api03-...\"${NC}"
echo -e "${YELLOW} }${NC}"
echo -e "${YELLOW} }${NC}"
echo ""
echo -e "${GREEN}Step 3: Start Claude Code${NC}"
echo "─────────────────────────────────────────────────────────────────" echo "─────────────────────────────────────────────────────────────────"
echo "" echo ""
echo " cd your-project-directory" echo " cd your-project-directory"
@@ -281,11 +622,26 @@ show_manual_instructions() {
echo "" echo ""
echo " # Check model status with: /status" echo " # Check model status with: /status"
echo "" echo ""
echo -e "${GREEN}Available GLM Models${NC}" echo -e "${GREEN}Step 4 (Optional): Z.AI Coding-Helper${NC}"
echo "─────────────────────────────────────────────────────────────────" echo "─────────────────────────────────────────────────────────────────"
echo "" echo ""
echo " • glm-4.5-air - Fast, efficient model (Haiku class)" echo " # Install the helper tool"
echo " • glm-4.7 - Powerful model (Sonnet/Opus class)" echo " npm install -g @z_ai/coding-helper"
echo ""
echo " # Or run directly"
echo " npx @z_ai/coding-helper"
echo ""
echo -e "${GREEN}Available Models${NC}"
echo "─────────────────────────────────────────────────────────────────"
echo ""
echo -e "${CYAN}Z.AI GLM Models:${NC}"
echo " • glm-4.5-air - Fast, efficient (Haiku class)"
echo " • glm-4.7 - Powerful (Sonnet/Opus class)"
echo ""
echo -e "${CYAN}Anthropic Models (default):${NC}"
echo " • claude-3-5-haiku - Fast & efficient"
echo " • claude-3-5-sonnet - Balanced power"
echo " • claude-3-5-sonnet - Most capable"
echo "" echo ""
echo -e "${CYAN}${BOLD}═══════════════════════════════════════════════════════════════${NC}" echo -e "${CYAN}${BOLD}═══════════════════════════════════════════════════════════════${NC}"
echo "" echo ""
@@ -297,21 +653,22 @@ print_success_summary() {
echo -e "${GREEN}${BOLD}║ Installation Complete! ║${NC}" echo -e "${GREEN}${BOLD}║ Installation Complete! ║${NC}"
echo -e "${GREEN}${BOLD}╚═══════════════════════════════════════════════════════════════╝${NC}" echo -e "${GREEN}${BOLD}╚═══════════════════════════════════════════════════════════════╝${NC}"
echo "" echo ""
echo -e "${BOLD}Claude Code is ready with Z.AI GLM models!${NC}" echo -e "${BOLD}Claude Code is ready with your chosen configuration!${NC}"
echo "" echo ""
echo -e "${CYAN}Quick Start:${NC}" echo -e "${CYAN}Quick Start:${NC}"
echo -e " 1. ${YELLOW}cd your-project-directory${NC}" echo -e " 1. ${YELLOW}cd your-project-directory${NC}"
echo -e " 2. ${YELLOW}claude${NC}" echo -e " 2. ${YELLOW}claude${NC}"
echo -e " 3. ${YELLOW}/status${NC} - Check current model status" echo -e " 3. ${YELLOW}/status${NC} - Check current model status"
echo "" echo ""
echo -e "${CYAN}Model Configuration:${NC}"
echo -e "${GREEN}Haiku class${NC}: glm-4.5-air (fast, efficient)"
echo -e "${GREEN}Sonnet class${NC}: glm-4.7 (powerful)"
echo -e "${GREEN}Opus class${NC}: glm-4.7 (most powerful)"
echo ""
echo -e "${CYAN}Configuration File:${NC}" echo -e "${CYAN}Configuration File:${NC}"
echo -e " ${YELLOW}~/.claude/settings.json${NC}" echo -e " ${YELLOW}~/.claude/settings.json${NC}"
echo "" echo ""
echo -e "${CYAN}Switch Providers:${NC}"
echo -e " Run this script again: ${YELLOW}./install-claude-code.sh${NC}"
echo ""
echo -e "${CYAN}Z.AI Coding-Helper:${NC}"
echo -e " ${YELLOW}npx @z_ai/coding-helper${NC} - Interactive wizard"
echo ""
echo -e "${CYAN}Documentation:${NC}" echo -e "${CYAN}Documentation:${NC}"
echo -e " ${YELLOW}https://docs.z.ai/devpack/tool/claude${NC}" echo -e " ${YELLOW}https://docs.z.ai/devpack/tool/claude${NC}"
echo "" echo ""
@@ -341,7 +698,7 @@ main() {
;; ;;
-h|--help) -h|--help)
echo "Usage: $0 [options]" echo "Usage: $0 [options]"
echo " --auto Automatic installation with API key prompt (default)" echo " --auto Automatic installation with provider selection (default)"
echo " --manual Show manual installation steps only" echo " --manual Show manual installation steps only"
echo " --skip-install Skip Claude Code installation, just configure API" echo " --skip-install Skip Claude Code installation, just configure API"
exit 0 exit 0
@@ -361,20 +718,59 @@ main() {
# Automatic mode # Automatic mode
check_nodejs check_nodejs
# Check if Claude Code is already installed
if check_claude_code_installed; then
echo ""
log_step "Claude Code Detection"
log_info "Claude Code is already installed!"
echo ""
claude --version
echo ""
# Offer to switch provider or update API key
if [ "$SKIP_INSTALL" = false ]; then
if ! switch_provider; then
log_info "No configuration changes made"
fi
fi
else
# Not installed - proceed with installation
install_claude_code install_claude_code
# Get and configure API key # After installation, configure API
if get_zai_api_key; then
configure_zai_api "$API_KEY"
print_success_summary
else
echo "" echo ""
log_info "You can configure the API key later by:" log_step "API Configuration"
echo " 1. Editing ~/.claude/settings.json"
echo " 2. Or running this script again"
echo "" echo ""
show_manual_instructions echo -e "${CYAN}${BOLD}Select your preferred API provider:${NC}"
echo " 1) Z.AI (GLM Models: glm-4.5-air, glm-4.7) - 🎁 10% OFF"
echo " 2) Anthropic (Official Claude Models)"
echo " 3) Skip for now"
echo ""
read -p "Choose option [1-3]: " -n 1 -r initial_choice
echo ""
echo ""
case $initial_choice in
1)
configure_zai_api
;;
2)
configure_anthropic_api
;;
3)
log_info "Skipping API configuration"
;;
*)
log_error "Invalid choice"
;;
esac
fi fi
# Offer Z.AI coding-helper addons
offer_coding_helper_addons
print_success_summary
} }
# Run main function # Run main function