Last active
May 18, 2026 10:57
-
-
Save panicoenlaxbox/5508b5cf7ddd81cd5b5de071f925d035 to your computer and use it in GitHub Desktop.
Clear-Chat.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Clear-Chat { | |
| $paths = @( | |
| # "$env:USERPROFILE\.codex\sessions", | |
| # "$env:APPDATA\Claude\claude-code-sessions", | |
| "$env:APPDATA\Code\User\workspaceStorage", | |
| "$env:USERPROFILE\.copilot\session-state", | |
| "$env:USERPROFILE\.copilot\logs", | |
| "$env:USERPROFILE\.copilot\ide", | |
| "$env:USERPROFILE\.copilot\command-history-state.json", | |
| "$env:USERPROFILE\.claude\history.jsonl", | |
| "$env:USERPROFILE\.claude\backups", | |
| "$env:USERPROFILE\.claude\debug", | |
| "$env:USERPROFILE\.claude\file-history", | |
| "$env:USERPROFILE\.claude\ide", | |
| "$env:USERPROFILE\.claude\plans", | |
| # "$env:USERPROFILE\.claude\plugins\installed_plugins.json", | |
| "$env:USERPROFILE\.claude\shell-snapshots", | |
| "$env:USERPROFILE\.claude\projects", | |
| # "$env:USERPROFILE\.claude\skills", | |
| "$env:USERPROFILE\.claude\usage-data" | |
| ) | |
| $excludedPaths = @() | |
| $vscode = Get-Process -Name "Code" -ErrorAction SilentlyContinue | |
| if ($vscode) { | |
| Write-Host "Please close Visual Studio Code before running this script." -ForegroundColor Red | |
| return | |
| } | |
| $backupPath = [System.IO.Path]::GetFullPath("$env:TEMP\Clear-Chat-$(Get-Random)") | |
| $backupPathCreated = $false | |
| if ($null -ne $excludedPaths) { | |
| foreach ($excludedPath in $excludedPaths) { | |
| if (-not (Test-Path $excludedPath)) { | |
| continue | |
| } | |
| if (-not $backupPathCreated) { | |
| Write-Host "Creating temporary backup directory $backupPath" -ForegroundColor Cyan | |
| New-Item -ItemType Directory -Path $backupPath -Force | Out-Null | |
| $backupPathCreated = $true | |
| } | |
| $relativePath = $excludedPath.Substring([System.IO.Path]::GetPathRoot($excludedPath).Length) | |
| $absolutePath = Join-Path $backupPath $relativePath | |
| $parentPath = Split-Path -Path $absolutePath -Parent | |
| Write-Host "Backing up $excludedPath" -ForegroundColor Green | |
| New-Item -ItemType Directory -Path $parentPath -Force | Out-Null | |
| Copy-Item -LiteralPath $excludedPath -Destination $absolutePath -Force | Out-Null | |
| } | |
| } | |
| foreach ($path in $paths) { | |
| if (-not (Test-Path $path)) { | |
| continue | |
| } | |
| Write-Host "Clearing contents of $path" -ForegroundColor Yellow | |
| $children = Get-ChildItem -LiteralPath $path -Force | |
| foreach ($child in $children) { | |
| Write-Host "Removing $($child.FullName)" -ForegroundColor Yellow | |
| Remove-Item -LiteralPath $child.FullName -Force -Recurse | Out-Null | |
| } | |
| } | |
| if ($null -ne $excludedPaths) { | |
| foreach ($excludedPath in $excludedPaths) { | |
| $relativePath = $excludedPath.Substring([System.IO.Path]::GetPathRoot($excludedPath).Length) | |
| $absolutePath = Join-Path $backupPath $relativePath | |
| if (-not (Test-Path $absolutePath)) { | |
| continue | |
| } | |
| $parentPath = Split-Path -Path $excludedPath -Parent | |
| Write-Host "Restoring $excludedPath" -ForegroundColor Green | |
| New-Item -ItemType Directory -Path $parentPath -Force | Out-Null | |
| Copy-Item -LiteralPath $absolutePath -Destination $excludedPath -Force | Out-Null | |
| } | |
| if ($backupPathCreated) { | |
| Write-Host "Cleaning up temporary backup directory $backupPath" -ForegroundColor Cyan | |
| Remove-Item -LiteralPath $backupPath -Recurse -Force | Out-Null | |
| } | |
| } | |
| $path = "$env:USERPROFILE\.copilot\config.json" | |
| if (Test-Path $path) { | |
| Write-Host "Clearing trusted_folders from $path" -ForegroundColor Yellow | |
| $json = Get-Content -LiteralPath $path -Raw | ConvertFrom-Json | |
| if ($null -ne $json.PSObject.Properties['trusted_folders']) { | |
| $json.trusted_folders = @() | |
| } | |
| $json | ConvertTo-Json -Depth 10 | Set-Content -LiteralPath $path -Encoding UTF8 | |
| } | |
| $path = "$env:USERPROFILE\.claude.json" | |
| if (Test-Path $path) { | |
| Write-Host "Clearing projects and githubRepoPaths from $path" -ForegroundColor Yellow | |
| $json = Get-Content -LiteralPath $path -Raw | ConvertFrom-Json | |
| if ($null -ne $json.PSObject.Properties['projects']) { | |
| $json.projects = [PSCustomObject]@{} | |
| } | |
| # "projects": { | |
| # "C:/Users/sergio.leon/source/repos/doit-app": { | |
| # "allowedTools": [], | |
| # "mcpContextUris": [], | |
| # "mcpServers": {}, | |
| # "enabledMcpjsonServers": [], | |
| # "disabledMcpjsonServers": [], | |
| # "hasTrustDialogAccepted": true, | |
| # "projectOnboardingSeenCount": 0, | |
| # "hasClaudeMdExternalIncludesApproved": false, | |
| # "hasClaudeMdExternalIncludesWarningShown": false | |
| # } | |
| # }, | |
| if ($null -ne $json.PSObject.Properties['githubRepoPaths']) { | |
| $json.githubRepoPaths = [PSCustomObject]@{} | |
| } | |
| # "githubRepoPaths": { | |
| # "sergio-leon_aax/taskit": [ | |
| # "C:\\Users\\sergio.leon\\source\\repos\\taskit" | |
| # ] | |
| # }, | |
| $json | ConvertTo-Json -Depth 10 | Set-Content -LiteralPath $path -Encoding UTF8 | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment