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

Offen
#691 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
48/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
electron, nextjs, node.js, typescript

Rechercherichtung

Start by locating findClaudeBinary() and the duplicated CLI detection logic in the main process and Next server chunks, then read how where claude output is decoded and candidates are checked with --version. Reproduce on Windows with a non-ASCII username and Volta-installed Claude CLI. Done when detection passes the correct path and the runtime proceeds to the expected Using runtime and shadow-home log entries.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

bug P0-crash-or-interrupt
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
Vorherrschende Sprache
TypeScript
Sterne
6.5k
Forks
697
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Entwicklungsumgebung

  • Kein Dockerfile und keine Docker-Compose-Datei
  • Hat eine Pull-Request-Vorlage
  • Kein Beitragsleitfaden

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus op7418/CodePilot

Alle Issues in op7418/CodePilot

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.