| 123456789101112131415161718192021222324252627282930 |
- # OpenCode 会话清理脚本
- # 删除所有会话历史,保留插件/MCP/provider等配置
- # 用法: powershell -File clear_sessions.ps1
- $cli = "$env:LOCALAPPDATA\OpenCode\opencode-cli.exe"
- if (-not (Test-Path $cli)) {
- Write-Error "opencode-cli not found at $cli"
- exit 1
- }
- Write-Host "Fetching all sessions..." -ForegroundColor Cyan
- $sessions = & $cli db "SELECT id FROM session ORDER BY time_created;" --format json 2>&1 | ConvertFrom-Json
- $total = $sessions.Count
- if ($total -eq 0) {
- Write-Host "No sessions to delete." -ForegroundColor Green
- exit 0
- }
- Write-Host "Deleting $total sessions..." -ForegroundColor Yellow
- $i = 0
- foreach ($s in $sessions) {
- $i++
- $pct = [math]::Round($i / $total * 100, 1)
- Write-Progress -PercentComplete ($pct) -Activity "Deleting sessions" -Status "$i / $total ($pct%)" -CurrentOperation $s.id
- & $cli session delete $s.id 2>&1 | Out-Null
- }
- Write-Host "Done. Deleted $total sessions." -ForegroundColor Green
- Write-Host "Config at ~/.config/opencode/ is untouched (plugins, MCP, providers preserved)." -ForegroundColor Cyan
|