fix: 去掉 Start-Process, bat 负责窗口/ps1 负责执行

根因: Start-Process pwsh 开新窗口但 claude 找不到 PATH,
同时 OneClick.bat 重复调用 install.ps1 导致双启动。

- install.ps1: 新增 -SkipLaunch 参数, step9 改为同步 & claude
- auto-setup.ps1: Phase7 去掉 Start-Process, 同步 & claude
- OneClick.bat: step7 加 -SkipLaunch, 最终块 start pwsh -Command claude
- 启动/更新.bat: 直接 start pwsh -Command claude (不经 install.ps1)

架构: bat 决定窗口类型, ps1 只管同步执行

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
bookworm 2026-04-06 20:34:00 +08:00
parent c4c09992f6
commit 2d4dea242b
5 changed files with 27 additions and 37 deletions

View File

@ -202,12 +202,12 @@ echo [7/8] 执行安装配置...
echo. echo.
if exist "%INSTALL_DIR%\install.ps1" ( if exist "%INSTALL_DIR%\install.ps1" (
:: 优先 pwsh (PowerShell 7), 回退 powershell (5.1) :: 安装配置 (不启动 claude, 最终块负责在 pwsh7 窗口中启动)
where pwsh >nul 2>nul where pwsh >nul 2>nul
if !errorlevel! equ 0 ( if !errorlevel! equ 0 (
pwsh -NoLogo -ExecutionPolicy Bypass -File "%INSTALL_DIR%\install.ps1" -AutoAccept pwsh -NoLogo -ExecutionPolicy Bypass -File "%INSTALL_DIR%\install.ps1" -AutoAccept -SkipLaunch
) else ( ) else (
powershell -NoLogo -ExecutionPolicy Bypass -File "%INSTALL_DIR%\install.ps1" -AutoAccept powershell -NoLogo -ExecutionPolicy Bypass -File "%INSTALL_DIR%\install.ps1" -AutoAccept -SkipLaunch
) )
) else ( ) else (
echo [WARN] install.ps1 未找到, 跳过高级配置 echo [WARN] install.ps1 未找到, 跳过高级配置
@ -266,14 +266,12 @@ if %ERRORS% gtr 0 (
echo 按任意键启动 Bookworm... echo 按任意键启动 Bookworm...
pause > nul pause > nul
:: 启动 — 优先在 pwsh7 新窗口中运行 :: 启动 — pwsh7 新窗口直接运行 claude
cd /d "%INSTALL_DIR%"
where pwsh >nul 2>nul where pwsh >nul 2>nul
if !errorlevel! equ 0 ( if !errorlevel! equ 0 (
start "Bookworm Smart Assistant" pwsh -NoLogo -ExecutionPolicy Bypass -File "%INSTALL_DIR%\install.ps1" -StartOnly -AutoAccept start "Bookworm Smart Assistant" pwsh -NoLogo -NoExit -Command "& claude --dangerously-skip-permissions"
) else if exist "启动Bookworm.bat" (
call "启动Bookworm.bat"
) else ( ) else (
cd /d "%INSTALL_DIR%"
powershell -NoLogo -ExecutionPolicy Bypass -File "%INSTALL_DIR%\install.ps1" -StartOnly -AutoAccept powershell -NoLogo -ExecutionPolicy Bypass -File "%INSTALL_DIR%\install.ps1" -StartOnly -AutoAccept
) )

View File

@ -863,13 +863,7 @@ if ($allOK -and $env:ANTHROPIC_API_KEY) {
Write-Host "" Write-Host ""
Log-Info "正在启动 Claude Code..." Log-Info "正在启动 Claude Code..."
Write-Host "" Write-Host ""
# 始终在独立 pwsh7 窗口中启动 (bat 调 pwsh 子进程时窗口仍属 cmd.exe) & claude --dangerously-skip-permissions
$pwshCmd = Get-Command pwsh -ErrorAction SilentlyContinue
if ($pwshCmd) {
Start-Process $pwshCmd.Source -ArgumentList "-NoLogo", "-NoExit", "-Command", "& claude --dangerously-skip-permissions" -WorkingDirectory $env:USERPROFILE -WindowStyle Normal
} else {
& claude --dangerously-skip-permissions
}
} }
} else { } else {
Write-Host " +---------------------------------------------------+" -ForegroundColor Yellow Write-Host " +---------------------------------------------------+" -ForegroundColor Yellow
@ -885,11 +879,6 @@ if ($allOK -and $env:ANTHROPIC_API_KEY) {
$launchResult = Show-MsgBox "安装完成, 但存在以下问题:`n$issueText`n`n是否仍然启动 Claude Code?`n(将以受限模式运行)" "安装警告" "YesNo" "Warning" $launchResult = Show-MsgBox "安装完成, 但存在以下问题:`n$issueText`n`n是否仍然启动 Claude Code?`n(将以受限模式运行)" "安装警告" "YesNo" "Warning"
if ($launchResult -eq "Yes" -and -not $SkipLaunch) { if ($launchResult -eq "Yes" -and -not $SkipLaunch) {
$pwshCmd = Get-Command pwsh -ErrorAction SilentlyContinue & claude --dangerously-skip-permissions
if ($pwshCmd) {
Start-Process $pwshCmd.Source -ArgumentList "-NoLogo", "-NoExit", "-Command", "& claude --dangerously-skip-permissions" -WorkingDirectory $env:USERPROFILE -WindowStyle Normal
} else {
& claude --dangerously-skip-permissions
}
} }
} }

View File

@ -19,7 +19,8 @@ param(
[string]$GitUrl = "https://code.letcareme.com/bookworm/bookworm-config.git", [string]$GitUrl = "https://code.letcareme.com/bookworm/bookworm-config.git",
[switch]$StartOnly, [switch]$StartOnly,
[switch]$SkipSecrets, [switch]$SkipSecrets,
[switch]$AutoAccept # 豁免所有人工确认环节 [switch]$SkipLaunch, # 仅安装不启动 (由调用方负责启动)
[switch]$AutoAccept # 豁免所有人工确认环节
) )
$ErrorActionPreference = "Stop" $ErrorActionPreference = "Stop"
@ -727,12 +728,9 @@ if (-not $StartOnly) {
} }
} }
# 始终在独立 pwsh7 窗口中启动 Claude Code # 启动 Claude Code (同步执行, 窗口类型由调用方 .bat 决定)
# (bat 调 pwsh 子进程时窗口仍属 cmd.exe, 必须 Start-Process 新建窗口) if ($SkipLaunch) {
$pwshCmd = Get-Command pwsh -ErrorAction SilentlyContinue Write-Host " [OK] 安装完成 (由调用方负责启动)" -ForegroundColor Green
if ($pwshCmd) {
Write-Host " [..] 正在启动 Claude Code (PowerShell 7)..." -ForegroundColor Cyan
Start-Process $pwshCmd.Source -ArgumentList "-NoLogo", "-NoExit", "-Command", "& claude --dangerously-skip-permissions" -WorkingDirectory $env:USERPROFILE -WindowStyle Normal
} else { } else {
& claude --dangerously-skip-permissions & claude --dangerously-skip-permissions
} }

