< 自用文 Bash Script > 用来在 Claude Code 订阅用户 GLM API(代码编程专享计划 ),KIMI-Coding 切换登录

AI 时代程序员必备技能

Codex、Claude Code、Cursor、Hermes Agent、OpenClaw等工程化实战专栏 ,讲透 AI 如何接管脏活累活

前言:

之前有发过一编:https://blog.csdn.net/davenian/article/details/152609803

< 自用文 Bash Script > 用来在 Claude Code 订阅用户 与GLM API (代码编程专享计划 )切换登录

改起来太多,所以单开一文。

原因:

双 11, Kimi 有个首月 0.99 元。于是:

好奇用1块钱试一试,因为它有 coding key 可以使用。

更新之前的脚本.

完整脚本:claude.sh  ver.0.5

之前的选项2 API 改为 GCM-LITE, 添加 Kimi-Coding

#!/bin/bash
# Written by Dave on 6Oct.25 version 0.4
# ==============================================================================
# claude.sh - Script to switch configurations between Claude Pro Plan and API Plan
#
# Usage:
#   ./claude.sh
# Running the script will display a menu for selection
# ==============================================================================

# Version 0.5 on 11Nov.25, added model kimi-for-coding to opion 3 manual. 

# Define configuration file path
SETTINGS_DIR="$HOME/.claude"
SETTINGS_FILE="$SETTINGS_DIR/settings.json"

# JSON content for Pro Plan
# Simple configuration, only alwaysThinkingEnabled is enabled
PLAN_CONFIG='{
  "alwaysThinkingEnabled": true
}'

# JSON content for GCM-Lite Plan
# Includes detailed configurations like permissions, environment variables, etc.
GCM_LITE_CONFIG='{
  "permissions": {
    "allow": [
      "WebSearch",
      "WebFetch",
      "Bash",
      "Edit",
      "Write",
      "MultiEdit"
    ],
    "deny": [
      "Bash(curl:*)",
      "Read(./.env)",
      "Read(./.env.*)",
      "Read(./secrets/**)",
      "Read(./**/id_rsa)",
      "Read(./**/id_ed25519)",
      "Read(~/.ssh/**)",
      "Read(./**/*.key)",
      "Read(./**/*.pem)",
      "Bash(rm:*)",
      "Bash(sudo:*)"
    ],
    "defaultMode": "acceptEdits"
  },
  "cleanupPeriodDays": 30,
  "includeCoAuthoredBy": true,
  "alwaysThinkingEnabled": true,
  "env": {
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "glm-4.6-air",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "glm-4.6",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "glm-4.6",
    "ANTHROPIC_AUTH_TOKEN": "<Your GCM API key>",
    "ANTHROPIC_BASE_URL": "https://open.bigmodel.cn/api/anthropic",
    "API_TIMEOUT_MS": "3000000"
  }
}'

# JSON content for Kimi-Coding Plan
# Kimi For Coding API configuration
KIMI_CONFIG='{
  "permissions": {
    "allow": [
      "WebSearch",
      "WebFetch",
      "Bash",
      "Edit",
      "Write",
      "MultiEdit"
    ],
    "deny": [
      "Bash(curl:*)",
      "Read(./.env)",
      "Read(./.env.*)",
      "Read(./secrets/**)",
      "Read(./**/id_rsa)",
      "Read(./**/id_ed25519)",
      "Read(~/.ssh/**)",
      "Read(./**/*.key)",
      "Read(./**/*.pem)",
      "Bash(rm:*)",
      "Bash(sudo:*)"
    ],
    "defaultMode": "acceptEdits"
  },
  "cleanupPeriodDays": 30,
  "includeCoAuthoredBy": true,
  "alwaysThinkingEnabled": true,
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.kimi.com/coding/",
    "ANTHROPIC_AUTH_TOKEN": "<Your KIMI CODING key>",
    "ANTHROPIC_MODEL": "kimi-for-coding",
    "ANTHROPIC_SMALL_FAST_MODEL": "kimi-for-coding",
    "API_TIMEOUT_MS": "3000000"
  }
}'

