| domain | archive |
|---|---|
| title | Claude Code Proxy Troubleshoot |
| verification | metadata-normalized |
| source | skill-pipeline |
| status | draft |
| created | 2026-05-09 |
(此 lesson 从 skill claude-code-proxy-troubleshoot 自动提取,待补全)
(待补充)
- Claude 报
Unable to connect to API (ConnectionRefused) - Claude 卡在
Retrying in 3s · attempt N/10 - 用户问"代理怎么开关"、"连不上了"
ccswitch proxy status显示代理未运行
# 1. 三行诊断
ccswitch proxy status # 代理是否在跑 + 当前模式
ss -tlnp | grep 8765 # 端口是否在监听
ps aux | grep anthropic-openai-proxy | grep -v grep # 进程是否存在代理进程可能因 shell 退出、系统休眠、OOM 等原因消失。
# 重启代理(确保 DEEPSEEK_API_KEY 可用)
ccswitch proxy on
# 或手动启动:
UPSTREAM_BASE="https://api.deepseek.com/v1" \
UPSTREAM_KEY="$DEEPSEEK_API_KEY" \
DEFAULT_MODEL="deepseek-v4-flash" \
FALLBACK_BASE="https://api.deepseek.com/v1" \
FALLBACK_KEY="$DEEPSEEK_API_KEY" \
FALLBACK_MODEL="deepseek-v4-flash" \
python3 ~/anthropic-openai-proxy.py &代理进程启动时从 shell 继承环境变量。如果启动代理的 shell 没设 DEEPSEEK_API_KEY,代理会带着空 key 去调 DeepSeek → 401。
# 检查代理进程实际拿到的 key
cat /proc/<PID>/environ | tr '\0' '\n' | grep DEEPSEEK
# 如果为空,source 后重启
source /tmp/proxy_env.sh # 或 export DEEPSEEK_API_KEY=xxx
ccswitch proxy onccswitch proxy off 会把 settings.json 改成 mify 直连模式。如果之后想用代理但忘了切回来:
# 看当前 settings 指向哪
python3 -c "import json; d=json.load(open('~/.claude/settings.json')); print(d['env']['ANTHROPIC_BASE_URL'])"
# 如果是 model.mify.ai.srv → 说明是直连模式
# 如果是 127.0.0.1:8765 → 说明是代理模式
# 切回代理模式
ccswitch proxy onClaude 启动时检测到自定义 API key,弹出 "Do you want to use this API key?" 选择框。
- 选 1. Yes — 使用 mify key
- 如果 bootstrap 报错 → 需要
--bare模式(ccswitch proxy off会自动创建 wrapper)
可能是 Claude 进程在代理启动之前就启动了,连接已失败。
# 退出当前 claude,重新启动
exit # 或 Ctrl+C
claude| 模式 | 命令 | ANTHROPIC_BASE_URL | 用途 |
|---|---|---|---|
| 代理 ON | ccswitch proxy on |
http://127.0.0.1:8765 |
DeepSeek/mimo 模型 |
| 代理 OFF | ccswitch proxy off |
http://model.mify.ai.srv/anthropic |
mify Claude 直连 |
Claude Code (Anthropic 格式)
↓ localhost:8765
anthropic-openai-proxy.py (ThreadingHTTPServer)
↓ 格式转换: Anthropic Messages → OpenAI Chat Completions
DeepSeek API / Mioffice API (OpenAI 格式)
↓ 响应转换回来
Claude Code
- 代理额外延迟 ~5-10ms(可忽略)
- ThreadingHTTPServer 多线程,不会阻塞并发工具调用
- 双上游 fallback:主挂了自动切备
ccswitch proxy status # 查看代理状态
ccswitch proxy on # 开代理
ccswitch proxy off # 关代理(mify 直连)
ccswitch status # 查看完整配置(模型+代理)
ccswitch list # 可用模型列表| 文件 | 用途 |
|---|---|
~/anthropic-openai-proxy.py |
代理脚本(ThreadingHTTPServer :8765) |
~/ccswitch |
模型+代理切换脚本 |
~/.claude/settings.json |
WSL 侧 Claude 配置 |
C:/Users/User/.claude/settings.json |
Windows 侧 Claude 配置 |
/tmp/proxy_env.sh |
API key 环境变量 |
~/Desktop/start-claude-proxy.bat |
Windows 桌面一键开代理 |
~/Desktop/stop-claude-proxy.bat |
Windows 桌面一键关代理 |
(待补充)