ClaudeCode安装记录

ClaudeCode安装记录

ClaudeCode目前目前支持配置AutoGLM和Kimi;Mac版本会相对简单一点,AutoGLM配了自动化的部署脚本,Windows会稍微复杂一点,需要自己配置环境变量

1-参考网址


2-Windows安装

  • 配置环境变量
复制代码
CLAUDE_CODE_GIT_BASH_PATH=git的路径:D:\TT_INSTALL+\GIT\bin\bash.exe
ANTHROPIC_API_KEY:XXXXXXXXXXXXXXXXXXXXXXX
ANTHROPIC_BASE_URL:https://api.moonshot.cn/anthropic
  • 安装claude-code

    npm install -g @anthropic-ai/claude-code

  • 编辑C:\Users\popyu.claude.json

当前在代码中添加hasCompletedOnboarding=true之后就可以进行使用了,参考网址:https://blog.csdn.net/qq_35376047/article/details/150064785

json 复制代码
{
  "installMethod": "npm-global",
  "cachedStatsigGates": {
    "tengu_disable_bypass_permissions_mode": false,
    "tengu_thinkback": false,
    "tengu_sumi": false,
    "tengu_prompt_suggestion": false
  },
  "mcpServers": {},
  "firstStartTime": "2025-12-18T11:31:06.602Z",
  "sonnet45MigrationComplete": true,
  "opus45MigrationComplete": true,
  "thinkingMigrationComplete": true,
  "hasCompletedOnboarding": true
}


3-Mac安装

shell 复制代码
#!/bin/bash

set -euo pipefail

# ========================
#       常量定义
# ========================
SCRIPT_NAME=$(basename "$0")
NODE_MIN_VERSION=18
NODE_INSTALL_VERSION=22
NVM_VERSION="v0.40.3"
CLAUDE_PACKAGE="@anthropic-ai/claude-code"
CONFIG_DIR="$HOME/.claude"
CONFIG_FILE="$CONFIG_DIR/settings.json"
API_BASE_URL="https://open.bigmodel.cn/api/anthropic"
API_KEY="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
API_TIMEOUT_MS=3000000

# ========================
#       工具函数
# ========================

log_info() {
    echo "🔹 $*"
}

log_success() {
    echo "✅ $*"
}

log_error() {
    echo "❌ $*" >&2
}

ensure_dir_exists() {
    local dir="$1"
    if [ ! -d "$dir" ]; then
        mkdir -p "$dir" || {
            log_error "Failed to create directory: $dir"
            exit 1
        }
    fi
}

# ========================
#     Node.js 安装函数
# ========================

install_nodejs() {
    local platform=$(uname -s)

    case "$platform" in
        Linux|Darwin)
            log_info "Installing Node.js on $platform..."

            # 安装 nvm
            log_info "Installing nvm ($NVM_VERSION)..."
            curl -s https://raw.githubusercontent.com/nvm-sh/nvm/"$NVM_VERSION"/install.sh | bash

            # 加载 nvm
            log_info "Loading nvm environment..."
            \. "$HOME/.nvm/nvm.sh"

            # 安装 Node.js
            log_info "Installing Node.js $NODE_INSTALL_VERSION..."
            nvm install "$NODE_INSTALL_VERSION"

            # 验证安装
            node -v &>/dev/null || {
                log_error "Node.js installation failed"
                exit 1
            }
            log_success "Node.js installed: $(node -v)"
            log_success "npm version: $(npm -v)"
            ;;
        *)
            log_error "Unsupported platform: $platform"
            exit 1
            ;;
    esac
}

# ========================
#     Node.js 检查函数
# ========================

check_nodejs() {
    if command -v node &>/dev/null; then
        current_version=$(node -v | sed 's/v//')
        major_version=$(echo "$current_version" | cut -d. -f1)

        if [ "$major_version" -ge "$NODE_MIN_VERSION" ]; then
            log_success "Node.js is already installed: v$current_version"
            return 0
        else
            log_info "Node.js v$current_version is installed but version < $NODE_MIN_VERSION. Upgrading..."
            install_nodejs
        fi
    else
        log_info "Node.js not found. Installing..."
        install_nodejs
    fi
}

# ========================
#     Claude Code 安装
# ========================

install_claude_code() {
    if command -v claude &>/dev/null; then
        log_success "Claude Code is already installed: $(claude --version)"
    else
        log_info "Installing Claude Code..."
        npm install -g "$CLAUDE_PACKAGE" || {
            log_error "Failed to install claude-code"
            exit 1
        }
        log_success "Claude Code installed successfully"
    fi
}

configure_claude_json(){
  node --eval '
      const os = require("os");
      const fs = require("fs");
      const path = require("path");

      const homeDir = os.homedir();
      const filePath = path.join(homeDir, ".claude.json");
      if (fs.existsSync(filePath)) {
          const content = JSON.parse(fs.readFileSync(filePath, "utf-8"));
          fs.writeFileSync(filePath, JSON.stringify({ ...content, hasCompletedOnboarding: true }, null, 2), "utf-8");
      } else {
          fs.writeFileSync(filePath, JSON.stringify({ hasCompletedOnboarding: true }, null, 2), "utf-8");
      }'
}

# ========================
#     API Key 配置
# ========================