# Function to find Claude executable
find_claude_executable() {
    # List of possible locations for claude executable
    local possible_paths=(
        "/usr/bin/claude"
        "/root/.npm-global/bin/claude"
        "/run/user/0/fnm_multishells/81682_1759786528507/bin/claude"
        "$HOME/.npm-global/bin/claude"
        "$(which claude 2>/dev/null)"
    )
    
    # Check each path
    for path in "${possible_paths[@]}"; do
        if [ -n "$path" ] && [ -x "$path" ]; then
            echo "$path"
            return 0
        fi
    done
    
    # If not found, return empty string
    return 1
}

# Ensure .claude directory exists
mkdir -p "$SETTINGS_DIR"

# Find Claude executable
CLAUDE_PATH=$(find_claude_executable)

if [ -z "$CLAUDE_PATH" ]; then
    echo "❌ Error: Claude executable not found!"
    echo "Please ensure Claude is installed and accessible in your PATH."
    echo ""
    echo "Checked locations:"
    echo "  - /usr/bin/claude"
    echo "  - /root/.npm-global/bin/claude"
    echo "  - \$HOME/.npm-global/bin/claude"
    echo "  - PATH environment variable"
    exit 1
fi

# Clear the screen for a better menu display
clear

echo "Claude Configuration Switcher"
echo "============================="
echo "Claude executable found at: $CLAUDE_PATH"
echo ""

# Use select to create a menu
# The PS3 variable sets the prompt for the select loop
PS3="Please enter your choice (number): "
options=("Switch to Pro Plan" "Switch to GCM-Lite" "Switch to Kimi-Coding" "Exit")
select opt in "${options[@]}"
do
    case $opt in
        "Switch to Pro Plan")
            echo ""
            echo "Switching to Claude Pro Plan configuration..."
            echo "$PLAN_CONFIG" > "$SETTINGS_FILE"
            echo "✅ Success! Claude will now use the Pro Plan."
            echo "🚀 Starting Claude..."
            # Execute the main claude program after switching
            "$CLAUDE_PATH"
            break
            ;;
        "Switch to GCM-Lite")
            echo ""
            echo "Switching to GCM-Lite configuration..."
            echo "$GCM_LITE_CONFIG" > "$SETTINGS_FILE"
            echo "✅ Success! Claude will now use GCM-Lite API."
            echo "🚀 Starting Claude..."
            # Execute the main claude program after switching
            "$CLAUDE_PATH"

            # After exiting Claude Code, switch back to Pro Plan
            echo ""
            echo "📝 Claude Code session ended."
            echo "🔄 Automatically switching back to Pro Plan configuration..."
            echo "$PLAN_CONFIG" > "$SETTINGS_FILE"
            echo "✅ Restored to Pro Plan settings."
            break
            ;;
        "Switch to Kimi-Coding")
            echo ""
            echo "Switching to Kimi-Coding configuration..."
            echo "$KIMI_CONFIG" > "$SETTINGS_FILE"
            echo "✅ Success! Claude will now use Kimi-Coding API."
            echo "🚀 Starting Claude..."
            # Execute the main claude program after switching
            "$CLAUDE_PATH"

            # After exiting Claude Code, switch back to Pro Plan
            echo ""
            echo "📝 Claude Code session ended."
            echo "🔄 Automatically switching back to Pro Plan configuration..."
            echo "$PLAN_CONFIG" > "$SETTINGS_FILE"
            echo "✅ Restored to Pro Plan settings."
            break
            ;;
        "Exit")
            echo ""
            echo "Operation cancelled."
            break
            ;;
        *) 
            # If the user enters an invalid number
            echo "Invalid option '$REPLY'. Please try again."
            ;;
    esac
done

exit 0

AI 时代程序员必备技能

Codex、Claude Code、Cursor、Hermes Agent、OpenClaw等工程化实战专栏 ,讲透 AI 如何接管脏活累活

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值