1. 安装claude code安装nvm通过nvm 安装node.js$ nvm--version0.39.3 $npm--version11.12.1 $node--vv22.14.0安装 claude-codenpminstall-ganthropic-ai/claude-code2. 安装litellm安装python3.10创建python虚拟环境ccx安装litellm#$ mkvirtualenv ccx -p /usr/bin/python3.10(ccx)$ pipinstalllitellm(ccx)$ pipinstalllitellm[proxy](ccx)$ pipinstallhttpx[socks]3. 配置claude code3.1 启用litellm在~/.zshrc文件中添加以下内容exportZHIPU_API_KEYyour_api_key运行source ~/.zshrc命令使环境变量生效。创建litellm_config.yaml与下文启动命令文件名一致并添加以下内容。Claude Code 会通过 Anthropic 接口请求诸如claude-sonnet-4-6等官方模型名因此需要一条model_name: *的通配路由把这些名称全部转到实际使用的国内模型。model_list:# - model_name: qwen# litellm_params:# model: dashscope/qwen-plus# - model_name: kimi# litellm_params:# model: moonshot/moonshot-v1-8k-model_name:*litellm_params:model:zai/glm-5.1api_key:os.environ/ZHIPU_API_KEY-model_name:glmlitellm_params:model:zai/glm-5.1api_key:os.environ/ZHIPU_API_KEYlitellm_settings:drop_params:trueClaude Code 会带上 Anthropic 专有字段如context_management转给 GLM 时需丢弃drop_params: true即由 LiteLLM 自动去掉后端不支持的参数。运行 LiteLLM 代理(ccx)➜ ccx litellm--configlitellm_config.yaml--port4000INFO: Started server process[379725]INFO: Waitingforapplication startup. ██╗ ██╗████████╗███████╗██╗ ██╗ ███╗ ███╗ ██║ ██║╚══██╔══╝██╔════╝██║ ██║ ████╗ ████║ ██║ ██║ ██║ █████╗ ██║ ██║ ██╔████╔██║ ██║ ██║ ██║ ██╔══╝ ██║ ██║ ██║╚██╔╝██║ ███████╗██║ ██║ ███████╗███████╗███████╗██║ ╚═╝ ██║ ╚══════╝╚═╝ ╚═╝ ╚══════╝╚══════╝╚══════╝╚═╝ ╚═╝#------------------------------------------------------------## ## This product would be better if... ## https://github.com/BerriAI/litellm/issues/new ## ##------------------------------------------------------------#Thank youforusing LiteLLM!- KrrishIshaan Give Feedback / Get Help: https://github.com/BerriAI/litellm/issues/new LiteLLM: Proxy initialized with Config, Set models: qwen kimi glm INFO: Application startup complete. INFO: Uvicorn running on http://0.0.0.0:4000(Press CTRLC to quit)3.2 配置claude code在~/.zshrc文件中添加以下内容exportANTHROPIC_API_KEYdummyexportANTHROPIC_BASE_URLhttp://127.0.0.1:4000运行source ~/.zshrc命令使环境变量生效。运行claude命令并输入以下内容$ claudeChoose the text style that looks best with your terminalANTHROPIC_API_KEY: sk-ant-…dummy [选择yes]Enteryes如果运行claude初始化配置有问题则执行以下命令重新配置:$rm-rf~/.claude* $ claude4. 测试claude code运行claude命令并输入以下内容$ claude写一个python函数判断质数 ❯