Claude Code 在 WezTerm 中无输出问题
问题现象
在 WezTerm 中启动 Claude Code:
claude --dangerously-skip-permissions
进入交互界面后,输入内容例如:
你好
Claude Code 没有正常输出回答,而是一直显示类似:
Retrying in 10s · attempt 8/10
Whisking...
有时还会出现:
API Error: Unable to connect to API (UnsupportedProxyProtocol)
但是使用非交互模式测试时可以正常输出:
with-env { http_proxy: "", https_proxy: "", HTTP_PROXY: "", HTTPS_PROXY: "", ALL_PROXY: "", all_proxy: "" } { claude -p "你好" }
根因
根因不是 WezTerm 本身,也不是 Claude Code 完全无法联网,而是 NuShell 启动时自动设置了代理环境变量。
在 NuShell 配置文件中:
C:\Users\Administrator\AppData\Roaming\nushell\config.nu
存在类似配置:
def --env "proxy set" [] {
load-env { "HTTP_PROXY": "socks5://127.0.0.1:7890", "HTTPS_PROXY": "socks5://127.0.0.1:7890" }
}
proxy set
其中 proxy set 会在每次打开 NuShell 时自动执行,导致环境变量被设置为:
HTTP_PROXY=socks5://127.0.0.1:7890
HTTPS_PROXY=socks5://127.0.0.1:7890
Claude Code 交互模式不兼容这里的 socks5:// 代理协议,因此出现:
UnsupportedProxyProtocol
或者一直 retry、没有正文输出。
排查过程
1. 检查 WezTerm 代理配置
一开始怀疑是 WezTerm 的代理配置问题,检查:
C:\Users\Administrator\.wezterm.lua
曾尝试配置:
config.set_environment_variables = {
http_proxy = 'http://127.0.0.1:7890',
https_proxy = 'http://127.0.0.1:7890',
}
也尝试过清空代理变量:
config.set_environment_variables = {
http_proxy = '',
https_proxy = '',
HTTP_PROXY = '',
HTTPS_PROXY = '',
ALL_PROXY = '',
all_proxy = '',
}
但从桌面右键 Open WezTerm here 打开后,问题仍然存在。
2. 测试网络连通性
测试代理端口和 Anthropic API:
curl.exe -x http://127.0.0.1:7890 -I https://api.anthropic.com
返回:
HTTP/1.1 200 Connection established
HTTP/1.1 404 Not Found
再直接测试:
curl.exe -I https://api.anthropic.com
也能返回:
HTTP/1.1 404 Not Found
说明网络和代理端口本身是通的。
3. 测试 Claude Code 无代理环境
执行:
with-env {
http_proxy: "",
https_proxy: "",
HTTP_PROXY: "",
HTTPS_PROXY: "",
ALL_PROXY: "",
all_proxy: ""
} {
claude -p "你好"
}
可以正常输出。
这说明 Claude Code 本身可用,问题来自代理环境变量。
4. 检查 NuShell 环境变量
执行:
$env | columns | where $it =~ 'proxy|PROXY'
发现有代理变量。
进一步查看 NuShell 配置文件后发现:
proxy set
每次启动 shell 都会自动执行。
解决方法
编辑 NuShell 配置文件:
C:\Users\Administrator\AppData\Roaming\nushell\config.nu
把自动执行的:
proxy set
改成注释:
# 不要默认开启代理;Claude Code 交互模式会被代理变量影响,导致一直 Retrying/无输出。
# 需要代理时再手动执行:proxy set
# proxy set
保留 proxy set 和 proxy unset 函数,这样需要代理时仍然可以手动开启。
最终状态
以后打开 WezTerm / NuShell 后,不再默认设置代理。
需要代理时手动执行:
proxy set
关闭代理:
proxy unset
检查当前 shell 是否还有代理变量:
$env | transpose key value | where key =~ 'proxy|PROXY'
启动 Claude Code:
claude --dangerously-skip-permissions
现在可以正常输出。
避坑总结
- Claude Code 交互模式可能不兼容
socks5://形式的HTTP_PROXY/HTTPS_PROXY。 curl能通,不代表 Claude Code 交互模式一定能通。claude -p "你好"能输出,可以用来判断 Claude Code 本身是否可用。- 如果交互模式一直
Retrying,优先检查环境变量:
$env | transpose key value | where key =~ 'proxy|PROXY'
- WezTerm 配置清空代理不一定有效,因为 shell 启动脚本可能会再次设置代理。
- NuShell 的
config.nu/env.nu里如果有自动proxy set,会覆盖 WezTerm 的环境变量设置。
远程技术支持,➕dqtx33

浙公网安备 33010602011771号