Skip to content

fix: 修复 Windows Claude 启动与会话模型持久化#260

Open
fightZy wants to merge 4 commits intoop7418:mainfrom
fightZy:codex/fix-windows-claude-detection-launch
Open

fix: 修复 Windows Claude 启动与会话模型持久化#260
fightZy wants to merge 4 commits intoop7418:mainfrom
fightZy:codex/fix-windows-claude-detection-launch

Conversation

@fightZy
Copy link

@fightZy fightZy commented Mar 12, 2026

关联 Issue

Closes #174

概要

  • 修复 Windows 下非 npm claude.cmd/.bat 包装器被错误改写为不存在 cli.js 路径的问题,兼容 Scoop shim 等安装方式
  • 恢复 chat/bridge 流程对 statusData.model 的会话持久化,确保 env 或 provider 默认模型会写回 session
  • 补充回归测试,并修复 claude-session-parser 在 Windows 下的既有单测问题

根因

  • Windows 启动路径推导默认假设所有 cmd 包装器都来自 npm 全局安装
  • SDK status 事件返回的真实模型没有再写回 chat_sessions.model
  • claude-session-parser 单测在 Windows 下直接用磁盘路径动态导入 ESM,导致测试被取消

验证

  • npm run test
  • 新增/更新单元测试覆盖 Windows 启动路径、模型持久化、Windows 下 parser 测试加载

fightZy added 4 commits March 11, 2026 22:15
- search Scoop and Node.js global install paths when resolving Claude CLI on Windows

- accept Windows cmd/bat wrappers during detection and route SDK launch through the real Claude Code cli.js entrypoint with node

- classify launch failures more accurately and cover the regression with unit tests
claude-client:\n- normalize upstream Anthropic model ids back to Claude Code aliases before launch\n- add launch diagnostics for model, executable, env, stderr, and failure details\n- keep Windows wrapper resolution explicit so packaged builds launch the system Claude CLI predictably\n\nprovider-resolution:\n- inherit auth/base URL from ~/.claude/settings.json in env mode\n- stop relying only on process env or legacy DB settings for Claude-compatible providers\n\nroutes-and-bridge:\n- stop persisting SDK status model into chat sessions to avoid model pollution\n- preserve session model selection across bridge/chat runs\n\nroot-cause:\n- Windows env-mode sessions could store upstream model ids like claude-sonnet-4-20250514\n- Claude CLI launched with that invalid model against DashScope-compatible endpoints and exited with code 1
按功能分组:\n- src/lib/claude-client.ts 与 src/__tests__/unit/claude-client-launch.test.ts: 仅在同目录 npm cli.js 存在时才将 Windows .cmd/.bat 包装器改写为 node 启动,避免 Scoop shim 被解析到不存在路径\n- src/app/api/chat/route.ts 与 src/lib/bridge/conversation-engine.ts: 恢复 statusData.model 的 session 持久化,确保 env/provider 默认模型会写回会话\n- src/__tests__/unit/chat-route-model-persistence.test.ts: 新增回归测试覆盖模型持久化契约\n- src/__tests__/unit/claude-session-parser.test.ts: 修复 Windows ESM file URL 与 HOME/USERPROFILE 测试环境,消除既有 cancelled 测试\n\n根因:\n- Windows 启动路径推导默认假设所有 cmd 包装器都来自 npm 全局安装\n- status 事件返回的真实模型未再写回 chat_sessions\n- claude-session-parser 单测在 Windows 下使用磁盘路径直接 import ESM 导致失败\n\n影响范围:\n- Windows Claude CLI 检测与启动\n- chat/bridge 流程中的会话模型展示与统计\n- Windows 下单元测试稳定性
@vercel
Copy link

vercel bot commented Mar 12, 2026

@fightZy is attempting to deploy a commit to the op7418's projects Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Claude Code 通过 npm 安装后在 Windows 上无法被 CodePilot 检测到

1 participant