# Setup Periodic Context Save - Windows Task Scheduler # This script creates a scheduled task to run periodic_save_check.py every minute # Uses pythonw.exe to run without console window $TaskName = "ClaudeTools - Periodic Context Save" $ScriptPath = "D:\ClaudeTools\.claude\hooks\periodic_save_check.py" $WorkingDir = "D:\ClaudeTools" # Use pythonw.exe instead of python.exe to run without console window $PythonExe = (Get-Command python).Source $PythonDir = Split-Path $PythonExe -Parent $PythonwPath = Join-Path $PythonDir "pythonw.exe" # Fallback to python.exe if pythonw.exe doesn't exist (shouldn't happen) if (-not (Test-Path $PythonwPath)) { Write-Warning "pythonw.exe not found at $PythonwPath, falling back to python.exe" $PythonwPath = $PythonExe } # Check if task already exists $ExistingTask = Get-ScheduledTask -TaskName $TaskName -ErrorAction SilentlyContinue if ($ExistingTask) { Write-Host "Task '$TaskName' already exists. Removing old task..." Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false } # Create action to run Python script with pythonw.exe (no console window) $Action = New-ScheduledTaskAction -Execute $PythonwPath ` -Argument $ScriptPath ` -WorkingDirectory $WorkingDir # Create trigger to run every minute (indefinitely) $Trigger = New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Minutes 1) # Create settings - Hidden and DisallowStartIfOnBatteries set to false $Settings = New-ScheduledTaskSettingsSet ` -AllowStartIfOnBatteries ` -DontStopIfGoingOnBatteries ` -StartWhenAvailable ` -ExecutionTimeLimit (New-TimeSpan -Minutes 5) ` -Hidden # Create principal (run as current user, no window) $Principal = New-ScheduledTaskPrincipal -UserId "$env:USERDOMAIN\$env:USERNAME" -LogonType S4U # Register the task Register-ScheduledTask -TaskName $TaskName ` -Action $Action ` -Trigger $Trigger ` -Settings $Settings ` -Principal $Principal ` -Description "Automatically saves Claude Code context every 5 minutes of active work" Write-Host "[SUCCESS] Scheduled task created successfully!" Write-Host "" Write-Host "Task Name: $TaskName" Write-Host "Runs: Every 1 minute (HIDDEN - no console window)" Write-Host "Action: Checks activity and saves context every 5 minutes" Write-Host "Executable: $PythonwPath (pythonw.exe = no window)" Write-Host "" Write-Host "To verify task is hidden:" Write-Host " Get-ScheduledTask -TaskName '$TaskName' | Select-Object -ExpandProperty Settings" Write-Host "" Write-Host "To remove:" Write-Host " Unregister-ScheduledTask -TaskName '$TaskName' -Confirm:`$false" Write-Host "" Write-Host "View logs:" Write-Host ' Get-Content D:\ClaudeTools\.claude\periodic-save.log -Tail 20'