Code Snippets|SCRIPTS

Last Updated: Monday, November 10th, 2025

Deep Clean script for Adobe Photoshop

powershell PowerShell
This script targets the massive temporary files Photoshop creates (scratch files), the "Media Cache" (which often causes lag), the Camera Raw cache, and the AutoRecover folder (which is often the culprit if Photoshop crashes on startup).

Warning: This script clears the AutoRecover folder. If your Photoshop crashed 5 minutes ago and you are trying to recover an unsaved file, do not run this yet. If you are running this because Photoshop is sluggish or glitching, this is exactly what you need.
Write-Host "Starting Photoshop Deep Clean..." -ForegroundColor Cyan

# --- STEP 0: Force Close Photoshop ---
Write-Host "Stopping Photoshop processes to unlock files..." -ForegroundColor Yellow
$processes = @("Photoshop", "AdobeCollabSync", "CoreSync", "Adobe Spaces Helper")
foreach ($proc in $processes) {
    Get-Process -Name $proc -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
}

# --- STEP 1: Define Adobe & System Paths ---
$pathsToClean = @(
    # 1. Standard Windows Temp (Photoshop loves this folder)
    "$env:TEMP\*",
    "C:\Windows\Temp\*",

    # 2. Adobe Common Media Cache (Massive space hog, causes lag)
    "$env:APPDATA\Adobe\Common\Media Cache Files\*",
    "$env:APPDATA\Adobe\Common\Media Cache Database\*",
    "$env:LOCALAPPDATA\Adobe\Common\Media Cache Files\*",

    # 3. Camera Raw Cache (Stores previews of raw files)
    "$env:LOCALAPPDATA\Adobe\CameraRaw\Cache\*",
    "$env:LOCALAPPDATA\Adobe\CameraRaw\GPU\*",

    # 4. Photoshop AutoRecover (Clears 'stuck' crash files that prevent startup)
    # Note: Using wildcards '*' to catch specific versions (e.g., Photoshop 2024, 2025)
    "$env:APPDATA\Adobe\Adobe Photoshop*\AutoRecover\*",

    # 5. Adobe Generic Temp & OOBE
    "$env:LOCALAPPDATA\Adobe\OOBE\*",
    "$env:LOCALAPPDATA\Temp\Adobe\*"
)

# --- STEP 2: GPU Shader Caches (Crucial for Photoshop Canvas/Rendering glitches) ---
# Photoshop uses GPU acceleration heavily; stale shaders cause visual artifacts.
$gpuPaths = @(
    "$env:LOCALAPPDATA\NVIDIA\DXCache\*",
    "$env:LOCALAPPDATA\NVIDIA\GLCache\*",
    "$env:LOCALAPPDATA\AMD\DxCache\*"
)

# Combine all paths
$allPaths = $pathsToClean + $gpuPaths

# --- STEP 3: Execution Loop ---
Write-Host "Scrubbing Scratch Disks and Caches..." -ForegroundColor Yellow
foreach ($path in $allPaths) {
    if (Test-Path $path) {
        # Using -Recurse -Force to handle hidden files and folders
        Remove-Item -Path $path -Recurse -Force -ErrorAction SilentlyContinue
        Write-Host "Cleaned: $path" -ForegroundColor Gray
    }
}

# --- STEP 4: Targeted "Photoshop Temp" Search ---
# Photoshop sometimes leaves massive "Photoshop Temp12345" files in the root Temp folder.
# This command hunts them specifically by name pattern.
Write-Host "Hunting for orphaned 'Photoshop Temp' files..." -ForegroundColor Yellow
Get-ChildItem -Path "$env:TEMP" -Filter "Photoshop Temp*" -ErrorAction SilentlyContinue |
    Remove-Item -Force -ErrorAction SilentlyContinue

# --- STEP 5: Empty Recycle Bin ---
Write-Host "Emptying Recycle Bin..." -ForegroundColor Yellow
Clear-RecycleBin -Force -ErrorAction SilentlyContinue

Write-Host "Photoshop Cleanup Complete! You may restart the app now." -ForegroundColor Green
Last Updated: Sunday, December 7th, 2025

Clear Cache Locations for Claude Code and Claude AI

powershell PowerShell
This script performs a complete "deep clean" of your AI workspace by first terminating Claude and related background processes to release file locks, then aggressively purging standard Windows temporary folders, GPU shader caches, and specific Claude/Electron application data. It creates a fresh environment by sweeping your user directory for development leftovers like Python and npm caches, resetting the Windows Store, and emptying the Recycle Bin, all while using safety flags to skip any locked system files without generating errors.
# PowerShell
Write-Host "Starting Claude Cleanup Process..." -ForegroundColor Cyan