View File

@ -6,10 +6,10 @@ cd /d "%~dp0"
set NO_PROXY=bww.letcareme.com,code.letcareme.com,letcareme.com,localhost,127.0.0.1 set NO_PROXY=bww.letcareme.com,code.letcareme.com,letcareme.com,localhost,127.0.0.1
set no_proxy=%NO_PROXY% set no_proxy=%NO_PROXY%
:: 优先 pwsh7: 启动新 PowerShell 7 窗口, 退出 cmd :: 优先 pwsh7: 直接在 pwsh7 窗口运行 claude
where pwsh >nul 2>nul where pwsh >nul 2>nul
if %errorlevel% equ 0 ( if %errorlevel% equ 0 (
start "Bookworm Smart Assistant" pwsh -NoLogo -ExecutionPolicy Bypass -File "%~dp0install.ps1" -StartOnly -AutoAccept start "Bookworm Smart Assistant" pwsh -NoLogo -NoExit -Command "& claude --dangerously-skip-permissions"
exit exit
) )

View File

@ -6,19 +6,24 @@ cd /d "%~dp0"
set NO_PROXY=bww.letcareme.com,code.letcareme.com,letcareme.com,localhost,127.0.0.1 set NO_PROXY=bww.letcareme.com,code.letcareme.com,letcareme.com,localhost,127.0.0.1
set no_proxy=%NO_PROXY% set no_proxy=%NO_PROXY%
:: 优先 pwsh7: 启动新 PowerShell 7 窗口, 退出 cmd :: 先更新配置 (在 cmd 中完成)
where pwsh >nul 2>nul where pwsh >nul 2>nul
if %errorlevel% equ 0 ( if %errorlevel% equ 0 (
start "Bookworm - 更新并启动" pwsh -NoLogo -ExecutionPolicy Bypass -File "%~dp0install.ps1" -AutoAccept pwsh -NoLogo -ExecutionPolicy Bypass -File "%~dp0install.ps1" -AutoAccept -SkipLaunch
) else (
powershell -ExecutionPolicy Bypass -File "%~dp0install.ps1" -AutoAccept -SkipLaunch
)
:: 更新后在 pwsh7 新窗口启动 claude
where pwsh >nul 2>nul
if %errorlevel% equ 0 (
start "Bookworm Smart Assistant" pwsh -NoLogo -NoExit -Command "& claude --dangerously-skip-permissions"
exit exit
) )
:: 回退 PowerShell 5.1 :: 回退 PowerShell 5.1
title Bookworm Portable - 更新并启动 title Bookworm Portable
echo. powershell -ExecutionPolicy Bypass -File "%~dp0install.ps1" -StartOnly -AutoAccept
echo [!] PowerShell 7 未安装, 使用 PowerShell 5.1
echo.
powershell -ExecutionPolicy Bypass -File install.ps1 -AutoAccept
if %errorlevel% neq 0 ( if %errorlevel% neq 0 (
echo. echo.
echo 启动失败,按任意键退出... echo 启动失败,按任意键退出...