configure_claude() {
    log_info "Configuring Claude Code..."
    ensure_dir_exists "$CONFIG_DIR"

    # 写入配置文件
    node --eval '
        const os = require("os");
        const fs = require("fs");
        const path = require("path");

        const homeDir = os.homedir();
        const filePath = path.join(homeDir, ".claude", "settings.json");
        const apiKey = "'"$API_KEY"'";

        const content = fs.existsSync(filePath)
            ? JSON.parse(fs.readFileSync(filePath, "utf-8"))
            : {};

        fs.writeFileSync(filePath, JSON.stringify({
            ...content,
            env: {
                ANTHROPIC_AUTH_TOKEN: apiKey,
                ANTHROPIC_BASE_URL: "'"$API_BASE_URL"'",
                API_TIMEOUT_MS: "'"$API_TIMEOUT_MS"'",
                CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: 1
            }
        }, null, 2), "utf-8");
    ' || {
        log_error "Failed to write settings.json"
        exit 1
    }

    log_success "Claude Code configured successfully"
}

# ========================
#        主流程
# ========================

main() {
    echo "🚀 Starting $SCRIPT_NAME"

    check_nodejs
    install_claude_code
    configure_claude_json
    configure_claude

    echo ""
    log_success "🎉 Installation completed successfully!"
    echo ""
    echo "🚀 You can now start using Claude Code with:"
    echo "   claude"
}

main "$@"
  • 配置环境配置环境变量(如果使用脚本可以跳过该步骤)

    echo 'export ANTHROPIC_API_KEY="XXXXXXXXXXXXX"' >> ~/.zshrc
    echo 'export https_proxy="https://api.moonshot.cn/anthropic"' >> ~/.zshrc
    source ~/.zshrc

    echo 'export ANTHROPIC_API_KEY="XXXXXXXXXXXXX"' >> ~/.bash_profile
    echo 'export https_proxy="https://api.moonshot.cn/anthropic"' >> ~/.bash_profile
    source ~/.bash_profile


4-网络代理设置

复制代码
echo 'export http_proxy="http://127.0.0.1:7890"' >> ~/.zshrc 
echo 'export https_proxy="http://127.0.0.1:7890"' >> ~/.zshrc 
source ~/.zshrc


echo 'export http_proxy="http://127.0.0.1:7890"' >> ~/.bash_profile
echo 'export https_proxy="http://127.0.0.1:7890"' >> ~/.bash_profile
source ~/.bash_profile

5-原版备份

cat ~/.claude/settings.json 在env中添加ANTHROPIC_API_KEY和ANTHROPIC_BASE_URL配置

复制代码
{
  "$schema": "https://json.schemastore.org/claude-code-settings.json",
  "env": {
    "DISABLE_TELEMETRY": "1",
    "DISABLE_ERROR_REPORTING": "1",
    "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1",
    "MCP_TIMEOUT": "60000"
  },
  "includeCoAuthoredBy": false,
  "permissions": {
    "allow": [
      "Bash",
      "BashOutput",
      "Edit",
      "Glob",
      "Grep",
      "KillShell",
      "NotebookEdit",
      "Read",
      "SlashCommand",
      "Task",
      "TodoWrite",
      "WebFetch",
      "WebSearch",
      "Write",
      "mcp__ide",
      "mcp__exa",
      "mcp__context7",
      "mcp__mcp-deepwiki",
      "mcp__Playwright",
      "mcp__spec-workflow",
      "mcp__open-websearch",
      "mcp__serena"
    ],
    "deny": []
  },
  "hooks": {},
  "outputStyle": "engineer-professional"
}

6-配置中文展示

  • 工作目录创建.claude 文件夹,内部创建一个setting.json文件(核心是language_preferences配置)

  • vim ./.claude/settings.json

    {
    "model": "claude-3-5-sonnet-20241022",
    "max_tokens": 4000,
    "temperature": 0.7,
    "auto_approve": false,
    "git_integration": true,
    "excluded_files": [
    "node_modules/",
    ".git/
    ",
    "*.log",
    "dist/**"
    ],
    "language_preferences": {
    "documentation": "zh-CN",
    "code_comments": "zh-CN"
    }
    }

相关推荐
ServBay38 分钟前
Claude 账号可能被盗刷,而你毫无察觉
api·ai编程·claude
Darling噜啦啦2 小时前
LLM 记忆管理三剑客:截断、总结、检索,彻底搞懂 Agent 的 Memory 系统
langchain·llm·agent
今日无bug2 小时前
大模型的回答是怎么一个字一个字蹦出来的?前端流式输出解析
前端·llm·agent
大刚测试开发实战4 小时前
用例写不完、回归跑不动?我把最磨人的活交给 TestHub,KPI 反而稳了
ai编程·测试·claude
桃西西呀6 小时前
《牛来》票房涨 1000 倍是真的吗?——2026暑期档 124 亿里的数学
人工智能·数据分析·llm
Behavior6 小时前
刚刚,Claude 5.1 发布!全球最强模型来了?
aigc·claude·vibecoding
wangruofeng7 小时前
Claude Fable 5.1 发布,一个模型两种安全档,账单最多省 45%
aigc·ai编程·claude
tachibana27 小时前
如何设计多 Agent 的协作与动态切换机制?
网络·人工智能·ai·大模型·llm·agent
程序员三明治9 小时前
【体验毛坯房】Deep Harness 入门教程
java·人工智能·后端·大模型·llm·deepseek·dsh
桃西西呀9 小时前
AI 为什么一本正经地胡说八道?3 个底层原因 + 2 个防坑法
人工智能·llm·ai编程