# --- STEP 0: Stop Claude only (avoid killing unrelated node/python work) ---
Write-Host "Stopping Claude processes to release file locks..." -ForegroundColor Yellow
$processes = @("Claude", "Claude Desktop", "ClaudeAI")
foreach ($proc in $processes) {
    Get-Process -Name $proc -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
}

# --- Helper: remove contents of a directory safely (handles empty dirs + avoids wildcard Test-Path weirdness) ---
function Clear-DirContents {
    param(
        [Parameter(Mandatory=$true)]
        [string]$DirPath
    )

    if (Test-Path -LiteralPath $DirPath) {
        try {
            # Remove contents, not the folder itself
            Remove-Item -LiteralPath (Join-Path $DirPath '*') -Recurse -Force -ErrorAction Stop
            Write-Host "Cleaned: $DirPath" -ForegroundColor Gray
        }
        catch {
            Write-Host "Skipped (locked/permission): $DirPath" -ForegroundColor DarkYellow
        }
    }
}

# --- STEP 1: Claude-specific and closely related cache paths ---
# Notes:
# - Keep this focused on Claude + common Electron cache locations.
# - Avoid nuking all Windows Store app caches (Packages\*LocalCache\*) unless you truly want that.
$dirsToClean = @(
    # Windows user temp (often used by installers/updaters)
    "$env:TEMP",
    "$env:LOCALAPPDATA\Temp",

    # Electron caches (generic, but low-risk and often helps)
    "$env:APPDATA\Electron\Cache",
    "$env:LOCALAPPDATA\Electron\Cache",

    # Claude Desktop / ClaudeAI (common locations)
    "$env:LOCALAPPDATA\Claude",
    "$env:LOCALAPPDATA\ClaudeAI",
    "$env:APPDATA\Claude",
    "$env:APPDATA\ClaudeAI",

    # Squirrel temp used by some Electron app updaters (Claude may use it)
    "$env:LOCALAPPDATA\SquirrelTemp"
)

Write-Host "Cleaning Claude/Electron cache directories..." -ForegroundColor Yellow
foreach ($dir in $dirsToClean) {
    Clear-DirContents -DirPath $dir
}

# --- STEP 2: Windows Store package cache (Claude-only) ---
# This searches the Windows Store Packages directory for packages with "Claude" in the name,
# then clears only their LocalCache folders.
Write-Host "Cleaning Microsoft Store package cache for Claude (if present)..." -ForegroundColor Yellow
$packagesRoot = Join-Path $env:LOCALAPPDATA "Packages"
if (Test-Path -LiteralPath $packagesRoot) {
    Get-ChildItem -LiteralPath $packagesRoot -Directory -ErrorAction SilentlyContinue |
        Where-Object { $_.Name -match 'Claude' } |
        ForEach-Object {
            $localCache = Join-Path $_.FullName "LocalCache"
            if (Test-Path -LiteralPath $localCache) {
                Clear-DirContents -DirPath $localCache
            }
        }
}

# --- STEP 3: Optional: clear GPU shader caches (safe-ish; can improve Electron app weirdness) ---
# Comment this block out if you don't want shader caches touched.
Write-Host "Cleaning GPU shader caches (optional)..." -ForegroundColor Yellow
$gpuDirs = @(
    "$env:LOCALAPPDATA\NVIDIA\DXCache",
    "$env:LOCALAPPDATA\NVIDIA\GLCache",
    "$env:LOCALAPPDATA\AMD\DxCache"
)
foreach ($dir in $gpuDirs) {
    Clear-DirContents -DirPath $dir
}

# --- STEP 4: Optional: Windows Store cache reset (often unrelated; leave enabled only if you know you want it) ---
# Comment out if you only want Claude cleanup.
Write-Host "Resetting Microsoft Store cache (optional)..." -ForegroundColor Yellow
try {
    Start-Process -FilePath "wsreset.exe" -NoNewWindow -Wait -ErrorAction Stop
} catch {
    Write-Host "wsreset skipped (not available or blocked)." -ForegroundColor DarkYellow
}

# --- STEP 5: Optional: Empty Recycle Bin ---
Write-Host "Emptying Recycle Bin (optional)..." -ForegroundColor Yellow
try {
    Clear-RecycleBin -Force -ErrorAction Stop
} catch {
    Write-Host "Recycle Bin cleanup skipped (cmdlet not available or blocked)." -ForegroundColor DarkYellow
}

Write-Host "Claude cleanup complete!" -ForegroundColor Green
Last Updated: Wednesday, January 28th, 2026

Recursively Show Files & Folders in Folder

powershell PowerShell
Show folders/files, full paths, and time written in a folder [Start in Parent Folder]
Get-ChildItem -File -Recurse | Select-Object FullName, LastWriteTime
Last Updated: Saturday, December 6th, 2025