Skip to content

中文 Windows 用户名下误报 "Claude Code CLI is not installed or not detected" #691

Open

Description

@fumj0114

CodePilot 版本 / Version

0.56

操作系统与架构 / OS & arch

Windows 11 家庭中文版 26200

Runtime

Claude Code (SDK)

Provider / Model

DeepSeek

是否可复现 / Reproducible?

每次都能复现 / always

复现步骤 / Steps to reproduce

标题:中文 Windows 用户名下误报 "Claude Code CLI is not installed or not detected"

环境:

  • Windows 11 家庭中文版 26200
  • CodePilot 0.67.17
  • Claude Code 2.1.234,通过 Volta 安装
  • Windows 用户名含中文(C:\Users\傅明杰)

复现步骤:

  1. 新建会话,运行时选 Claude Code(会话被钉在 claude_code)
  2. 发送任意消息(如"你好")

实际结果:
报错 "Claude Code is pinned for this session, but the Claude Code CLI is not installed or not detected..."
但此时在终端执行 where claude 能找到路径,claude --version 正常输出 2.1.234。
codepilot-main.log 中该请求有 [chat API] streamClaude params,但没有后续的
[streamClaude] Using runtime 和 [shadow-home] 日志,说明卡在运行时解析阶段。

根因(已定位并复现):
findClaudeBinary() 的固定候选目录(/.local/bin、/.claude/bin、/.bun/bin、
%APPDATA%\npm、%LOCALAPPDATA%\npm、
/.npm-global/bin)不包含 Volta 的安装位置,
因此只能走 where claude 回退分支。而中文 Windows 下 where.exe 按 OEM 代码页 936 (GBK)
输出,Node 的 execFileSync 默认按 UTF-8 解码,导致路径中的中文变成替换字符,
后续对每个候选执行 --version 全部失败(ENOENT / 系统找不到指定的路径),
函数返回 undefined,isAvailable() 为 false,于是抛出"未安装"。

证据:where claude 的原始输出字节为
433a5c55736572735cb8b5c3f7bddc5c417070446174615c...
其中 b8b5 c3f7 bddc 正是"傅明杰"的 GBK 编码。

临时绕过(已验证有效):
在 %USERPROFILE%.local\bin\ 下放一个 claude.cmd 转发脚本即可,
因为该目录属于固定候选,路径由 JS 直接拼接,不经过 where 的输出解码。
(脚本内容:volta run claude %*)

建议修复:

  1. where 的输出用 encoding: 'buffer' 读取,再按系统 OEM 代码页解码
    (如 new TextDecoder('gbk'),Electron 的 full-icu 支持),不要直接 toString()。
  2. 或者去掉 where 回退,改为遍历 process.env.PATH 的各目录 + fs.existsSync(dir/claude.{cmd,exe,bat}),
    全程不经过子进程输出解码。
  3. 建议增加"手动指定 Claude Code CLI 路径"的设置项,作为最终兜底。
  4. 注意该检测逻辑在 main 进程(app.asar)和 Next server(.next chunks)各有一份,
    两处都要改。

验证方法:在一台中文用户名的机器上,确认 where 返回的路径能正确传递并成功执行 --version

期望 vs 实际 / Expected vs actual

【期望结果】
会话被钉在 Claude Code 运行时(runtime_pin = claude_code)且本机已安装 CLI 时,
发送消息应正常调用 Claude Code 并流式回复;日志中应出现:
[streamClaude] Using runtime: claude-code-sdk (session pin: claude_code, ...)
[shadow-home] Built shadow HOME ...

【实际结果】
发送"你好"后立即返回:
Claude Code is pinned for this session, but the Claude Code CLI is not installed
or not detected. Install the Claude Code CLI, or switch this session to CodePilot
or Codex Runtime.
没有任何模型输出。但终端里 where claude 能找到路径,claude --version 正常输出 2.1.234。
同一条会话的日志只有 [chat API] streamClaude params,之后没有 Using runtime 和
shadow-home 两行,说明在运行时解析阶段就失败了(实际是 where.exe 的 GBK 输出被
按 UTF-8 解码,路径乱码导致 --version 探测全部失败,详见正文)。

日志 / 截图 / session id

日志摘录.txt

Image

影响面 / Impact

  • 涉及文件写入或可能误改/丢失数据 / involves file write or possible data loss
  • 导致崩溃、闪退或对话被自动中断 / causes crash / quit / auto-interrupt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P0-crash-or-interrupt崩溃 / 自动中断 / 卡死,阻断主路径bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions